@modelrelay/sdk 1.42.0 → 2.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 +14 -46
- package/dist/api-DZpC1zuz.d.cts +4691 -0
- package/dist/api-DZpC1zuz.d.ts +4691 -0
- package/dist/api-D_hE36Ps.d.cts +4535 -0
- package/dist/api-D_hE36Ps.d.ts +4535 -0
- package/dist/api-Dz9HcUTt.d.cts +4522 -0
- package/dist/api-Dz9HcUTt.d.ts +4522 -0
- package/dist/billing/index.d.cts +3 -3
- package/dist/billing/index.d.ts +3 -3
- package/dist/chunk-AZD5EKLV.js +1133 -0
- package/dist/chunk-CYGWZYYJ.js +1194 -0
- package/dist/chunk-MXXJDLGU.js +1194 -0
- package/dist/chunk-R6O6UQYM.js +1133 -0
- package/dist/chunk-SCOP57J4.js +1194 -0
- package/dist/index.cjs +225 -2970
- package/dist/index.d.cts +101 -2090
- package/dist/index.d.ts +101 -2090
- package/dist/index.js +231 -2894
- package/dist/node.cjs +8 -9
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +8 -9
- package/dist/tools-CvfwPjC5.d.cts +1098 -0
- package/dist/tools-CvfwPjC5.d.ts +1098 -0
- package/dist/tools-DUYHZdZP.d.cts +982 -0
- package/dist/tools-DUYHZdZP.d.ts +982 -0
- package/dist/tools-bCt1QwNk.d.cts +998 -0
- package/dist/tools-bCt1QwNk.d.ts +998 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,38 +8,6 @@ bun add @modelrelay/sdk
|
|
|
8
8
|
|
|
9
9
|
Use token providers when you want the SDK to automatically obtain/refresh **bearer tokens** for data-plane calls like `/responses` and `/runs`.
|
|
10
10
|
|
|
11
|
-
### OIDC id_token → customer bearer token (exchange)
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
import { ModelRelay, OIDCExchangeTokenProvider, parseSecretKey } from "@modelrelay/sdk";
|
|
15
|
-
|
|
16
|
-
const tokenProvider = new OIDCExchangeTokenProvider({
|
|
17
|
-
apiKey: parseSecretKey(process.env.MODELRELAY_API_KEY!),
|
|
18
|
-
idTokenProvider: async () => {
|
|
19
|
-
// Return an OIDC id_token from your auth system (web login, device flow, etc).
|
|
20
|
-
return process.env.OIDC_ID_TOKEN!;
|
|
21
|
-
},
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
const mr = new ModelRelay({ tokenProvider });
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
If you need an `id_token` in a CLI-like context, you can use the OAuth device flow helper:
|
|
28
|
-
|
|
29
|
-
```ts
|
|
30
|
-
import { runOAuthDeviceFlowForIDToken } from "@modelrelay/sdk";
|
|
31
|
-
|
|
32
|
-
const idToken = await runOAuthDeviceFlowForIDToken({
|
|
33
|
-
deviceAuthorizationEndpoint: "https://issuer.example.com/oauth/device/code",
|
|
34
|
-
tokenEndpoint: "https://issuer.example.com/oauth/token",
|
|
35
|
-
clientId: "your-client-id",
|
|
36
|
-
scope: "openid email profile",
|
|
37
|
-
onUserCode: ({ verificationUri, userCode }) => {
|
|
38
|
-
console.log(`Open ${verificationUri} and enter code: ${userCode}`);
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
```
|
|
42
|
-
|
|
43
11
|
### Secret key → customer bearer token (mint)
|
|
44
12
|
|
|
45
13
|
```ts
|
|
@@ -62,7 +30,7 @@ const mr = ModelRelay.fromSecretKey("mr_sk_...");
|
|
|
62
30
|
|
|
63
31
|
const req = mr.responses
|
|
64
32
|
.new()
|
|
65
|
-
.model("claude-sonnet-4-
|
|
33
|
+
.model("claude-sonnet-4-5")
|
|
66
34
|
.user("Hello")
|
|
67
35
|
.build();
|
|
68
36
|
|
|
@@ -141,14 +109,14 @@ import { chain, llmStep } from "@modelrelay/sdk";
|
|
|
141
109
|
|
|
142
110
|
const summarizeReq = mr.responses
|
|
143
111
|
.new()
|
|
144
|
-
.model("claude-sonnet-4-
|
|
112
|
+
.model("claude-sonnet-4-5")
|
|
145
113
|
.system("Summarize the input concisely.")
|
|
146
114
|
.user("The quick brown fox...")
|
|
147
115
|
.build();
|
|
148
116
|
|
|
149
117
|
const translateReq = mr.responses
|
|
150
118
|
.new()
|
|
151
|
-
.model("claude-sonnet-4-
|
|
119
|
+
.model("claude-sonnet-4-5")
|
|
152
120
|
.system("Translate the input to French.")
|
|
153
121
|
.user("") // Bound from previous step
|
|
154
122
|
.build();
|
|
@@ -168,10 +136,10 @@ Concurrent LLM calls with optional aggregation:
|
|
|
168
136
|
import { parallel, llmStep } from "@modelrelay/sdk";
|
|
169
137
|
|
|
170
138
|
const gpt4Req = mr.responses.new().model("gpt-4.1").user("Analyze this...").build();
|
|
171
|
-
const claudeReq = mr.responses.new().model("claude-sonnet-4-
|
|
139
|
+
const claudeReq = mr.responses.new().model("claude-sonnet-4-5").user("Analyze this...").build();
|
|
172
140
|
const synthesizeReq = mr.responses
|
|
173
141
|
.new()
|
|
174
|
-
.model("claude-sonnet-4-
|
|
142
|
+
.model("claude-sonnet-4-5")
|
|
175
143
|
.system("Synthesize the analyses into a unified view.")
|
|
176
144
|
.user("") // Bound from join output
|
|
177
145
|
.build();
|
|
@@ -193,7 +161,7 @@ import { mapReduce } from "@modelrelay/sdk";
|
|
|
193
161
|
|
|
194
162
|
const combineReq = mr.responses
|
|
195
163
|
.new()
|
|
196
|
-
.model("claude-sonnet-4-
|
|
164
|
+
.model("claude-sonnet-4-5")
|
|
197
165
|
.system("Combine summaries into a cohesive overview.")
|
|
198
166
|
.user("") // Bound from join output
|
|
199
167
|
.build();
|
|
@@ -213,7 +181,7 @@ For the most common path (**system + user → assistant text**):
|
|
|
213
181
|
|
|
214
182
|
```ts
|
|
215
183
|
const text = await mr.responses.text(
|
|
216
|
-
"claude-sonnet-4-
|
|
184
|
+
"claude-sonnet-4-5",
|
|
217
185
|
"Answer concisely.",
|
|
218
186
|
"Say hi.",
|
|
219
187
|
);
|
|
@@ -234,7 +202,7 @@ To stream only message text deltas:
|
|
|
234
202
|
|
|
235
203
|
```ts
|
|
236
204
|
const deltas = await mr.responses.streamTextDeltas(
|
|
237
|
-
"claude-sonnet-4-
|
|
205
|
+
"claude-sonnet-4-5",
|
|
238
206
|
"Answer concisely.",
|
|
239
207
|
"Say hi.",
|
|
240
208
|
);
|
|
@@ -260,7 +228,7 @@ const Person = z.object({
|
|
|
260
228
|
|
|
261
229
|
// Simple one-call API (recommended)
|
|
262
230
|
const person = await mr.responses.object<z.infer<typeof Person>>({
|
|
263
|
-
model: "claude-sonnet-4-
|
|
231
|
+
model: "claude-sonnet-4-5",
|
|
264
232
|
schema: Person,
|
|
265
233
|
prompt: "Extract: John Doe is 30 years old",
|
|
266
234
|
});
|
|
@@ -274,13 +242,13 @@ For parallel structured output calls:
|
|
|
274
242
|
```ts
|
|
275
243
|
const [security, performance] = await Promise.all([
|
|
276
244
|
mr.responses.object<SecurityReview>({
|
|
277
|
-
model: "claude-sonnet-4-
|
|
245
|
+
model: "claude-sonnet-4-5",
|
|
278
246
|
schema: SecuritySchema,
|
|
279
247
|
system: "You are a security expert.",
|
|
280
248
|
prompt: code,
|
|
281
249
|
}),
|
|
282
250
|
mr.responses.object<PerformanceReview>({
|
|
283
|
-
model: "claude-sonnet-4-
|
|
251
|
+
model: "claude-sonnet-4-5",
|
|
284
252
|
schema: PerformanceSchema,
|
|
285
253
|
system: "You are a performance expert.",
|
|
286
254
|
prompt: code,
|
|
@@ -293,7 +261,7 @@ For more control (retries, custom handlers, metadata):
|
|
|
293
261
|
```ts
|
|
294
262
|
const result = await mr.responses.structured(
|
|
295
263
|
Person,
|
|
296
|
-
mr.responses.new().model("claude-sonnet-4-
|
|
264
|
+
mr.responses.new().model("claude-sonnet-4-5").user("Extract: John Doe is 30").build(),
|
|
297
265
|
{ maxRetries: 2 },
|
|
298
266
|
);
|
|
299
267
|
|
|
@@ -319,7 +287,7 @@ const Article = z.object({
|
|
|
319
287
|
|
|
320
288
|
const stream = await mr.responses.streamStructured(
|
|
321
289
|
Article,
|
|
322
|
-
mr.responses.new().model("claude-sonnet-4-
|
|
290
|
+
mr.responses.new().model("claude-sonnet-4-5").user("Write an article about TypeScript").build(),
|
|
323
291
|
);
|
|
324
292
|
|
|
325
293
|
for await (const event of stream) {
|
|
@@ -387,7 +355,7 @@ import {
|
|
|
387
355
|
|
|
388
356
|
try {
|
|
389
357
|
const response = await mr.responses.text(
|
|
390
|
-
"claude-sonnet-4-
|
|
358
|
+
"claude-sonnet-4-5",
|
|
391
359
|
"You are helpful.",
|
|
392
360
|
"Hello!"
|
|
393
361
|
);
|