@modelrelay/sdk 0.17.0 → 0.19.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
@@ -347,7 +347,7 @@ function isTokenReusable(token) {
347
347
  // package.json
348
348
  var package_default = {
349
349
  name: "@modelrelay/sdk",
350
- version: "0.17.0",
350
+ version: "0.19.0",
351
351
  description: "TypeScript SDK for the ModelRelay API",
352
352
  type: "module",
353
353
  main: "dist/index.cjs",
@@ -2026,6 +2026,13 @@ var TiersClient = class {
2026
2026
  );
2027
2027
  }
2028
2028
  }
2029
+ ensureSecretKey() {
2030
+ if (!this.apiKey || !this.apiKey.startsWith("mr_sk_")) {
2031
+ throw new ConfigError(
2032
+ "Secret key (mr_sk_*) required for checkout operations"
2033
+ );
2034
+ }
2035
+ }
2029
2036
  /**
2030
2037
  * List all tiers in the project.
2031
2038
  */
@@ -2051,6 +2058,40 @@ var TiersClient = class {
2051
2058
  });
2052
2059
  return response.tier;
2053
2060
  }
2061
+ /**
2062
+ * Create a Stripe checkout session for a tier (Stripe-first flow).
2063
+ *
2064
+ * This enables users to subscribe before authenticating. Stripe collects
2065
+ * the customer's email during checkout. After checkout completes, a
2066
+ * customer record is created with the email from Stripe. The customer
2067
+ * can later be linked to an identity via POST /customers/claim.
2068
+ *
2069
+ * Requires a secret key (mr_sk_*).
2070
+ *
2071
+ * @param tierId - The tier ID to create a checkout session for
2072
+ * @param request - Checkout session request with redirect URLs
2073
+ * @returns Checkout session with Stripe URL
2074
+ */
2075
+ async checkout(tierId, request) {
2076
+ this.ensureSecretKey();
2077
+ if (!tierId?.trim()) {
2078
+ throw new ConfigError("tierId is required");
2079
+ }
2080
+ if (!request.success_url?.trim()) {
2081
+ throw new ConfigError("success_url is required");
2082
+ }
2083
+ if (!request.cancel_url?.trim()) {
2084
+ throw new ConfigError("cancel_url is required");
2085
+ }
2086
+ return await this.http.json(
2087
+ `/tiers/${tierId}/checkout`,
2088
+ {
2089
+ method: "POST",
2090
+ apiKey: this.apiKey,
2091
+ body: request
2092
+ }
2093
+ );
2094
+ }
2054
2095
  };
2055
2096
 
2056
2097
  // src/http.ts
package/dist/index.d.cts CHANGED
@@ -908,6 +908,21 @@ interface Tier {
908
908
  created_at: string;
909
909
  updated_at: string;
910
910
  }
911
+ /**
912
+ * Request to create a tier checkout session (Stripe-first flow).
913
+ * Stripe collects the customer's email during checkout.
914
+ */
915
+ interface TierCheckoutRequest {
916
+ success_url: string;
917
+ cancel_url: string;
918
+ }
919
+ /**
920
+ * Tier checkout session response.
921
+ */
922
+ interface TierCheckoutSession {
923
+ session_id: string;
924
+ url: string;
925
+ }
911
926
  interface TiersClientConfig {
912
927
  apiKey?: string;
913
928
  }
