@zhivex-ai/gateway 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,6 +21,54 @@ For agent routing, the gateway can also filter by `agentCapabilities`, such as p
|
|
|
21
21
|
bun add @zhivex-ai/gateway
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
## Usage
|
|
25
|
+
|
|
26
|
+
```ts
|
|
27
|
+
import { createGateway } from "@zhivex-ai/gateway";
|
|
28
|
+
import { createOpenAI } from "@zhivex-ai/openai";
|
|
29
|
+
import { createOllama } from "@zhivex-ai/ollama";
|
|
30
|
+
|
|
31
|
+
const gateway = createGateway({
|
|
32
|
+
adapters: {
|
|
33
|
+
openai: createOpenAI({ apiKey: process.env.OPENAI_API_KEY }),
|
|
34
|
+
ollama: createOllama()
|
|
35
|
+
},
|
|
36
|
+
maxRetries: 1
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const result = await gateway.generate({
|
|
40
|
+
primary: { provider: "openai", modelId: "gpt-4o-mini" },
|
|
41
|
+
fallbacks: [{ provider: "ollama", modelId: "llama3.2" }],
|
|
42
|
+
messages: [{ role: "user", content: "Summarize the benefits of fallback routing." }],
|
|
43
|
+
routingMode: "balanced"
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log(result.text);
|
|
47
|
+
console.log(result.providerUsed);
|
|
48
|
+
console.log(result.attempts);
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The gateway also supports `streamText()`, `generateObject()`, and `streamObject()` while preserving the selected target for the full request lifecycle, including tool loops.
|
|
52
|
+
|
|
53
|
+
For agent workloads, use `runAgent()` or `streamAgent()` to route by both regular model capabilities and agent-specific capabilities such as `supportTier`, `approvalRequests`, or `remoteMcp`.
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
const agentResult = await gateway.runAgent({
|
|
57
|
+
primary: { provider: "bedrock", modelId: "anthropic.claude-v2" },
|
|
58
|
+
fallbacks: [{ provider: "openai", modelId: "gpt-5" }],
|
|
59
|
+
prompt: "Use the strongest available agent provider.",
|
|
60
|
+
requiredAgentCapabilities: {
|
|
61
|
+
supportTier: "tier-a",
|
|
62
|
+
approvalRequests: true
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log(agentResult.providerUsed);
|
|
67
|
+
console.log(agentResult.routeDecision);
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
This package is the SDK-local routing layer. It is not the Zhivex-hosted Gateway API and it is not re-exported from `@zhivex-ai/sdk`.
|
|
71
|
+
|
|
24
72
|
Repository and full documentation:
|
|
25
73
|
|
|
26
74
|
- <https://github.com/Zhivex/zhivex-ai-sdk>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhivex-ai/gateway",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
4
4
|
"description": "Routing and fallback helpers for Zhivex AI SDK.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@zhivex-ai/core": "^0.
|
|
44
|
+
"@zhivex-ai/core": "^0.9.0"
|
|
45
45
|
}
|
|
46
46
|
}
|