@modelrelay/sdk 1.3.2 → 1.10.3

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
@@ -47,7 +47,7 @@ import { CustomerTokenProvider, ModelRelay } from "@modelrelay/sdk";
47
47
 
48
48
  const tokenProvider = new CustomerTokenProvider({
49
49
  secretKey: process.env.MODELRELAY_API_KEY!,
50
- request: { projectId: "proj_...", customerId: "cust_..." },
50
+ request: { customerId: "customer_..." },
51
51
  });
52
52
 
53
53
  const mr = new ModelRelay({ tokenProvider });
@@ -81,7 +81,7 @@ for await (const event of stream) {
81
81
  import { ModelRelay } from "@modelrelay/sdk";
82
82
 
83
83
  const mr = ModelRelay.fromSecretKey("mr_sk_...");
84
- const customer = mr.forCustomer("cust_abc123");
84
+ const customer = mr.forCustomer("customer_abc123");
85
85
 
86
86
  const text = await customer.responses.text(
87
87
  "You are a helpful assistant.",
@@ -96,7 +96,7 @@ import { z } from "zod";
96
96
  import { ModelRelay, outputFormatFromZod } from "@modelrelay/sdk";
97
97
 
98
98
  const mr = ModelRelay.fromSecretKey("mr_sk_...");
99
- const customer = mr.forCustomer("cust_abc123");
99
+ const customer = mr.forCustomer("customer_abc123");
100
100
 
101
101
  const schema = z.object({
102
102
  summary: z.string(),
@@ -122,7 +122,7 @@ You can also pass a single object to `textForCustomer`:
122
122
 
123
123
  ```ts
124
124
  const text = await mr.responses.textForCustomer({
125
- customerId: "cust_abc123",
125
+ customerId: "customer_abc123",
126
126
  system: "You are a helpful assistant.",
127
127
  user: "Summarize Q4 results",
128
128
  });
@@ -309,7 +309,7 @@ for await (const event of stream) {
309
309
 
310
310
  ## Customer-Attributed Requests
311
311
 
312
- For metered billing, use `customerId()` — the customer's tier determines the model and `model` can be omitted:
312
+ For metered billing, use `customerId()` — the customer's subscription tier determines the model and `model` can be omitted:
313
313
 
314
314
  ```ts
315
315
  const req = mr.responses
@@ -326,19 +326,57 @@ const stream = await mr.responses.stream(req);
326
326
  ```ts
327
327
  // Create/update customer
328
328
  const customer = await mr.customers.upsert({
329
- tier_id: "tier-uuid",
330
329
  external_id: "your-user-id",
331
330
  email: "user@example.com",
332
331
  });
333
332
 
334
333
  // Create checkout session for subscription billing
335
- const session = await mr.customers.createCheckoutSession(customer.id, {
334
+ const session = await mr.customers.subscribe(customer.customer.id, {
335
+ tier_id: "tier-uuid",
336
336
  success_url: "https://myapp.com/success",
337
337
  cancel_url: "https://myapp.com/cancel",
338
338
  });
339
339
 
340
340
  // Check subscription status
341
- const status = await mr.customers.getSubscription(customer.id);
341
+ const status = await mr.customers.getSubscription(customer.customer.id);
342
+ ```
343
+
344
+ ## Error Handling
345
+
346
+ Errors are typed so callers can branch cleanly:
347
+
348
+ ```ts
349
+ import {
350
+ ModelRelay,
351
+ APIError,
352
+ TransportError,
353
+ StreamTimeoutError,
354
+ ConfigError,
355
+ } from "@modelrelay/sdk";
356
+
357
+ try {
358
+ const response = await mr.responses.text(
359
+ "claude-sonnet-4-20250514",
360
+ "You are helpful.",
361
+ "Hello!"
362
+ );
363
+ } catch (error) {
364
+ if (error instanceof APIError) {
365
+ console.log("Status:", error.status);
366
+ console.log("Code:", error.code);
367
+ console.log("Message:", error.message);
368
+
369
+ if (error.isRateLimit()) {
370
+ // Back off and retry
371
+ } else if (error.isUnauthorized()) {
372
+ // Re-authenticate
373
+ }
374
+ } else if (error instanceof TransportError) {
375
+ console.log("Network error:", error.message);
376
+ } else if (error instanceof StreamTimeoutError) {
377
+ console.log("Stream timeout:", error.streamKind); // "ttft" | "idle" | "total"
378
+ }
379
+ }
342
380
  ```
343
381
 
344
382
  ## Configuration
@@ -351,3 +389,14 @@ const mr = new ModelRelay({
351
389
  retry: { maxAttempts: 3 },
352
390
  });
353
391
  ```
392
+
393
+ ## Documentation
394
+
395
+ For detailed guides and API reference, visit [docs.modelrelay.ai](https://docs.modelrelay.ai):
396
+
397
+ - [First Request](https://docs.modelrelay.ai/getting-started/first-request) — Make your first API call
398
+ - [Streaming](https://docs.modelrelay.ai/guides/streaming) — Real-time response streaming
399
+ - [Structured Output](https://docs.modelrelay.ai/guides/structured-output) — Get typed JSON responses
400
+ - [Tool Use](https://docs.modelrelay.ai/guides/tools) — Let models call functions
401
+ - [Error Handling](https://docs.modelrelay.ai/guides/error-handling) — Handle errors gracefully
402
+ - [Workflows](https://docs.modelrelay.ai/guides/workflows) — Multi-step AI pipelines