@@ -920,6 +935,7 @@ declare class TiersClient {
920
935
  private readonly apiKey?;
921
936
  constructor(http: HTTPClient, cfg: TiersClientConfig);
922
937
  private ensureApiKey;
938
+ private ensureSecretKey;
923
939
  /**
924
940
  * List all tiers in the project.
925
941
  */
@@ -928,6 +944,21 @@ declare class TiersClient {
928
944
  * Get a tier by ID.
929
945
  */
930
946
  get(tierId: string): Promise<Tier>;
947
+ /**
948
+ * Create a Stripe checkout session for a tier (Stripe-first flow).
949
+ *
950
+ * This enables users to subscribe before authenticating. Stripe collects
951
+ * the customer's email during checkout. After checkout completes, a
952
+ * customer record is created with the email from Stripe. The customer
953
+ * can later be linked to an identity via POST /customers/claim.
954
+ *
955
+ * Requires a secret key (mr_sk_*).
956
+ *
957
+ * @param tierId - The tier ID to create a checkout session for
958
+ * @param request - Checkout session request with redirect URLs
959
+ * @returns Checkout session with Stripe URL
960
+ */
961
+ checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
931
962
  }
932
963
 
933
964
  /**
@@ -1430,4 +1461,4 @@ declare class ModelRelay {
1430
1461
  constructor(options: ModelRelayOptions);
1431
1462
  }
1432
1463
 
1433
- 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 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, 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, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
1464
+ 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 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, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
package/dist/index.d.ts CHANGED
@@ -908,6 +908,21 @@ interface Tier {
908
908
  created_at: string;
909
909
  updated_at: string;
910
910
  }
911
+ /**
912
+ * Request to create a tier checkout session (Stripe-first flow).
913
+ * Stripe collects the customer's email during checkout.
914
+ */
915
+ interface TierCheckoutRequest {
916
+ success_url: string;
917
+ cancel_url: string;
918
+ }
919
+ /**
920
+ * Tier checkout session response.
921
+ */
922
+ interface TierCheckoutSession {
923
+ session_id: string;
924
+ url: string;
925
+ }
911
926
  interface TiersClientConfig {
912
927
  apiKey?: string;
913
928
  }
@@ -920,6 +935,7 @@ declare class TiersClient {
920
935
  private readonly apiKey?;
921
936
  constructor(http: HTTPClient, cfg: TiersClientConfig);
922
937
  private ensureApiKey;
938
+ private ensureSecretKey;
923
939
  /**
924
940
  * List all tiers in the project.
925
941
  */
@@ -928,6 +944,21 @@ declare class TiersClient {
928
944
  * Get a tier by ID.
929
945
  */
930
946
  get(tierId: string): Promise<Tier>;
947
+ /**
948
+ * Create a Stripe checkout session for a tier (Stripe-first flow).
949
+ *
950
+ * This enables users to subscribe before authenticating. Stripe collects
951
+ * the customer's email during checkout. After checkout completes, a
952
+ * customer record is created with the email from Stripe. The customer
953
+ * can later be linked to an identity via POST /customers/claim.
954
+ *
955
+ * Requires a secret key (mr_sk_*).
956
+ *
957
+ * @param tierId - The tier ID to create a checkout session for
958
+ * @param request - Checkout session request with redirect URLs
959
+ * @returns Checkout session with Stripe URL
960
+ */
961
+ checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
931
962
  }
932
963
 
933
964
  /**
@@ -1430,4 +1461,4 @@ declare class ModelRelay {
1430
1461
  constructor(options: ModelRelayOptions);
1431
1462
  }
1432
1463
 
1433
- 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 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, 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, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
1464
+ 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 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, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
package/dist/index.js CHANGED
@@ -261,7 +261,7 @@ function isTokenReusable(token) {
261
261
  // package.json
262
262
  var package_default = {
263
263
  name: "@modelrelay/sdk",
264
- version: "0.17.0",
264
+ version: "0.19.0",
265
265
  description: "TypeScript SDK for the ModelRelay API",
266
266
  type: "module",
267
267
  main: "dist/index.cjs",
@@ -1940,6 +1940,13 @@ var TiersClient = class {
1940
1940
  );
1941
1941
  }
1942
1942
  }
1943
+ ensureSecretKey() {
1944
+ if (!this.apiKey || !this.apiKey.startsWith("mr_sk_")) {
1945
+ throw new ConfigError(
1946
+ "Secret key (mr_sk_*) required for checkout operations"
1947
+ );
1948
+ }
1949
+ }
1943
1950
  /**
1944
1951
  * List all tiers in the project.
1945
1952
  */
@@ -1965,6 +1972,40 @@ var TiersClient = class {
1965
1972
  });
1966
1973
  return response.tier;
1967
1974
  }
1975
+ /**
1976
+ * Create a Stripe checkout session for a tier (Stripe-first flow).
1977
+ *
1978
+ * This enables users to subscribe before authenticating. Stripe collects
1979
+ * the customer's email during checkout. After checkout completes, a
1980
+ * customer record is created with the email from Stripe. The customer
1981
+ * can later be linked to an identity via POST /customers/claim.
1982
+ *
1983
+ * Requires a secret key (mr_sk_*).
1984
+ *
1985
+ * @param tierId - The tier ID to create a checkout session for
1986
+ * @param request - Checkout session request with redirect URLs
1987
+ * @returns Checkout session with Stripe URL
1988
+ */
1989
+ async checkout(tierId, request) {
1990
+ this.ensureSecretKey();
1991
+ if (!tierId?.trim()) {
1992
+ throw new ConfigError("tierId is required");
1993
+ }
1994
+ if (!request.success_url?.trim()) {
1995
+ throw new ConfigError("success_url is required");
1996
+ }
1997
+ if (!request.cancel_url?.trim()) {
1998
+ throw new ConfigError("cancel_url is required");
1999
+ }
2000
+ return await this.http.json(
2001
+ `/tiers/${tierId}/checkout`,
2002
+ {
2003
+ method: "POST",
2004
+ apiKey: this.apiKey,
2005
+ body: request
2006
+ }
2007
+ );
2008
+ }
1968
2009
  };
1969
2010
 
1970
2011
  // src/http.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@modelrelay/sdk",
3
- "version": "0.17.0",
3
+ "version": "0.19.0",
4
4
  "description": "TypeScript SDK for the ModelRelay API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",