@modelrelay/sdk 0.2.0 → 0.5.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/dist/index.d.ts CHANGED
@@ -3,7 +3,54 @@ declare const DEFAULT_BASE_URL = "https://api.modelrelay.ai/api/v1";
3
3
  declare const STAGING_BASE_URL = "https://api-stg.modelrelay.ai/api/v1";
4
4
  declare const SANDBOX_BASE_URL = "https://api.sandbox.modelrelay.ai/api/v1";
5
5
  declare const DEFAULT_CLIENT_HEADER: string;
6
+ declare const DEFAULT_CONNECT_TIMEOUT_MS = 5000;
6
7
  declare const DEFAULT_REQUEST_TIMEOUT_MS = 60000;
8
+ type NonEmptyArray<T> = [T, ...T[]];
9
+ declare const StopReasons: {
10
+ readonly Completed: "completed";
11
+ readonly Stop: "stop";
12
+ readonly StopSequence: "stop_sequence";
13
+ readonly EndTurn: "end_turn";
14
+ readonly MaxTokens: "max_tokens";
15
+ readonly MaxLength: "max_len";
16
+ readonly MaxContext: "max_context";
17
+ readonly ToolCalls: "tool_calls";
18
+ readonly TimeLimit: "time_limit";
19
+ readonly ContentFilter: "content_filter";
20
+ readonly Incomplete: "incomplete";
21
+ readonly Unknown: "unknown";
22
+ };
23
+ type KnownStopReason = (typeof StopReasons)[keyof typeof StopReasons];
24
+ type StopReason = KnownStopReason | {
25
+ other: string;
26
+ };
27
+ declare const Providers: {
28
+ readonly OpenAI: "openai";
29
+ readonly Anthropic: "anthropic";
30
+ readonly Grok: "grok";
31
+ readonly OpenRouter: "openrouter";
32
+ readonly Echo: "echo";
33
+ };
34
+ type KnownProvider = (typeof Providers)[keyof typeof Providers];
35
+ type ProviderId = KnownProvider | {
36
+ other: string;
37
+ };
38
+ declare const Models: {
39
+ readonly OpenAIGpt4o: "openai/gpt-4o";
40
+ readonly OpenAIGpt4oMini: "openai/gpt-4o-mini";
41
+ readonly OpenAIGpt51: "openai/gpt-5.1";
42
+ readonly AnthropicClaude35HaikuLatest: "anthropic/claude-3-5-haiku-latest";
43
+ readonly AnthropicClaude35SonnetLatest: "anthropic/claude-3-5-sonnet-latest";
44
+ readonly AnthropicClaudeOpus45: "anthropic/claude-opus-4-5-20251101";
45
+ readonly OpenRouterClaude35Haiku: "anthropic/claude-3.5-haiku";
46
+ readonly Grok2: "grok-2";
47
+ readonly Grok4Fast: "grok-4-fast";
48
+ readonly Echo1: "echo-1";
49
+ };
50
+ type KnownModel = (typeof Models)[keyof typeof Models];
51
+ type ModelId = KnownModel | {
52
+ other: string;
53
+ } | string;
7
54
  interface ModelRelayOptions {
8
55
  /**
9
56
  * API key (secret or publishable). Publishable keys are required for frontend token exchange.
@@ -20,13 +67,17 @@ interface ModelRelayOptions {
20
67
  baseUrl?: string;
21
68
  fetch?: typeof fetch;
22
69
  /**
23
- * Default end-user metadata used when exchanging publishable keys for frontend tokens.
70
+ * Default customer metadata used when exchanging publishable keys for frontend tokens.
24
71
  */
25
- endUser?: FrontendIdentity;
72
+ customer?: FrontendCustomer;
26
73
  /**
27
74
  * Optional client header override for telemetry.
28
75
  */
29
76
  clientHeader?: string;
77
+ /**
78
+ * Default connect timeout in milliseconds (applies to each attempt).
79
+ */
80
+ connectTimeoutMs?: number;
30
81
  /**
31
82
  * Default request timeout in milliseconds (non-streaming). Set to 0 to disable.
32
83
  */
@@ -43,16 +94,24 @@ interface ModelRelayOptions {
43
94
  * Default metadata merged into every chat completion request.
44
95
  */
45
96
  defaultMetadata?: Record<string, string>;
97
+ /**
98
+ * Optional metrics callbacks for latency/usage.
99
+ */
100
+ metrics?: MetricsCallbacks;
101
+ /**
102
+ * Optional trace/log hooks for request + stream lifecycle.
103
+ */
104
+ trace?: TraceCallbacks;
46
105
  }
47
106
  type Environment = "production" | "staging" | "sandbox";
48
- interface FrontendIdentity {
107
+ interface FrontendCustomer {
49
108
  id: string;
50
109
  deviceId?: string;
51
110
  ttlSeconds?: number;
52
111
  }
53
112
  interface FrontendTokenRequest {
54
113
  publishableKey?: string;
55
- userId: string;
114
+ customerId: string;
56
115
  deviceId?: string;
57
116
  ttlSeconds?: number;
58
117
  }
@@ -66,9 +125,9 @@ interface FrontendToken {
66
125
  tokenScope?: string[];
67
126
  tokenSource?: string;
68
127
  /**
69
- * The end-user identifier used when issuing the token. Added client-side for caching.
128
+ * The customer identifier used when issuing the token. Added client-side for caching.
70
129
  */
71
- endUserId?: string;
130
+ customerId?: string;
72
131
  /**
73
132
  * Publishable key used for issuance. Added client-side for caching.
74
133
  */
@@ -78,53 +137,47 @@ interface FrontendToken {
78
137
  */
79
138
  deviceId?: string;
80
139
  }
81
- interface CheckoutRequest {
82
- endUserId: string;
83
- deviceId?: string;
84
- planId?: string;
85
- plan?: string;
86
- successUrl: string;
87
- cancelUrl: string;
88
- }
89
- interface CheckoutSession {
90
- id: string;
91
- plan: string;
92
- status: string;
93
- url: string;
94
- expiresAt?: Date;
95
- completedAt?: Date;
96
- }
97
- interface EndUserRef {
98
- id: string;
99
- externalId: string;
100
- ownerId: string;
101
- }
102
- interface CheckoutResponse {
103
- endUser: EndUserRef;
104
- session: CheckoutSession;
105
- }
106
140
  interface Usage {
107
141
  inputTokens: number;
108
142
  outputTokens: number;
109
143
  totalTokens: number;
110
144
  }
145
+ interface UsageSummary {
146
+ plan: string;
147
+ planType?: string;
148
+ windowStart?: Date | string;
149
+ windowEnd?: Date | string;
150
+ limit?: number;
151
+ used?: number;
152
+ actionsLimit?: number;
153
+ actionsUsed?: number;
154
+ remaining?: number;
155
+ state?: string;
156
+ }
157
+ interface Project {
158
+ id: string;
159
+ name: string;
160
+ description?: string;
161
+ createdAt?: Date;
162
+ updatedAt?: Date;
163
+ }
111
164
  interface ChatMessage {
112
165
  role: string;
113
166
  content: string;
114
167
  }
115
168
  interface ChatCompletionCreateParams {
116
- model: string;
117
- messages: ChatMessage[];
118
- provider?: string;
169
+ model: ModelId;
170
+ messages: NonEmptyArray<ChatMessage>;
171
+ provider?: ProviderId;
119
172
  maxTokens?: number;
120
173
  temperature?: number;
121
174
  metadata?: Record<string, string>;
122
175
  stop?: string[];
123
176
  stopSequences?: string[];
124
177
  /**
125
- * When using publishable keys, an end-user id is required to mint a frontend token.
178
+ * When using publishable keys, a customer id is required to mint a frontend token.
126
179
  */
127
- endUserId?: string;
180
+ customerId?: string;
128
181
  /**
129
182
  * Opt out of SSE streaming and request a blocking JSON response.
130
183
  */
@@ -136,10 +189,10 @@ interface ChatCompletionCreateParams {
136
189
  }
137
190
  interface ChatCompletionResponse {
138
191
  id: string;
139
- provider: string;
192
+ provider?: ProviderId;
140
193
  content: string[];
141
- stopReason?: string;
142
- model: string;
194
+ stopReason?: StopReason;
195
+ model?: ModelId;
143
196
  usage: Usage;
144
197
  requestId?: string;
145
198
  }
@@ -153,6 +206,67 @@ interface RetryConfig {
153
206
  maxBackoffMs?: number;
154
207
  retryPost?: boolean;
155
208
  }
209
+ interface RetryMetadata {
210
+ attempts: number;
211
+ lastStatus?: number;
212
+ lastError?: string;
213
+ }
214
+ type TransportErrorKind = "timeout" | "connect" | "request" | "other";
215
+ interface RequestContext {
216
+ method: string;
217
+ path: string;
218
+ provider?: ProviderId;
219
+ model?: ModelId;
220
+ requestId?: string;
221
+ responseId?: string;
222
+ }
223
+ interface HttpRequestMetrics {
224
+ latencyMs: number;
225
+ status?: number;
226
+ error?: string;
227
+ retries?: RetryMetadata;
228
+ context: RequestContext;
229
+ }
230
+ interface StreamFirstTokenMetrics {
231
+ latencyMs: number;
232
+ error?: string;
233
+ context: RequestContext;
234
+ }
235
+ interface TokenUsageMetrics {
236
+ usage: Usage;
237
+ context: RequestContext;
238
+ }
239
+ interface MetricsCallbacks {
240
+ httpRequest?: (metrics: HttpRequestMetrics) => void;
241
+ streamFirstToken?: (metrics: StreamFirstTokenMetrics) => void;
242
+ usage?: (metrics: TokenUsageMetrics) => void;
243
+ }
244
+ interface TraceCallbacks {
245
+ requestStart?: (context: RequestContext) => void;
246
+ requestFinish?: (info: {
247
+ context: RequestContext;
248
+ status?: number;
249
+ error?: unknown;
250
+ retries?: RetryMetadata;
251
+ latencyMs: number;
252
+ }) => void;
253
+ streamEvent?: (info: {
254
+ context: RequestContext;
255
+ event: ChatCompletionEvent;
256
+ }) => void;
257
+ streamError?: (info: {
258
+ context: RequestContext;
259
+ error: unknown;
260
+ }) => void;
261
+ }
262
+ declare function mergeMetrics(base?: MetricsCallbacks, override?: MetricsCallbacks): MetricsCallbacks | undefined;
263
+ declare function mergeTrace(base?: TraceCallbacks, override?: TraceCallbacks): TraceCallbacks | undefined;
264
+ declare function normalizeStopReason(value?: unknown): StopReason | undefined;
265
+ declare function stopReasonToString(value?: StopReason): string | undefined;
266
+ declare function normalizeProvider(value?: unknown): ProviderId | undefined;
267
+ declare function providerToString(value?: ProviderId): string | undefined;
268
+ declare function normalizeModelId(value: unknown): ModelId | undefined;
269
+ declare function modelToString(value: ModelId): string;
156
270
  type ChatEventType = "message_start" | "message_delta" | "message_stop" | "ping" | "custom";
157
271
  interface MessageStartData {
158
272
  responseId?: string;
@@ -170,10 +284,10 @@ interface MessageDeltaData {
170
284
  [key: string]: unknown;
171
285
  }
172
286
  interface MessageStopData {
173
- stopReason?: string;
287
+ stopReason?: StopReason;
174
288
  usage?: Usage;
175
289
  responseId?: string;
176
- model?: string;
290
+ model?: ModelId;
177
291
  [key: string]: unknown;
178
292
  }
179
293
  interface ChatCompletionEvent<T = unknown> {
@@ -182,8 +296,8 @@ interface ChatCompletionEvent<T = unknown> {
182
296
  data?: T;
183
297
  textDelta?: string;
184
298
  responseId?: string;
185
- model?: string;
186
- stopReason?: string;
299
+ model?: ModelId;
300
+ stopReason?: StopReason;
187
301
  usage?: Usage;
188
302
  requestId?: string;
189
303
  raw: string;
@@ -191,21 +305,14 @@ interface ChatCompletionEvent<T = unknown> {
191
305
  interface APIFrontendToken {
192
306
  token: string;
193
307
  expires_at?: string;
194
- expiresAt?: string;
195
308
  expires_in?: number;
196
- expiresIn?: number;
197
309
  token_type?: string;
198
- tokenType?: string;
199
310
  key_id?: string;
200
- keyId?: string;
201
311
  session_id?: string;
202
- sessionId?: string;
203
312
  token_scope?: string[];
204
- tokenScope?: string[];
205
313
  token_source?: string;
206
- tokenSource?: string;
207
314
  }
208
- interface APIEndUserRef {
315
+ interface APICustomerRef {
209
316
  id: string;
210
317
  external_id: string;
211
318
  owner_id: string;
@@ -218,28 +325,19 @@ interface APICheckoutSession {
218
325
  expires_at?: string;
219
326
  completed_at?: string;
220
327
  }
221
- interface APICheckoutResponse {
222
- end_user?: APIEndUserRef;
223
- session?: APICheckoutSession;
224
- }
225
328
  interface APIChatUsage {
226
329
  input_tokens?: number;
227
330
  output_tokens?: number;
228
331
  total_tokens?: number;
229
- inputTokens?: number;
230
- outputTokens?: number;
231
- totalTokens?: number;
232
332
  }
233
333
  interface APIChatResponse {
234
334
  id?: string;
235
335
  provider?: string;
236
336
  content?: string | string[];
237
337
  stop_reason?: string;
238
- stopReason?: string;
239
338
  model?: string;
240
339
  usage?: APIChatUsage;
241
340
  response_id?: string;
242
- responseId?: string;
243
341
  message?: {
244
342
  id?: string;
245
343
  model?: string;
@@ -261,11 +359,6 @@ interface APIKey {
261
359
  redactedKey: string;
262
360
  secretKey?: string;
263
361
  }
264
- interface APIKeyCreateRequest {
265
- label: string;
266
- expiresAt?: Date;
267
- kind?: string;
268
- }
269
362
 
270
363
  interface RequestOptions {
271
364
  method?: string;
@@ -288,6 +381,26 @@ interface RequestOptions {
288
381
  * When false, skip the default client timeout (useful for streaming).
289
382
  */
290
383
  useDefaultTimeout?: boolean;
384
+ /**
385
+ * Override the per-request connect timeout in milliseconds (set to 0 to disable).
386
+ */
387
+ connectTimeoutMs?: number;
388
+ /**
389
+ * When false, skip the default connect timeout for this request.
390
+ */
391
+ useDefaultConnectTimeout?: boolean;
392
+ /**
393
+ * Per-request metrics callbacks merged over client defaults.
394
+ */
395
+ metrics?: MetricsCallbacks;
396
+ /**
397
+ * Per-request trace/log hooks merged over client defaults.
398
+ */
399
+ trace?: TraceCallbacks;
400
+ /**
401
+ * Optional request context metadata to propagate to telemetry.
402
+ */
403
+ context?: Partial<RequestContext>;
291
404
  }
292
405
  declare class HTTPClient {
293
406
  private readonly baseUrl;
@@ -296,18 +409,24 @@ declare class HTTPClient {
296
409
  private readonly fetchImpl?;
297
410
  private readonly clientHeader?;
298
411
  private readonly defaultTimeoutMs;
412
+ private readonly defaultConnectTimeoutMs;
299
413
  private readonly retry?;
300
414
  private readonly defaultHeaders;
415
+ private readonly metrics?;
416
+ private readonly trace?;
301
417
  constructor(cfg: {
302
418
  baseUrl?: string;
303
419
  apiKey?: string;
304
420
  accessToken?: string;
305
421
  fetchImpl?: typeof fetch;
306
422
  clientHeader?: string;
423
+ connectTimeoutMs?: number;
307
424
  timeoutMs?: number;
308
425
  retry?: RetryConfig | false;
309
426
  defaultHeaders?: Record<string, string>;
310
427
  environment?: Environment;
428
+ metrics?: MetricsCallbacks;
429
+ trace?: TraceCallbacks;
311
430
  });
312
431
  request(path: string, options?: RequestOptions): Promise<Response>;
313
432
  json<T>(path: string, options?: RequestOptions): Promise<T>;
@@ -316,7 +435,7 @@ declare class HTTPClient {
316
435
  interface AuthConfig {
317
436
  apiKey?: string;
318
437
  accessToken?: string;
319
- endUser?: FrontendIdentity;
438
+ customer?: FrontendCustomer;
320
439
  }
321
440
  interface AuthHeaders {
322
441
  apiKey?: string;
@@ -326,7 +445,7 @@ declare class AuthClient {
326
445
  private readonly http;
327
446
  private readonly apiKey?;
328
447
  private readonly accessToken?;
329
- private readonly endUser?;
448
+ private readonly customer?;
330
449
  private cachedFrontend;
331
450
  constructor(http: HTTPClient, cfg: AuthConfig);
332
451
  /**
@@ -338,7 +457,7 @@ declare class AuthClient {
338
457
  * Determine the correct auth headers for chat completions.
339
458
  * Publishable keys are automatically exchanged for frontend tokens.
340
459
  */
341
- authForChat(endUserId?: string, overrides?: Partial<FrontendIdentity>): Promise<AuthHeaders>;
460
+ authForChat(customerId?: string, overrides?: Partial<FrontendCustomer>): Promise<AuthHeaders>;
342
461
  /**
343
462
  * Billing calls accept either bearer tokens or API keys (including publishable keys).
344
463
  */
@@ -346,24 +465,6 @@ declare class AuthClient {
346
465
  }
347
466
  declare function isPublishableKey(value?: string | null): boolean;
348
467
 
349
- declare class ApiKeysClient {
350
- private readonly http;
351
- constructor(http: HTTPClient);
352
- list(): Promise<APIKey[]>;
353
- create(req: APIKeyCreateRequest): Promise<APIKey>;
354
- delete(id: string): Promise<void>;
355
- }
356
-
357
- declare class BillingClient {
358
- private readonly http;
359
- private readonly auth;
360
- constructor(http: HTTPClient, auth: AuthClient);
361
- /**
362
- * Initiate a Stripe Checkout session for an end user.
363
- */
364
- checkout(params: CheckoutRequest): Promise<CheckoutResponse>;
365
- }
366
-
367
468
  interface ChatRequestOptions {
368
469
  /**
369
470
  * Abort the HTTP request and stream consumption.
@@ -389,22 +490,38 @@ interface ChatRequestOptions {
389
490
  * Override the per-request timeout in milliseconds (set to 0 to disable).
390
491
  */
391
492
  timeoutMs?: number;
493
+ /**
494
+ * Override the connect timeout in milliseconds (set to 0 to disable).
495
+ */
496
+ connectTimeoutMs?: number;
392
497
  /**
393
498
  * Override retry behavior for this call. Set to `false` to disable retries.
394
499
  */
395
500
  retry?: RetryConfig | false;
501
+ /**
502
+ * Per-call metrics callbacks (merged over client defaults).
503
+ */
504
+ metrics?: MetricsCallbacks;
505
+ /**
506
+ * Per-call trace/log hooks (merged over client defaults).
507
+ */
508
+ trace?: TraceCallbacks;
396
509
  }
397
510
  declare class ChatClient {
398
511
  readonly completions: ChatCompletionsClient;
399
512
  constructor(http: HTTPClient, auth: AuthClient, cfg?: {
400
513
  defaultMetadata?: Record<string, string>;
514
+ metrics?: MetricsCallbacks;
515
+ trace?: TraceCallbacks;
401
516
  });
402
517
  }
403
518
  declare class ChatCompletionsClient {
404
519
  private readonly http;
405
520
  private readonly auth;
406
521
  private readonly defaultMetadata?;
407
- constructor(http: HTTPClient, auth: AuthClient, defaultMetadata?: Record<string, string>);
522
+ private readonly metrics?;
523
+ private readonly trace?;
524
+ constructor(http: HTTPClient, auth: AuthClient, defaultMetadata?: Record<string, string>, metrics?: MetricsCallbacks, trace?: TraceCallbacks);
408
525
  create(params: ChatCompletionCreateParams & {
409
526
  stream: false;
410
527
  }, options?: ChatRequestOptions): Promise<ChatCompletionResponse>;
@@ -416,34 +533,224 @@ declare class ChatCompletionsClient {
416
533
  declare class ChatCompletionsStream implements AsyncIterable<ChatCompletionEvent> {
417
534
  private readonly response;
418
535
  private readonly requestId?;
536
+ private context;
537
+ private readonly metrics?;
538
+ private readonly trace?;
539
+ private readonly startedAt;
540
+ private firstTokenEmitted;
419
541
  private closed;
420
- constructor(response: Response, requestId?: string);
542
+ constructor(response: Response, requestId: string | undefined, context: RequestContext, metrics?: MetricsCallbacks, trace?: TraceCallbacks);
421
543
  cancel(reason?: unknown): Promise<void>;
422
544
  [Symbol.asyncIterator](): AsyncIterator<ChatCompletionEvent>;
545
+ private handleStreamEvent;
546
+ private enrichContext;
547
+ private recordFirstToken;
423
548
  }
424
549
 
550
+ /**
551
+ * Customer metadata as an arbitrary key-value object.
552
+ */
553
+ type CustomerMetadata = Record<string, unknown>;
554
+ /**
555
+ * Customer represents a customer in a ModelRelay project.
556
+ */
557
+ interface Customer {
558
+ id: string;
559
+ project_id: string;
560
+ tier_id: string;
561
+ tier_code?: string;
562
+ external_id: string;
563
+ email?: string;
564
+ metadata?: CustomerMetadata;
565
+ stripe_customer_id?: string;
566
+ stripe_subscription_id?: string;
567
+ subscription_status?: string;
568
+ current_period_start?: string;
569
+ current_period_end?: string;
570
+ created_at: string;
571
+ updated_at: string;
572
+ }
573
+ /**
574
+ * Request to create a customer.
575
+ */
576
+ interface CustomerCreateRequest {
577
+ tier_id: string;
578
+ external_id: string;
579
+ email?: string;
580
+ metadata?: CustomerMetadata;
581
+ }
582
+ /**
583
+ * Request to upsert a customer by external_id.
584
+ */
585
+ interface CustomerUpsertRequest {
586
+ tier_id: string;
587
+ external_id: string;
588
+ email?: string;
589
+ metadata?: CustomerMetadata;
590
+ }
591
+ /**
592
+ * Request to create a checkout session.
593
+ */
594
+ interface CheckoutSessionRequest {
595
+ success_url: string;
596
+ cancel_url: string;
597
+ }
598
+ /**
599
+ * Checkout session response.
600
+ */
601
+ interface CheckoutSession {
602
+ session_id: string;
603
+ url: string;
604
+ }
605
+ /**
606
+ * Subscription status response.
607
+ */
608
+ interface SubscriptionStatus {
609
+ active: boolean;
610
+ subscription_id?: string;
611
+ status?: string;
612
+ current_period_start?: string;
613
+ current_period_end?: string;
614
+ }
615
+ interface CustomersClientConfig {
616
+ apiKey?: string;
617
+ }
618
+ /**
619
+ * CustomersClient provides methods to manage customers in a project.
620
+ * Requires a secret key (mr_sk_*) for authentication.
621
+ */
622
+ declare class CustomersClient {
623
+ private readonly http;
624
+ private readonly apiKey?;
625
+ constructor(http: HTTPClient, cfg: CustomersClientConfig);
626
+ private ensureSecretKey;
627
+ /**
628
+ * List all customers in the project.
629
+ */
630
+ list(): Promise<Customer[]>;
631
+ /**
632
+ * Create a new customer in the project.
633
+ */
634
+ create(request: CustomerCreateRequest): Promise<Customer>;
635
+ /**
636
+ * Get a customer by ID.
637
+ */
638
+ get(customerId: string): Promise<Customer>;
639
+ /**
640
+ * Upsert a customer by external_id.
641
+ * If a customer with the given external_id exists, it is updated.
642
+ * Otherwise, a new customer is created.
643
+ */
644
+ upsert(request: CustomerUpsertRequest): Promise<Customer>;
645
+ /**
646
+ * Delete a customer by ID.
647
+ */
648
+ delete(customerId: string): Promise<void>;
649
+ /**
650
+ * Create a Stripe checkout session for a customer.
651
+ */
652
+ createCheckoutSession(customerId: string, request: CheckoutSessionRequest): Promise<CheckoutSession>;
653
+ /**
654
+ * Get the subscription status for a customer.
655
+ */
656
+ getSubscription(customerId: string): Promise<SubscriptionStatus>;
657
+ }
658
+
659
+ /**
660
+ * Billing interval for a tier.
661
+ */
662
+ type PriceInterval = "month" | "year";
663
+ /**
664
+ * Tier represents a pricing tier in a ModelRelay project.
665
+ */
666
+ interface Tier {
667
+ id: string;
668
+ project_id: string;
669
+ tier_code: string;
670
+ display_name: string;
671
+ actions_limit: number;
672
+ token_limit: number;
673
+ stripe_price_id?: string;
674
+ price_amount?: number;
675
+ price_currency?: string;
676
+ price_interval?: PriceInterval;
677
+ trial_days?: number;
678
+ created_at: string;
679
+ updated_at: string;
680
+ }
681
+ interface TiersClientConfig {
682
+ apiKey?: string;
683
+ }
684
+ /**
685
+ * TiersClient provides methods to query tiers in a project.
686
+ * Works with both publishable keys (mr_pk_*) and secret keys (mr_sk_*).
687
+ */
688
+ declare class TiersClient {
689
+ private readonly http;
690
+ private readonly apiKey?;
691
+ constructor(http: HTTPClient, cfg: TiersClientConfig);
692
+ private ensureApiKey;
693
+ /**
694
+ * List all tiers in the project.
695
+ */
696
+ list(): Promise<Tier[]>;
697
+ /**
698
+ * Get a tier by ID.
699
+ */
700
+ get(tierId: string): Promise<Tier>;
701
+ }
702
+
703
+ type ErrorCategory = "config" | "transport" | "api";
425
704
  declare class ModelRelayError extends Error {
426
- status: number;
705
+ category: ErrorCategory;
706
+ status?: number;
427
707
  code?: string;
428
708
  requestId?: string;
429
709
  fields?: FieldError[];
430
710
  data?: unknown;
711
+ retries?: RetryMetadata;
712
+ cause?: unknown;
713
+ constructor(message: string, opts: {
714
+ category: ErrorCategory;
715
+ status?: number;
716
+ code?: string;
717
+ requestId?: string;
718
+ fields?: FieldError[];
719
+ data?: unknown;
720
+ retries?: RetryMetadata;
721
+ cause?: unknown;
722
+ });
723
+ }
724
+ declare class ConfigError extends ModelRelayError {
725
+ constructor(message: string, data?: unknown);
726
+ }
727
+ declare class TransportError extends ModelRelayError {
728
+ kind: TransportErrorKind;
729
+ constructor(message: string, opts: {
730
+ kind: TransportErrorKind;
731
+ retries?: RetryMetadata;
732
+ cause?: unknown;
733
+ });
734
+ }
735
+ declare class APIError extends ModelRelayError {
431
736
  constructor(message: string, opts: {
432
737
  status: number;
433
738
  code?: string;
434
739
  requestId?: string;
435
740
  fields?: FieldError[];
436
741
  data?: unknown;
742
+ retries?: RetryMetadata;
437
743
  });
438
744
  }
745
+ declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
439
746
 
440
747
  declare class ModelRelay {
441
- readonly billing: BillingClient;
442
748
  readonly chat: ChatClient;
443
749
  readonly auth: AuthClient;
444
- readonly apiKeys: ApiKeysClient;
750
+ readonly customers: CustomersClient;
751
+ readonly tiers: TiersClient;
445
752
  readonly baseUrl: string;
446
753
  constructor(options: ModelRelayOptions);
447
754
  }
448
755
 
449
- export { type APIChatResponse, type APIChatUsage, type APICheckoutResponse, type APICheckoutSession, type APIEndUserRef, type APIFrontendToken, type APIKey, type APIKeyCreateRequest, ApiKeysClient, AuthClient, BillingClient, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutRequest, type CheckoutResponse, type CheckoutSession, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_REQUEST_TIMEOUT_MS, type EndUserRef, type Environment, type FieldError, type FrontendIdentity, type FrontendToken, type FrontendTokenRequest, type MessageDeltaData, type MessageStartData, type MessageStopData, ModelRelay, ModelRelayError, type ModelRelayOptions, type RetryConfig, SANDBOX_BASE_URL, SDK_VERSION, STAGING_BASE_URL, type Usage, isPublishableKey };
756
+ export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, ConfigError, type Customer, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type Environment, type ErrorCategory, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenRequest, type HttpRequestMetrics, type KnownModel, type KnownProvider, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, ModelRelayError, type ModelRelayOptions, Models, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, Providers, type RequestContext, type RetryConfig, type RetryMetadata, SANDBOX_BASE_URL, SDK_VERSION, STAGING_BASE_URL, type StopReason, StopReasons, type StreamFirstTokenMetrics, type SubscriptionStatus, type Tier, TiersClient, type TokenUsageMetrics, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeProvider, normalizeStopReason, parseErrorResponse, providerToString, stopReasonToString };