@zorveus/sdk 0.1.0
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 +236 -0
- package/dist/index.d.mts +919 -0
- package/dist/index.d.ts +919 -0
- package/dist/index.js +1205 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1158 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +34 -0
package/README.md
ADDED
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# @zorveus/sdk
|
|
2
|
+
|
|
3
|
+
The official TypeScript and JavaScript client library for the [Zorveus](https://zorveus.com) AI Infrastructure Platform.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📦 Key Capabilities
|
|
8
|
+
|
|
9
|
+
- **Unified AI Gateway & Streaming**: OpenAI-compatible chat completions across OpenAI, Anthropic, Gemini, DeepSeek, and more.
|
|
10
|
+
- **Product User Management & Credit Grants**: Manage spend limits, query live balances, and issue promotional AI credits using your application's `external_user_id`.
|
|
11
|
+
- **Live Model Discovery**: Query accessible models for any inference key with `client.models.list({ routeStatus: "available" })`.
|
|
12
|
+
- **Live Spend Cap Tracking**: Real-time spending, monthly budget caps, and remaining allowances with `client.getUsage()`.
|
|
13
|
+
- **OAuth 2.0 PKCE Helpers**: Complete PKCE authorization and token exchange utilities for user-owned AI wallet connections.
|
|
14
|
+
- **Provider Credentials Management**: Securely store and route BYOK foundation model provider keys.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 🚀 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @zorveus/sdk
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🔑 Client Types
|
|
27
|
+
|
|
28
|
+
`@zorveus/sdk` provides two specialized clients:
|
|
29
|
+
|
|
30
|
+
1. **`Zorveus`**: Client for AI inference, chat streaming, model discovery, and spend cap queries using an **Inference API Key** or **User OAuth Token**.
|
|
31
|
+
2. **`ZorveusServiceClient`**: Client for backend administration, product user provisioning, and credit grants using a **Master Organization Service Key** (`zrv_service_...`).
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## ⚡ Quickstart 1: AI Inference & Streaming (`Zorveus`)
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
import { Zorveus } from "@zorveus/sdk";
|
|
39
|
+
|
|
40
|
+
const client = new Zorveus({
|
|
41
|
+
apiKey: process.env.ZORVEUS_INFERENCE_KEY // Direct inference key or user access token
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 1. Live Model Discovery (Zero Mock Fallbacks)
|
|
45
|
+
const models = await client.models.list({ routeStatus: "available" });
|
|
46
|
+
console.log(`Available models: ${models.data.map(m => m.id).join(", ")}`);
|
|
47
|
+
|
|
48
|
+
// 2. Real-Time Chat Streaming with User Attribution
|
|
49
|
+
const stream = await client.chat.completions.create({
|
|
50
|
+
model: "openai/gpt-4.1-mini",
|
|
51
|
+
messages: [
|
|
52
|
+
{ role: "system", content: "You are an expert career strategist." },
|
|
53
|
+
{ role: "user", content: "Write a high-converting executive summary bullet." }
|
|
54
|
+
],
|
|
55
|
+
stream: true,
|
|
56
|
+
zorveusMetadata: {
|
|
57
|
+
externalUserId: "usr_sara_101",
|
|
58
|
+
displayName: "Sara Connor",
|
|
59
|
+
userEmail: "sara@example.com"
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
for await (const chunk of stream) {
|
|
64
|
+
process.stdout.write(chunk.choices[0]?.delta?.content || "");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 3. Query Live Spend Cap & Usage (GET /inference-keys/usage)
|
|
68
|
+
const usage = await client.getUsage();
|
|
69
|
+
console.log(`Spent this period: $${usage.spent_this_period} / $${usage.spend_cap} ${usage.currency}`);
|
|
70
|
+
console.log(`Remaining balance: $${usage.remaining_balance}`);
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 🏢 Quickstart 2: Product Users & Credit Grants (`ZorveusServiceClient`)
|
|
76
|
+
|
|
77
|
+
Anchor all product user operations directly to your SaaS user identifiers (`external_user_id`), without needing Zorveus internal IDs or session cookies.
|
|
78
|
+
|
|
79
|
+
```typescript
|
|
80
|
+
import { ZorveusServiceClient } from "@zorveus/sdk";
|
|
81
|
+
|
|
82
|
+
const zorveus = new ZorveusServiceClient({
|
|
83
|
+
apiKey: process.env.ZORVEUS_SERVICE_KEY // Master Service Key: zrv_svc_...
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const appId = "app_startup_123";
|
|
87
|
+
const externalUserId = "usr_sara_101";
|
|
88
|
+
|
|
89
|
+
// 1. Auto-Provision or Upsert User Profile
|
|
90
|
+
const profile = await zorveus.productUsers.createOrUpdate({
|
|
91
|
+
appId,
|
|
92
|
+
externalUserId,
|
|
93
|
+
displayName: "Sara Connor",
|
|
94
|
+
email: "sara@example.com",
|
|
95
|
+
metadata: { plan: "Pro", tier: "Growth" }
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
console.log("Status:", profile.product_user.status);
|
|
99
|
+
console.log("Live Balance:", profile.product_user.credits?.available_credits);
|
|
100
|
+
|
|
101
|
+
// 2. Grant Promotional AI Credits (Using External ID)
|
|
102
|
+
const grantRes = await zorveus.productUsers.grantCreditByExternalId({
|
|
103
|
+
appId,
|
|
104
|
+
externalUserId,
|
|
105
|
+
amount: "25.000000000000", // Strict decimal string
|
|
106
|
+
currency: "USD",
|
|
107
|
+
source: "promotion", // 'admin_adjustment' | 'promotion' | 'purchase' | 'monthly_allowance' | 'support_credit'
|
|
108
|
+
reason: "Welcome Growth Bonus"
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
console.log("Issued Grant ID:", grantRes.credit_grant.credit_grant_id);
|
|
112
|
+
console.log("New Balance:", grantRes.credit_summary.remaining_balance);
|
|
113
|
+
|
|
114
|
+
// 3. Query User's Credit Grants Ledger (Using External ID)
|
|
115
|
+
const ledger = await zorveus.productUsers.listCreditGrantsByExternalId({
|
|
116
|
+
appId,
|
|
117
|
+
externalUserId,
|
|
118
|
+
status: "active" // Optional: 'active' | 'exhausted' | 'expired' | 'revoked'
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
for (const grant of ledger.credit_grants) {
|
|
122
|
+
console.log(`- Grant $${grant.amount} (${grant.source}): ${grant.reason}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// 4. Query Lightweight Credit Summary
|
|
126
|
+
const summary = await zorveus.productUsers.getCreditSummaryByExternalId({
|
|
127
|
+
appId,
|
|
128
|
+
externalUserId,
|
|
129
|
+
currency: "USD"
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
console.log("Available Credits:", summary.available_credits);
|
|
133
|
+
console.log("Expiring Soon:", summary.expiring_soon_amount);
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## 🔐 Quickstart 3: OAuth 2.0 PKCE Authentication (`ZorveusOAuth`)
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { ZorveusOAuth } from "@zorveus/sdk";
|
|
142
|
+
|
|
143
|
+
// Step 1: Generate PKCE parameters
|
|
144
|
+
const pkce = ZorveusOAuth.generatePKCE();
|
|
145
|
+
|
|
146
|
+
// Step 2: Generate authorization URL for user consent
|
|
147
|
+
const authUrl = ZorveusOAuth.generateAuthUrl({
|
|
148
|
+
clientId: "zrv_client_123456",
|
|
149
|
+
redirectUri: "https://yourapp.com/oauth/callback",
|
|
150
|
+
codeChallenge: pkce.codeChallenge,
|
|
151
|
+
state: pkce.state,
|
|
152
|
+
scopes: ["inference:write", "models:*"]
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// Redirect user to authUrl...
|
|
156
|
+
|
|
157
|
+
// Step 3: Exchange authorization code for Access Token
|
|
158
|
+
const tokenData = await ZorveusOAuth.exchangeToken({
|
|
159
|
+
clientId: "zrv_client_123456",
|
|
160
|
+
code: callbackCode,
|
|
161
|
+
codeVerifier: pkce.codeVerifier,
|
|
162
|
+
redirectUri: "https://yourapp.com/oauth/callback"
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
console.log("User Access Token:", tokenData.access_token);
|
|
166
|
+
console.log("App Connection ID:", tokenData.app_connection_id);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 📚 Complete API Reference
|
|
172
|
+
|
|
173
|
+
### `Zorveus` (Inference Client)
|
|
174
|
+
| Method | Description |
|
|
175
|
+
| :--- | :--- |
|
|
176
|
+
| `client.chat.completions.create(params)` | Create streaming or non-streaming chat completions with model routing and metadata attribution |
|
|
177
|
+
| `client.models.list(params)` | List accessible foundation models (`GET /v1/models?route_status=available`) |
|
|
178
|
+
| `client.getUsage(options)` | Query live spend cap, period spend, and remaining allowance (`GET /inference-keys/usage`) |
|
|
179
|
+
|
|
180
|
+
### `ZorveusServiceClient.productUsers` (Product Users & Credits)
|
|
181
|
+
| Method | Description |
|
|
182
|
+
| :--- | :--- |
|
|
183
|
+
| `createOrUpdate(params)` | Upsert product user by external ID (`PUT /product-users/by-external-id`) |
|
|
184
|
+
| `getByExternalId(params)` | Get product user profile with live cap & credit summary (`GET /product-users/by-external-id`) |
|
|
185
|
+
| `getCreditSummaryByExternalId(params)` | Fetch aggregated live credit balance (`GET /product-users/by-external-id/credit-summary`) |
|
|
186
|
+
| `listCreditGrantsByExternalId(params)` | Query user's credit grants ledger (`GET /product-users/by-external-id/credit-grants`) |
|
|
187
|
+
| `grantCreditByExternalId(params)` | Issue credits anchored to external ID (`POST /product-users/by-external-id/credit-grants`) |
|
|
188
|
+
| `list(params)` | List organization product users (`GET /product-users`) |
|
|
189
|
+
| `revokeCredit(userIdentifier, grantId)` | Revoke active grant (`POST /product-users/{id}/credit-grants/{grantId}/revoke`) |
|
|
190
|
+
|
|
191
|
+
### `ZorveusServiceClient.providerCredentials` (BYOK Management)
|
|
192
|
+
| Method | Description |
|
|
193
|
+
| :--- | :--- |
|
|
194
|
+
| `create(params)` | Store encrypted provider credential (OpenAI, Anthropic, Gemini, DeepSeek, etc.) |
|
|
195
|
+
| `list(params)` | List registered provider credentials |
|
|
196
|
+
| `get(credentialId)` | Get credential metadata |
|
|
197
|
+
| `delete(credentialId)` | Revoke provider credential |
|
|
198
|
+
|
|
199
|
+
### `ZorveusOAuth` (OAuth PKCE Utilities)
|
|
200
|
+
| Method | Description |
|
|
201
|
+
| :--- | :--- |
|
|
202
|
+
| `generatePKCE()` | Generates cryptographically secure `codeVerifier`, `codeChallenge`, and `state` |
|
|
203
|
+
| `generateAuthUrl(params)` | Generates OAuth 2.0 authorization URL |
|
|
204
|
+
| `validateCallback(params)` | Validates callback code and anti-CSRF state token |
|
|
205
|
+
| `exchangeToken(params)` | Exchanges authorization code for Bearer access token |
|
|
206
|
+
| `revokeToken(params)` | Revokes connection or access token |
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 🛡️ Error Handling
|
|
211
|
+
|
|
212
|
+
The SDK exposes strongly-typed errors for easy handling:
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
import { ZorveusError, AuthenticationError, RateLimitError, InvalidDecimalError } from "@zorveus/sdk";
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
await zorveus.productUsers.grantCreditByExternalId({ ... });
|
|
219
|
+
} catch (error) {
|
|
220
|
+
if (error instanceof InvalidDecimalError) {
|
|
221
|
+
console.error("Amount must be a valid decimal string (e.g. '25.00')");
|
|
222
|
+
} else if (error instanceof AuthenticationError) {
|
|
223
|
+
console.error("Invalid API Key or Service Key");
|
|
224
|
+
} else if (error instanceof RateLimitError) {
|
|
225
|
+
console.error("Rate limit exceeded");
|
|
226
|
+
} else if (error instanceof ZorveusError) {
|
|
227
|
+
console.error(`Zorveus Error (${error.status}):`, error.message);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
---
|
|
233
|
+
|
|
234
|
+
## 📄 License
|
|
235
|
+
|
|
236
|
+
MIT © [Zorveus Inc.](https://zorveus.com)
|