@modelrelay/sdk 1.14.0 → 1.27.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 CHANGED
@@ -245,24 +245,60 @@ for await (const delta of deltas) {
245
245
 
246
246
  ## Structured Outputs with Zod
247
247
 
248
+ The simplest way to get typed structured output:
249
+
248
250
  ```ts
249
- import { ModelRelay, parseSecretKey } from "@modelrelay/sdk";
251
+ import { ModelRelay } from "@modelrelay/sdk";
250
252
  import { z } from "zod";
251
253
 
252
- const mr = new ModelRelay({ key: parseSecretKey("mr_sk_...") });
254
+ const mr = ModelRelay.fromSecretKey("mr_sk_...");
253
255
 
254
256
  const Person = z.object({
255
257
  name: z.string(),
256
258
  age: z.number(),
257
259
  });
258
260
 
261
+ // Simple one-call API (recommended)
262
+ const person = await mr.responses.object<z.infer<typeof Person>>({
263
+ model: "claude-sonnet-4-20250514",
264
+ schema: Person,
265
+ prompt: "Extract: John Doe is 30 years old",
266
+ });
267
+
268
+ console.log(person.name); // "John Doe"
269
+ console.log(person.age); // 30
270
+ ```
271
+
272
+ For parallel structured output calls:
273
+
274
+ ```ts
275
+ const [security, performance] = await Promise.all([
276
+ mr.responses.object<SecurityReview>({
277
+ model: "claude-sonnet-4-20250514",
278
+ schema: SecuritySchema,
279
+ system: "You are a security expert.",
280
+ prompt: code,
281
+ }),
282
+ mr.responses.object<PerformanceReview>({
283
+ model: "claude-sonnet-4-20250514",
284
+ schema: PerformanceSchema,
285
+ system: "You are a performance expert.",
286
+ prompt: code,
287
+ }),
288
+ ]);
289
+ ```
290
+
291
+ For more control (retries, custom handlers, metadata):
292
+
293
+ ```ts
259
294
  const result = await mr.responses.structured(
260
295
  Person,
261
296
  mr.responses.new().model("claude-sonnet-4-20250514").user("Extract: John Doe is 30").build(),
262
297
  { maxRetries: 2 },
263
298
  );
264
299
 
265
- console.log(result.value); // { name: "John Doe", age: 30 }
300
+ console.log(result.value); // { name: "John Doe", age: 30 }
301
+ console.log(result.attempts); // 1
266
302
  ```
267
303
 
268
304
  ## Streaming Structured Outputs
@@ -369,7 +405,7 @@ try {
369
405
  } else if (error instanceof TransportError) {
370
406
  console.log("Network error:", error.message);
371
407
  } else if (error instanceof StreamTimeoutError) {
372
- console.log("Stream timeout:", error.streamKind); // "ttft" | "idle" | "total"
408
+ console.log("Stream timeout:", error.kind); // "ttft" | "idle" | "total"
373
409
  }
374
410
  }
375
411
  ```