@modelrelay/sdk 0.22.0 → 0.23.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.cjs CHANGED
@@ -354,7 +354,6 @@ var AuthClient = class {
354
354
  );
355
355
  const token = normalizeFrontendToken(response, {
356
356
  publishableKey,
357
- customerId,
358
357
  deviceId
359
358
  });
360
359
  this.cachedFrontend.set(cacheKey, token);
@@ -406,17 +405,17 @@ function isPublishableKey(value) {
406
405
  return value.trim().toLowerCase().startsWith("mr_pk_");
407
406
  }
408
407
  function normalizeFrontendToken(payload, meta) {
409
- const expiresAt = payload.expires_at;
410
408
  return {
411
409
  token: payload.token,
412
- expiresAt: expiresAt ? new Date(expiresAt) : void 0,
410
+ expiresAt: new Date(payload.expires_at),
413
411
  expiresIn: payload.expires_in,
414
412
  tokenType: payload.token_type,
415
413
  keyId: payload.key_id,
416
414
  sessionId: payload.session_id,
417
- tokenScope: payload.token_scope,
418
- tokenSource: payload.token_source,
419
- customerId: meta.customerId,
415
+ projectId: payload.project_id,
416
+ customerId: payload.customer_id,
417
+ customerExternalId: payload.customer_external_id,
418
+ tierCode: payload.tier_code,
420
419
  publishableKey: meta.publishableKey,
421
420
  deviceId: meta.deviceId
422
421
  };
@@ -425,9 +424,6 @@ function isTokenReusable(token) {
425
424
  if (!token.token) {
426
425
  return false;
427
426
  }
428
- if (!token.expiresAt) {
429
- return true;
430
- }
431
427
  return token.expiresAt.getTime() - Date.now() > 6e4;
432
428
  }
433
429
 
package/dist/index.d.cts CHANGED
@@ -211,19 +211,29 @@ interface FrontendTokenAutoProvisionRequest {
211
211
  /** Optional TTL in seconds for the issued token. */
212
212
  ttlSeconds?: number;
213
213
  }
214
+ /** Token type for OAuth2 bearer tokens. */
215
+ type TokenType = "Bearer";
214
216
  interface FrontendToken {
217
+ /** The bearer token for authenticating LLM requests. */
215
218
  token: string;
216
- expiresAt?: Date;
217
- expiresIn?: number;
218
- tokenType?: string;
219
- keyId?: string;
220
- sessionId?: string;
221
- tokenScope?: string[];
222
- tokenSource?: string;
223
- /**
224
- * The customer identifier used when issuing the token. Added client-side for caching.
225
- */
226
- customerId?: string;
219
+ /** When the token expires. */
220
+ expiresAt: Date;
221
+ /** Seconds until the token expires. */
222
+ expiresIn: number;
223
+ /** Token type, always "Bearer". */
224
+ tokenType: TokenType;
225
+ /** The publishable key ID that issued this token. */
226
+ keyId: string;
227
+ /** Unique session identifier for this token. */
228
+ sessionId: string;
229
+ /** The project ID this token is scoped to. */
230
+ projectId: string;
231
+ /** The internal customer ID (UUID). */
232
+ customerId: string;
233
+ /** The external customer ID provided by the application. */
234
+ customerExternalId: string;
235
+ /** The tier code for the customer (e.g., "free", "pro", "enterprise"). */
236
+ tierCode: string;
227
237
  /**
228
238
  * Publishable key used for issuance. Added client-side for caching.
229
239
  */
@@ -514,13 +524,15 @@ interface StructuredJSONEvent<T> {
514
524
  }
515
525
  interface APIFrontendToken {
516
526
  token: string;
517
- expires_at?: string;
518
- expires_in?: number;
519
- token_type?: string;
520
- key_id?: string;
521
- session_id?: string;
522
- token_scope?: string[];
523
- token_source?: string;
527
+ expires_at: string;
528
+ expires_in: number;
529
+ token_type: TokenType;
530
+ key_id: string;
531
+ session_id: string;
532
+ project_id: string;
533
+ customer_id: string;
534
+ customer_external_id: string;
535
+ tier_code: string;
524
536
  }
525
537
  interface APICustomerRef {
526
538
  id: string;
@@ -1546,4 +1558,4 @@ declare class ModelRelay {
1546
1558
  constructor(options: ModelRelayOptions);
1547
1559
  }
1548
1560
 
1549
- export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
1561
+ export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenType, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -211,19 +211,29 @@ interface FrontendTokenAutoProvisionRequest {
211
211
  /** Optional TTL in seconds for the issued token. */
212
212
  ttlSeconds?: number;
213
213
  }
214
+ /** Token type for OAuth2 bearer tokens. */
215
+ type TokenType = "Bearer";
214
216
  interface FrontendToken {
217
+ /** The bearer token for authenticating LLM requests. */
215
218
  token: string;
216
- expiresAt?: Date;
217
- expiresIn?: number;
218
- tokenType?: string;
219
- keyId?: string;
220
- sessionId?: string;
221
- tokenScope?: string[];
222
- tokenSource?: string;
223
- /**
224
- * The customer identifier used when issuing the token. Added client-side for caching.
225
- */
226
- customerId?: string;
219
+ /** When the token expires. */
220
+ expiresAt: Date;
221
+ /** Seconds until the token expires. */
222
+ expiresIn: number;
223
+ /** Token type, always "Bearer". */
224
+ tokenType: TokenType;
225
+ /** The publishable key ID that issued this token. */
226
+ keyId: string;
227
+ /** Unique session identifier for this token. */
228
+ sessionId: string;
229
+ /** The project ID this token is scoped to. */
230
+ projectId: string;
231
+ /** The internal customer ID (UUID). */
232
+ customerId: string;
233
+ /** The external customer ID provided by the application. */
234
+ customerExternalId: string;
235
+ /** The tier code for the customer (e.g., "free", "pro", "enterprise"). */
236
+ tierCode: string;
227
237
  /**
228
238
  * Publishable key used for issuance. Added client-side for caching.
229
239
  */
@@ -514,13 +524,15 @@ interface StructuredJSONEvent<T> {
514
524
  }
515
525
  interface APIFrontendToken {
516
526
  token: string;
517
- expires_at?: string;
518
- expires_in?: number;
519
- token_type?: string;
520
- key_id?: string;
521
- session_id?: string;
522
- token_scope?: string[];
523
- token_source?: string;
527
+ expires_at: string;
528
+ expires_in: number;
529
+ token_type: TokenType;
530
+ key_id: string;
531
+ session_id: string;
532
+ project_id: string;
533
+ customer_id: string;
534
+ customer_external_id: string;
535
+ tier_code: string;
524
536
  }
525
537
  interface APICustomerRef {
526
538
  id: string;
@@ -1546,4 +1558,4 @@ declare class ModelRelay {
1546
1558
  constructor(options: ModelRelayOptions);
1547
1559
  }
1548
1560
 
1549
- export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
1561
+ export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenType, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
package/dist/index.js CHANGED
@@ -264,7 +264,6 @@ var AuthClient = class {
264
264
  );
265
265
  const token = normalizeFrontendToken(response, {
266
266
  publishableKey,
267
- customerId,
268
267
  deviceId
269
268
  });
270
269
  this.cachedFrontend.set(cacheKey, token);
@@ -316,17 +315,17 @@ function isPublishableKey(value) {
316
315
  return value.trim().toLowerCase().startsWith("mr_pk_");
317
316
  }
318
317
  function normalizeFrontendToken(payload, meta) {
319
- const expiresAt = payload.expires_at;
320
318
  return {
321
319
  token: payload.token,
322
- expiresAt: expiresAt ? new Date(expiresAt) : void 0,
320
+ expiresAt: new Date(payload.expires_at),
323
321
  expiresIn: payload.expires_in,
324
322
  tokenType: payload.token_type,
325
323
  keyId: payload.key_id,
326
324
  sessionId: payload.session_id,
327
- tokenScope: payload.token_scope,
328
- tokenSource: payload.token_source,
329
- customerId: meta.customerId,
325
+ projectId: payload.project_id,
326
+ customerId: payload.customer_id,
327
+ customerExternalId: payload.customer_external_id,
328
+ tierCode: payload.tier_code,
330
329
  publishableKey: meta.publishableKey,
331
330
  deviceId: meta.deviceId
332
331
  };
@@ -335,9 +334,6 @@ function isTokenReusable(token) {
335
334
  if (!token.token) {
336
335
  return false;
337
336
  }
338
- if (!token.expiresAt) {
339
- return true;
340
- }
341
337
  return token.expiresAt.getTime() - Date.now() > 6e4;
342
338
  }
343
339
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelrelay/sdk",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "TypeScript SDK for the ModelRelay API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -13,28 +13,30 @@
13
13
  "require": "./dist/index.cjs"
14
14
  }
15
15
  },
16
- "publishConfig": { "access": "public" },
17
- "files": [
18
- "dist"
19
- ],
20
- "scripts": {
21
- "build": "tsup src/index.ts --format esm,cjs --dts",
22
- "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
23
- "lint": "tsc --noEmit",
24
- "test": "vitest run"
25
- },
26
- "keywords": [
27
- "modelrelay",
28
- "llm",
29
- "sdk",
30
- "typescript"
31
- ],
32
- "author": "Shane Vitarana",
33
- "license": "Apache-2.0",
34
- "devDependencies": {
35
- "tsup": "^8.2.4",
36
- "typescript": "^5.6.3",
37
- "vitest": "^2.1.4",
38
- "zod": "^3.23.0"
39
- }
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "build": "tsup src/index.ts --format esm,cjs --dts",
24
+ "dev": "tsup src/index.ts --format esm,cjs --dts --watch",
25
+ "lint": "tsc --noEmit",
26
+ "test": "vitest run"
27
+ },
28
+ "keywords": [
29
+ "modelrelay",
30
+ "llm",
31
+ "sdk",
32
+ "typescript"
33
+ ],
34
+ "author": "Shane Vitarana",
35
+ "license": "Apache-2.0",
36
+ "devDependencies": {
37
+ "tsup": "^8.2.4",
38
+ "typescript": "^5.6.3",
39
+ "vitest": "^2.1.4",
40
+ "zod": "^3.23.0"
41
+ }
40
42
  }