@modelrelay/sdk 0.17.0 → 0.18.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.18.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,42 @@ 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. After checkout
2065
+ * completes, a customer record is created with the provided email. The
2066
+ * customer can later be linked to an identity via POST /customers/claim.
2067
+ *
2068
+ * Requires a secret key (mr_sk_*).
2069
+ *
2070
+ * @param tierId - The tier ID to create a checkout session for
2071
+ * @param request - Checkout session request with email and redirect URLs
2072
+ * @returns Checkout session with Stripe URL
2073
+ */
2074
+ async checkout(tierId, request) {
2075
+ this.ensureSecretKey();
2076
+ if (!tierId?.trim()) {
2077
+ throw new ConfigError("tierId is required");
2078
+ }
2079
+ if (!request.email?.trim()) {
2080
+ throw new ConfigError("email is required");
2081
+ }
2082
+ if (!request.success_url?.trim()) {
2083
+ throw new ConfigError("success_url is required");
2084
+ }
2085
+ if (!request.cancel_url?.trim()) {
2086
+ throw new ConfigError("cancel_url is required");
2087
+ }
2088
+ return await this.http.json(
2089
+ `/tiers/${tierId}/checkout`,
2090
+ {
2091
+ method: "POST",
2092
+ apiKey: this.apiKey,
2093
+ body: request
2094
+ }
2095
+ );
2096
+ }
2054
2097
  };
2055
2098
 
2056
2099
  // 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
+ */
914
+ interface TierCheckoutRequest {
915
+ email: string;
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,20 @@ 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. After checkout
951
+ * completes, a customer record is created with the provided email. The
952
+ * customer can later be linked to an identity via POST /customers/claim.
953
+ *
954
+ * Requires a secret key (mr_sk_*).
955
+ *
956
+ * @param tierId - The tier ID to create a checkout session for
957
+ * @param request - Checkout session request with email and redirect URLs
958
+ * @returns Checkout session with Stripe URL
959
+ */
960
+ checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
931
961
  }
932
962
 
933
963
  /**
@@ -1430,4 +1460,4 @@ declare class ModelRelay {
1430
1460
  constructor(options: ModelRelayOptions);
1431
1461
  }
1432
1462
 
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 };
1463
+ 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
+ */
914
+ interface TierCheckoutRequest {
915
+ email: string;
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,20 @@ 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. After checkout
951
+ * completes, a customer record is created with the provided email. The
952
+ * customer can later be linked to an identity via POST /customers/claim.
953
+ *
954
+ * Requires a secret key (mr_sk_*).
955
+ *
956
+ * @param tierId - The tier ID to create a checkout session for
957
+ * @param request - Checkout session request with email and redirect URLs
958
+ * @returns Checkout session with Stripe URL
959
+ */
960
+ checkout(tierId: string, request: TierCheckoutRequest): Promise<TierCheckoutSession>;
931
961
  }
932
962
 
933
963
  /**
@@ -1430,4 +1460,4 @@ declare class ModelRelay {
1430
1460
  constructor(options: ModelRelayOptions);
1431
1461
  }
1432
1462
 
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 };
1463
+ 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.18.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,42 @@ 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. After checkout
1979
+ * completes, a customer record is created with the provided email. The
1980
+ * customer can later be linked to an identity via POST /customers/claim.
1981
+ *
1982
+ * Requires a secret key (mr_sk_*).
1983
+ *
1984
+ * @param tierId - The tier ID to create a checkout session for
1985
+ * @param request - Checkout session request with email and redirect URLs
1986
+ * @returns Checkout session with Stripe URL
1987
+ */
1988
+ async checkout(tierId, request) {
1989
+ this.ensureSecretKey();
1990
+ if (!tierId?.trim()) {
1991
+ throw new ConfigError("tierId is required");
1992
+ }
1993
+ if (!request.email?.trim()) {
1994
+ throw new ConfigError("email is required");
1995
+ }
1996
+ if (!request.success_url?.trim()) {
1997
+ throw new ConfigError("success_url is required");
1998
+ }
1999
+ if (!request.cancel_url?.trim()) {
2000
+ throw new ConfigError("cancel_url is required");
2001
+ }
2002
+ return await this.http.json(
2003
+ `/tiers/${tierId}/checkout`,
2004
+ {
2005
+ method: "POST",
2006
+ apiKey: this.apiKey,
2007
+ body: request
2008
+ }
2009
+ );
2010
+ }
1968
2011
  };
1969
2012
 
1970
2013
  // 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.18.0",
4
4
  "description": "TypeScript SDK for the ModelRelay API",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",