@modelrelay/sdk 0.7.0 → 0.14.1
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 +1 -1
- package/dist/index.cjs +1552 -1428
- package/dist/index.d.cts +88 -19
- package/dist/index.d.ts +88 -19
- package/dist/index.js +1542 -1427
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -25,7 +25,8 @@ type StopReason = KnownStopReason | {
|
|
|
25
25
|
declare const Providers: {
|
|
26
26
|
readonly OpenAI: "openai";
|
|
27
27
|
readonly Anthropic: "anthropic";
|
|
28
|
-
readonly
|
|
28
|
+
readonly XAI: "xai";
|
|
29
|
+
readonly GoogleAIStudio: "google-ai-studio";
|
|
29
30
|
readonly Echo: "echo";
|
|
30
31
|
};
|
|
31
32
|
type KnownProvider = (typeof Providers)[keyof typeof Providers];
|
|
@@ -33,13 +34,13 @@ type ProviderId = KnownProvider | {
|
|
|
33
34
|
other: string;
|
|
34
35
|
};
|
|
35
36
|
declare const Models: {
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
39
|
-
readonly
|
|
40
|
-
readonly
|
|
41
|
-
readonly
|
|
42
|
-
readonly
|
|
37
|
+
readonly Gpt4o: "gpt-4o";
|
|
38
|
+
readonly Gpt4oMini: "gpt-4o-mini";
|
|
39
|
+
readonly Gpt51: "gpt-5.1";
|
|
40
|
+
readonly Claude35HaikuLatest: "claude-3-5-haiku-latest";
|
|
41
|
+
readonly Claude35SonnetLatest: "claude-3-5-sonnet-latest";
|
|
42
|
+
readonly ClaudeOpus45: "claude-opus-4-5";
|
|
43
|
+
readonly Claude35Haiku: "claude-3.5-haiku";
|
|
43
44
|
readonly Grok2: "grok-2";
|
|
44
45
|
readonly Grok4_1FastNonReasoning: "grok-4-1-fast-non-reasoning";
|
|
45
46
|
readonly Grok4_1FastReasoning: "grok-4-1-fast-reasoning";
|
|
@@ -48,7 +49,7 @@ declare const Models: {
|
|
|
48
49
|
type KnownModel = (typeof Models)[keyof typeof Models];
|
|
49
50
|
type ModelId = KnownModel | {
|
|
50
51
|
other: string;
|
|
51
|
-
}
|
|
52
|
+
};
|
|
52
53
|
/**
|
|
53
54
|
* Common configuration options for the ModelRelay client.
|
|
54
55
|
*/
|
|
@@ -238,6 +239,10 @@ interface Usage {
|
|
|
238
239
|
outputTokens: number;
|
|
239
240
|
totalTokens: number;
|
|
240
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Creates a Usage object with automatic totalTokens calculation if not provided.
|
|
244
|
+
*/
|
|
245
|
+
declare function createUsage(inputTokens: number, outputTokens: number, totalTokens?: number): Usage;
|
|
241
246
|
interface UsageSummary {
|
|
242
247
|
plan: string;
|
|
243
248
|
planType?: string;
|
|
@@ -265,7 +270,7 @@ interface ChatMessage {
|
|
|
265
270
|
}
|
|
266
271
|
declare const ToolTypes: {
|
|
267
272
|
readonly Function: "function";
|
|
268
|
-
readonly
|
|
273
|
+
readonly Web: "web";
|
|
269
274
|
readonly XSearch: "x_search";
|
|
270
275
|
readonly CodeExecution: "code_execution";
|
|
271
276
|
};
|
|
@@ -275,10 +280,12 @@ interface FunctionTool {
|
|
|
275
280
|
description?: string;
|
|
276
281
|
parameters?: Record<string, unknown>;
|
|
277
282
|
}
|
|
278
|
-
|
|
283
|
+
type WebToolMode = "auto" | "search_only" | "fetch_only" | "search_and_fetch";
|
|
284
|
+
interface WebToolConfig {
|
|
279
285
|
allowedDomains?: string[];
|
|
280
286
|
excludedDomains?: string[];
|
|
281
287
|
maxUses?: number;
|
|
288
|
+
mode?: WebToolMode;
|
|
282
289
|
}
|
|
283
290
|
interface XSearchConfig {
|
|
284
291
|
allowedHandles?: string[];
|
|
@@ -293,7 +300,7 @@ interface CodeExecConfig {
|
|
|
293
300
|
interface Tool {
|
|
294
301
|
type: ToolType;
|
|
295
302
|
function?: FunctionTool;
|
|
296
|
-
|
|
303
|
+
web?: WebToolConfig;
|
|
297
304
|
xSearch?: XSearchConfig;
|
|
298
305
|
codeExecution?: CodeExecConfig;
|
|
299
306
|
}
|
|
@@ -316,7 +323,10 @@ interface ToolCall {
|
|
|
316
323
|
function?: FunctionCall;
|
|
317
324
|
}
|
|
318
325
|
interface ChatCompletionCreateParams {
|
|
319
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Model to use for the request. Optional - if omitted, the tier's default model is used.
|
|
328
|
+
*/
|
|
329
|
+
model?: KnownModel;
|
|
320
330
|
messages: NonEmptyArray<ChatMessage>;
|
|
321
331
|
provider?: ProviderId;
|
|
322
332
|
maxTokens?: number;
|
|
@@ -615,6 +625,14 @@ interface AuthHeaders {
|
|
|
615
625
|
apiKey?: string;
|
|
616
626
|
accessToken?: string;
|
|
617
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates AuthHeaders with an API key.
|
|
630
|
+
*/
|
|
631
|
+
declare function createApiKeyAuth(apiKey: string): AuthHeaders;
|
|
632
|
+
/**
|
|
633
|
+
* Creates AuthHeaders with an access token.
|
|
634
|
+
*/
|
|
635
|
+
declare function createAccessTokenAuth(accessToken: string): AuthHeaders;
|
|
618
636
|
declare class AuthClient {
|
|
619
637
|
private readonly http;
|
|
620
638
|
private readonly apiKey?;
|
|
@@ -734,7 +752,7 @@ interface Customer {
|
|
|
734
752
|
tier_id: string;
|
|
735
753
|
tier_code?: string;
|
|
736
754
|
external_id: string;
|
|
737
|
-
email
|
|
755
|
+
email: string;
|
|
738
756
|
metadata?: CustomerMetadata;
|
|
739
757
|
stripe_customer_id?: string;
|
|
740
758
|
stripe_subscription_id?: string;
|
|
@@ -750,7 +768,7 @@ interface Customer {
|
|
|
750
768
|
interface CustomerCreateRequest {
|
|
751
769
|
tier_id: string;
|
|
752
770
|
external_id: string;
|
|
753
|
-
email
|
|
771
|
+
email: string;
|
|
754
772
|
metadata?: CustomerMetadata;
|
|
755
773
|
}
|
|
756
774
|
/**
|
|
@@ -759,7 +777,7 @@ interface CustomerCreateRequest {
|
|
|
759
777
|
interface CustomerUpsertRequest {
|
|
760
778
|
tier_id: string;
|
|
761
779
|
external_id: string;
|
|
762
|
-
email
|
|
780
|
+
email: string;
|
|
763
781
|
metadata?: CustomerMetadata;
|
|
764
782
|
}
|
|
765
783
|
/**
|
|
@@ -873,6 +891,24 @@ declare class TiersClient {
|
|
|
873
891
|
get(tierId: string): Promise<Tier>;
|
|
874
892
|
}
|
|
875
893
|
|
|
894
|
+
/**
|
|
895
|
+
* API error codes returned by the server.
|
|
896
|
+
* These constants can be used for programmatic error handling.
|
|
897
|
+
*/
|
|
898
|
+
declare const ErrorCodes: {
|
|
899
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
900
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
901
|
+
readonly RATE_LIMIT: "RATE_LIMIT";
|
|
902
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
903
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
904
|
+
readonly CONFLICT: "CONFLICT";
|
|
905
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
906
|
+
readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
|
|
907
|
+
readonly INVALID_INPUT: "INVALID_INPUT";
|
|
908
|
+
readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
|
|
909
|
+
readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
|
|
910
|
+
};
|
|
911
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
876
912
|
type ErrorCategory = "config" | "transport" | "api";
|
|
877
913
|
declare class ModelRelayError extends Error {
|
|
878
914
|
category: ErrorCategory;
|
|
@@ -914,9 +950,41 @@ declare class APIError extends ModelRelayError {
|
|
|
914
950
|
data?: unknown;
|
|
915
951
|
retries?: RetryMetadata;
|
|
916
952
|
});
|
|
953
|
+
/** Returns true if the error is a not found error. */
|
|
954
|
+
isNotFound(): boolean;
|
|
955
|
+
/** Returns true if the error is a validation error. */
|
|
956
|
+
isValidation(): boolean;
|
|
957
|
+
/** Returns true if the error is a rate limit error. */
|
|
958
|
+
isRateLimit(): boolean;
|
|
959
|
+
/** Returns true if the error is an unauthorized error. */
|
|
960
|
+
isUnauthorized(): boolean;
|
|
961
|
+
/** Returns true if the error is a forbidden error. */
|
|
962
|
+
isForbidden(): boolean;
|
|
963
|
+
/** Returns true if the error is a service unavailable error. */
|
|
964
|
+
isUnavailable(): boolean;
|
|
917
965
|
}
|
|
918
966
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
919
967
|
|
|
968
|
+
/**
|
|
969
|
+
* Creates a user message.
|
|
970
|
+
*/
|
|
971
|
+
declare function createUserMessage(content: string): ChatMessage;
|
|
972
|
+
/**
|
|
973
|
+
* Creates an assistant message.
|
|
974
|
+
*/
|
|
975
|
+
declare function createAssistantMessage(content: string): ChatMessage;
|
|
976
|
+
/**
|
|
977
|
+
* Creates a system message.
|
|
978
|
+
*/
|
|
979
|
+
declare function createSystemMessage(content: string): ChatMessage;
|
|
980
|
+
/**
|
|
981
|
+
* Creates a tool call object.
|
|
982
|
+
*/
|
|
983
|
+
declare function createToolCall(id: string, name: string, args: string, type?: ToolType): ToolCall;
|
|
984
|
+
/**
|
|
985
|
+
* Creates a function call object.
|
|
986
|
+
*/
|
|
987
|
+
declare function createFunctionCall(name: string, args: string): FunctionCall;
|
|
920
988
|
/**
|
|
921
989
|
* Interface for Zod-like schema types.
|
|
922
990
|
* Compatible with Zod's ZodType and similar libraries.
|
|
@@ -988,9 +1056,10 @@ declare function createFunctionToolFromSchema(name: string, description: string,
|
|
|
988
1056
|
*/
|
|
989
1057
|
declare function createFunctionTool(name: string, description: string, parameters?: Record<string, unknown>): Tool;
|
|
990
1058
|
/**
|
|
991
|
-
* Creates a web
|
|
1059
|
+
* Creates a web tool with optional domain filters and mode.
|
|
992
1060
|
*/
|
|
993
|
-
declare function
|
|
1061
|
+
declare function createWebTool(options?: {
|
|
1062
|
+
mode?: WebToolMode;
|
|
994
1063
|
allowedDomains?: string[];
|
|
995
1064
|
excludedDomains?: string[];
|
|
996
1065
|
maxUses?: number;
|
|
@@ -1322,4 +1391,4 @@ declare class ModelRelay {
|
|
|
1322
1391
|
constructor(options: ModelRelayOptions);
|
|
1323
1392
|
}
|
|
1324
1393
|
|
|
1325
|
-
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, type CodeExecConfig, 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 ErrorCategory, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownModel, type KnownProvider, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, Models, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, Providers, type RequestContext, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, 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
|
|
1394
|
+
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 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 KnownModel, type KnownProvider, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, Models, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, Providers, type RequestContext, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, 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 WebToolConfig, type WebToolMode, 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, normalizeProvider, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, providerToString, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -25,7 +25,8 @@ type StopReason = KnownStopReason | {
|
|
|
25
25
|
declare const Providers: {
|
|
26
26
|
readonly OpenAI: "openai";
|
|
27
27
|
readonly Anthropic: "anthropic";
|
|
28
|
-
readonly
|
|
28
|
+
readonly XAI: "xai";
|
|
29
|
+
readonly GoogleAIStudio: "google-ai-studio";
|
|
29
30
|
readonly Echo: "echo";
|
|
30
31
|
};
|
|
31
32
|
type KnownProvider = (typeof Providers)[keyof typeof Providers];
|
|
@@ -33,13 +34,13 @@ type ProviderId = KnownProvider | {
|
|
|
33
34
|
other: string;
|
|
34
35
|
};
|
|
35
36
|
declare const Models: {
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
39
|
-
readonly
|
|
40
|
-
readonly
|
|
41
|
-
readonly
|
|
42
|
-
readonly
|
|
37
|
+
readonly Gpt4o: "gpt-4o";
|
|
38
|
+
readonly Gpt4oMini: "gpt-4o-mini";
|
|
39
|
+
readonly Gpt51: "gpt-5.1";
|
|
40
|
+
readonly Claude35HaikuLatest: "claude-3-5-haiku-latest";
|
|
41
|
+
readonly Claude35SonnetLatest: "claude-3-5-sonnet-latest";
|
|
42
|
+
readonly ClaudeOpus45: "claude-opus-4-5";
|
|
43
|
+
readonly Claude35Haiku: "claude-3.5-haiku";
|
|
43
44
|
readonly Grok2: "grok-2";
|
|
44
45
|
readonly Grok4_1FastNonReasoning: "grok-4-1-fast-non-reasoning";
|
|
45
46
|
readonly Grok4_1FastReasoning: "grok-4-1-fast-reasoning";
|
|
@@ -48,7 +49,7 @@ declare const Models: {
|
|
|
48
49
|
type KnownModel = (typeof Models)[keyof typeof Models];
|
|
49
50
|
type ModelId = KnownModel | {
|
|
50
51
|
other: string;
|
|
51
|
-
}
|
|
52
|
+
};
|
|
52
53
|
/**
|
|
53
54
|
* Common configuration options for the ModelRelay client.
|
|
54
55
|
*/
|
|
@@ -238,6 +239,10 @@ interface Usage {
|
|
|
238
239
|
outputTokens: number;
|
|
239
240
|
totalTokens: number;
|
|
240
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Creates a Usage object with automatic totalTokens calculation if not provided.
|
|
244
|
+
*/
|
|
245
|
+
declare function createUsage(inputTokens: number, outputTokens: number, totalTokens?: number): Usage;
|
|
241
246
|
interface UsageSummary {
|
|
242
247
|
plan: string;
|
|
243
248
|
planType?: string;
|
|
@@ -265,7 +270,7 @@ interface ChatMessage {
|
|
|
265
270
|
}
|
|
266
271
|
declare const ToolTypes: {
|
|
267
272
|
readonly Function: "function";
|
|
268
|
-
readonly
|
|
273
|
+
readonly Web: "web";
|
|
269
274
|
readonly XSearch: "x_search";
|
|
270
275
|
readonly CodeExecution: "code_execution";
|
|
271
276
|
};
|
|
@@ -275,10 +280,12 @@ interface FunctionTool {
|
|
|
275
280
|
description?: string;
|
|
276
281
|
parameters?: Record<string, unknown>;
|
|
277
282
|
}
|
|
278
|
-
|
|
283
|
+
type WebToolMode = "auto" | "search_only" | "fetch_only" | "search_and_fetch";
|
|
284
|
+
interface WebToolConfig {
|
|
279
285
|
allowedDomains?: string[];
|
|
280
286
|
excludedDomains?: string[];
|
|
281
287
|
maxUses?: number;
|
|
288
|
+
mode?: WebToolMode;
|
|
282
289
|
}
|
|
283
290
|
interface XSearchConfig {
|
|
284
291
|
allowedHandles?: string[];
|
|
@@ -293,7 +300,7 @@ interface CodeExecConfig {
|
|
|
293
300
|
interface Tool {
|
|
294
301
|
type: ToolType;
|
|
295
302
|
function?: FunctionTool;
|
|
296
|
-
|
|
303
|
+
web?: WebToolConfig;
|
|
297
304
|
xSearch?: XSearchConfig;
|
|
298
305
|
codeExecution?: CodeExecConfig;
|
|
299
306
|
}
|
|
@@ -316,7 +323,10 @@ interface ToolCall {
|
|
|
316
323
|
function?: FunctionCall;
|
|
317
324
|
}
|
|
318
325
|
interface ChatCompletionCreateParams {
|
|
319
|
-
|
|
326
|
+
/**
|
|
327
|
+
* Model to use for the request. Optional - if omitted, the tier's default model is used.
|
|
328
|
+
*/
|
|
329
|
+
model?: KnownModel;
|
|
320
330
|
messages: NonEmptyArray<ChatMessage>;
|
|
321
331
|
provider?: ProviderId;
|
|
322
332
|
maxTokens?: number;
|
|
@@ -615,6 +625,14 @@ interface AuthHeaders {
|
|
|
615
625
|
apiKey?: string;
|
|
616
626
|
accessToken?: string;
|
|
617
627
|
}
|
|
628
|
+
/**
|
|
629
|
+
* Creates AuthHeaders with an API key.
|
|
630
|
+
*/
|
|
631
|
+
declare function createApiKeyAuth(apiKey: string): AuthHeaders;
|
|
632
|
+
/**
|
|
633
|
+
* Creates AuthHeaders with an access token.
|
|
634
|
+
*/
|
|
635
|
+
declare function createAccessTokenAuth(accessToken: string): AuthHeaders;
|
|
618
636
|
declare class AuthClient {
|
|
619
637
|
private readonly http;
|
|
620
638
|
private readonly apiKey?;
|
|
@@ -734,7 +752,7 @@ interface Customer {
|
|
|
734
752
|
tier_id: string;
|
|
735
753
|
tier_code?: string;
|
|
736
754
|
external_id: string;
|
|
737
|
-
email
|
|
755
|
+
email: string;
|
|
738
756
|
metadata?: CustomerMetadata;
|
|
739
757
|
stripe_customer_id?: string;
|
|
740
758
|
stripe_subscription_id?: string;
|
|
@@ -750,7 +768,7 @@ interface Customer {
|
|
|
750
768
|
interface CustomerCreateRequest {
|
|
751
769
|
tier_id: string;
|
|
752
770
|
external_id: string;
|
|
753
|
-
email
|
|
771
|
+
email: string;
|
|
754
772
|
metadata?: CustomerMetadata;
|
|
755
773
|
}
|
|
756
774
|
/**
|
|
@@ -759,7 +777,7 @@ interface CustomerCreateRequest {
|
|
|
759
777
|
interface CustomerUpsertRequest {
|
|
760
778
|
tier_id: string;
|
|
761
779
|
external_id: string;
|
|
762
|
-
email
|
|
780
|
+
email: string;
|
|
763
781
|
metadata?: CustomerMetadata;
|
|
764
782
|
}
|
|
765
783
|
/**
|
|
@@ -873,6 +891,24 @@ declare class TiersClient {
|
|
|
873
891
|
get(tierId: string): Promise<Tier>;
|
|
874
892
|
}
|
|
875
893
|
|
|
894
|
+
/**
|
|
895
|
+
* API error codes returned by the server.
|
|
896
|
+
* These constants can be used for programmatic error handling.
|
|
897
|
+
*/
|
|
898
|
+
declare const ErrorCodes: {
|
|
899
|
+
readonly NOT_FOUND: "NOT_FOUND";
|
|
900
|
+
readonly VALIDATION_ERROR: "VALIDATION_ERROR";
|
|
901
|
+
readonly RATE_LIMIT: "RATE_LIMIT";
|
|
902
|
+
readonly UNAUTHORIZED: "UNAUTHORIZED";
|
|
903
|
+
readonly FORBIDDEN: "FORBIDDEN";
|
|
904
|
+
readonly CONFLICT: "CONFLICT";
|
|
905
|
+
readonly INTERNAL_ERROR: "INTERNAL_ERROR";
|
|
906
|
+
readonly SERVICE_UNAVAILABLE: "SERVICE_UNAVAILABLE";
|
|
907
|
+
readonly INVALID_INPUT: "INVALID_INPUT";
|
|
908
|
+
readonly PAYMENT_REQUIRED: "PAYMENT_REQUIRED";
|
|
909
|
+
readonly METHOD_NOT_ALLOWED: "METHOD_NOT_ALLOWED";
|
|
910
|
+
};
|
|
911
|
+
type ErrorCode = (typeof ErrorCodes)[keyof typeof ErrorCodes];
|
|
876
912
|
type ErrorCategory = "config" | "transport" | "api";
|
|
877
913
|
declare class ModelRelayError extends Error {
|
|
878
914
|
category: ErrorCategory;
|
|
@@ -914,9 +950,41 @@ declare class APIError extends ModelRelayError {
|
|
|
914
950
|
data?: unknown;
|
|
915
951
|
retries?: RetryMetadata;
|
|
916
952
|
});
|
|
953
|
+
/** Returns true if the error is a not found error. */
|
|
954
|
+
isNotFound(): boolean;
|
|
955
|
+
/** Returns true if the error is a validation error. */
|
|
956
|
+
isValidation(): boolean;
|
|
957
|
+
/** Returns true if the error is a rate limit error. */
|
|
958
|
+
isRateLimit(): boolean;
|
|
959
|
+
/** Returns true if the error is an unauthorized error. */
|
|
960
|
+
isUnauthorized(): boolean;
|
|
961
|
+
/** Returns true if the error is a forbidden error. */
|
|
962
|
+
isForbidden(): boolean;
|
|
963
|
+
/** Returns true if the error is a service unavailable error. */
|
|
964
|
+
isUnavailable(): boolean;
|
|
917
965
|
}
|
|
918
966
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
919
967
|
|
|
968
|
+
/**
|
|
969
|
+
* Creates a user message.
|
|
970
|
+
*/
|
|
971
|
+
declare function createUserMessage(content: string): ChatMessage;
|
|
972
|
+
/**
|
|
973
|
+
* Creates an assistant message.
|
|
974
|
+
*/
|
|
975
|
+
declare function createAssistantMessage(content: string): ChatMessage;
|
|
976
|
+
/**
|
|
977
|
+
* Creates a system message.
|
|
978
|
+
*/
|
|
979
|
+
declare function createSystemMessage(content: string): ChatMessage;
|
|
980
|
+
/**
|
|
981
|
+
* Creates a tool call object.
|
|
982
|
+
*/
|
|
983
|
+
declare function createToolCall(id: string, name: string, args: string, type?: ToolType): ToolCall;
|
|
984
|
+
/**
|
|
985
|
+
* Creates a function call object.
|
|
986
|
+
*/
|
|
987
|
+
declare function createFunctionCall(name: string, args: string): FunctionCall;
|
|
920
988
|
/**
|
|
921
989
|
* Interface for Zod-like schema types.
|
|
922
990
|
* Compatible with Zod's ZodType and similar libraries.
|
|
@@ -988,9 +1056,10 @@ declare function createFunctionToolFromSchema(name: string, description: string,
|
|
|
988
1056
|
*/
|
|
989
1057
|
declare function createFunctionTool(name: string, description: string, parameters?: Record<string, unknown>): Tool;
|
|
990
1058
|
/**
|
|
991
|
-
* Creates a web
|
|
1059
|
+
* Creates a web tool with optional domain filters and mode.
|
|
992
1060
|
*/
|
|
993
|
-
declare function
|
|
1061
|
+
declare function createWebTool(options?: {
|
|
1062
|
+
mode?: WebToolMode;
|
|
994
1063
|
allowedDomains?: string[];
|
|
995
1064
|
excludedDomains?: string[];
|
|
996
1065
|
maxUses?: number;
|
|
@@ -1322,4 +1391,4 @@ declare class ModelRelay {
|
|
|
1322
1391
|
constructor(options: ModelRelayOptions);
|
|
1323
1392
|
}
|
|
1324
1393
|
|
|
1325
|
-
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, type CodeExecConfig, 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 ErrorCategory, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownModel, type KnownProvider, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, Models, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, Providers, type RequestContext, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, 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
|
|
1394
|
+
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 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 KnownModel, type KnownProvider, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, Models, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, Providers, type RequestContext, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, 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 WebToolConfig, type WebToolMode, 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, normalizeProvider, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, providerToString, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|