@ai-sdk/gateway 4.0.0-beta.23 → 4.0.0-beta.24
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/CHANGELOG.md +6 -0
- package/dist/index.d.mts +62 -1
- package/dist/index.d.ts +62 -1
- package/dist/index.js +246 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +298 -176
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +68 -3
- package/package.json +1 -1
- package/src/gateway-provider.ts +29 -0
- package/src/gateway-spend-report.ts +191 -0
- package/src/index.ts +5 -0
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -64,6 +64,62 @@ interface GatewayCreditsResponse {
|
|
|
64
64
|
totalUsed: string;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
interface GatewaySpendReportParams {
|
|
68
|
+
/** Start date in YYYY-MM-DD format (inclusive) */
|
|
69
|
+
startDate: string;
|
|
70
|
+
/** End date in YYYY-MM-DD format (inclusive) */
|
|
71
|
+
endDate: string;
|
|
72
|
+
/** Primary aggregation dimension. Defaults to 'day'. */
|
|
73
|
+
groupBy?: 'day' | 'user' | 'model' | 'tag' | 'provider' | 'credential_type';
|
|
74
|
+
/** Time granularity when groupBy is 'day'. */
|
|
75
|
+
datePart?: 'day' | 'hour';
|
|
76
|
+
/** Filter to a specific user's spend. */
|
|
77
|
+
userId?: string;
|
|
78
|
+
/** Filter to a specific model (e.g. 'anthropic/claude-sonnet-4.5'). */
|
|
79
|
+
model?: string;
|
|
80
|
+
/** Filter to a specific provider (e.g. 'anthropic'). */
|
|
81
|
+
provider?: string;
|
|
82
|
+
/** Filter to BYOK or system credentials. */
|
|
83
|
+
credentialType?: 'byok' | 'system';
|
|
84
|
+
/** Filter to requests with these tags. */
|
|
85
|
+
tags?: string[];
|
|
86
|
+
}
|
|
87
|
+
interface GatewaySpendReportRow {
|
|
88
|
+
/** Date string (present when groupBy is 'day') */
|
|
89
|
+
day?: string;
|
|
90
|
+
/** Hour timestamp (present when groupBy is 'day' and datePart is 'hour') */
|
|
91
|
+
hour?: string;
|
|
92
|
+
/** User identifier (present when groupBy is 'user') */
|
|
93
|
+
user?: string;
|
|
94
|
+
/** Model identifier (present when groupBy is 'model') */
|
|
95
|
+
model?: string;
|
|
96
|
+
/** Tag value (present when groupBy is 'tag') */
|
|
97
|
+
tag?: string;
|
|
98
|
+
/** Provider name (present when groupBy is 'provider') */
|
|
99
|
+
provider?: string;
|
|
100
|
+
/** Credential type (present when groupBy is 'credential_type') */
|
|
101
|
+
credentialType?: 'byok' | 'system';
|
|
102
|
+
/** Total cost in USD */
|
|
103
|
+
totalCost: number;
|
|
104
|
+
/** Market cost in USD */
|
|
105
|
+
marketCost?: number;
|
|
106
|
+
/** Number of input tokens */
|
|
107
|
+
inputTokens?: number;
|
|
108
|
+
/** Number of output tokens */
|
|
109
|
+
outputTokens?: number;
|
|
110
|
+
/** Number of cached input tokens */
|
|
111
|
+
cachedInputTokens?: number;
|
|
112
|
+
/** Number of cache creation input tokens */
|
|
113
|
+
cacheCreationInputTokens?: number;
|
|
114
|
+
/** Number of reasoning tokens */
|
|
115
|
+
reasoningTokens?: number;
|
|
116
|
+
/** Number of requests */
|
|
117
|
+
requestCount?: number;
|
|
118
|
+
}
|
|
119
|
+
interface GatewaySpendReportResponse {
|
|
120
|
+
results: GatewaySpendReportRow[];
|
|
121
|
+
}
|
|
122
|
+
|
|
67
123
|
type GatewayEmbeddingModelId = 'alibaba/qwen3-embedding-0.6b' | 'alibaba/qwen3-embedding-4b' | 'alibaba/qwen3-embedding-8b' | 'amazon/titan-embed-text-v2' | 'cohere/embed-v4.0' | 'google/gemini-embedding-001' | 'google/gemini-embedding-2' | 'google/text-embedding-005' | 'google/text-multilingual-embedding-002' | 'mistral/codestral-embed' | 'mistral/mistral-embed' | 'openai/text-embedding-3-large' | 'openai/text-embedding-3-small' | 'openai/text-embedding-ada-002' | 'voyage/voyage-3-large' | 'voyage/voyage-3.5' | 'voyage/voyage-3.5-lite' | 'voyage/voyage-4' | 'voyage/voyage-4-large' | 'voyage/voyage-4-lite' | 'voyage/voyage-code-2' | 'voyage/voyage-code-3' | 'voyage/voyage-finance-2' | 'voyage/voyage-law-2' | (string & {});
|
|
68
124
|
|
|
69
125
|
type GatewayImageModelId = 'bfl/flux-2-flex' | 'bfl/flux-2-klein-4b' | 'bfl/flux-2-klein-9b' | 'bfl/flux-2-max' | 'bfl/flux-2-pro' | 'bfl/flux-kontext-max' | 'bfl/flux-kontext-pro' | 'bfl/flux-pro-1.0-fill' | 'bfl/flux-pro-1.1' | 'bfl/flux-pro-1.1-ultra' | 'google/imagen-4.0-fast-generate-001' | 'google/imagen-4.0-generate-001' | 'google/imagen-4.0-ultra-generate-001' | 'openai/gpt-image-1' | 'openai/gpt-image-1-mini' | 'openai/gpt-image-1.5' | 'prodia/flux-fast-schnell' | 'recraft/recraft-v2' | 'recraft/recraft-v3' | 'recraft/recraft-v4' | 'recraft/recraft-v4-pro' | 'xai/grok-imagine-image' | 'xai/grok-imagine-image-pro' | (string & {});
|
|
@@ -370,6 +426,11 @@ interface GatewayProvider extends ProviderV4 {
|
|
|
370
426
|
* Returns credit information for the authenticated user.
|
|
371
427
|
*/
|
|
372
428
|
getCredits(): Promise<GatewayCreditsResponse>;
|
|
429
|
+
/**
|
|
430
|
+
* Returns a spend report with cost, token, and request count data,
|
|
431
|
+
* aggregated by the specified dimension.
|
|
432
|
+
*/
|
|
433
|
+
getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
|
|
373
434
|
/**
|
|
374
435
|
* Creates a model for generating text embeddings.
|
|
375
436
|
*/
|
|
@@ -599,4 +660,4 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
599
660
|
static isInstance(error: unknown): error is GatewayResponseError;
|
|
600
661
|
}
|
|
601
662
|
|
|
602
|
-
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, GatewayResponseError, type GatewayVideoModelId, createGatewayProvider as createGateway, createGatewayProvider, gateway };
|
|
663
|
+
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, GatewayResponseError, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayVideoModelId, createGatewayProvider as createGateway, createGatewayProvider, gateway };
|
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,62 @@ interface GatewayCreditsResponse {
|
|
|
64
64
|
totalUsed: string;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
interface GatewaySpendReportParams {
|
|
68
|
+
/** Start date in YYYY-MM-DD format (inclusive) */
|
|
69
|
+
startDate: string;
|
|
70
|
+
/** End date in YYYY-MM-DD format (inclusive) */
|
|
71
|
+
endDate: string;
|
|
72
|
+
/** Primary aggregation dimension. Defaults to 'day'. */
|
|
73
|
+
groupBy?: 'day' | 'user' | 'model' | 'tag' | 'provider' | 'credential_type';
|
|
74
|
+
/** Time granularity when groupBy is 'day'. */
|
|
75
|
+
datePart?: 'day' | 'hour';
|
|
76
|
+
/** Filter to a specific user's spend. */
|
|
77
|
+
userId?: string;
|
|
78
|
+
/** Filter to a specific model (e.g. 'anthropic/claude-sonnet-4.5'). */
|
|
79
|
+
model?: string;
|
|
80
|
+
/** Filter to a specific provider (e.g. 'anthropic'). */
|
|
81
|
+
provider?: string;
|
|
82
|
+
/** Filter to BYOK or system credentials. */
|
|
83
|
+
credentialType?: 'byok' | 'system';
|
|
84
|
+
/** Filter to requests with these tags. */
|
|
85
|
+
tags?: string[];
|
|
86
|
+
}
|
|
87
|
+
interface GatewaySpendReportRow {
|
|
88
|
+
/** Date string (present when groupBy is 'day') */
|
|
89
|
+
day?: string;
|
|
90
|
+
/** Hour timestamp (present when groupBy is 'day' and datePart is 'hour') */
|
|
91
|
+
hour?: string;
|
|
92
|
+
/** User identifier (present when groupBy is 'user') */
|
|
93
|
+
user?: string;
|
|
94
|
+
/** Model identifier (present when groupBy is 'model') */
|
|
95
|
+
model?: string;
|
|
96
|
+
/** Tag value (present when groupBy is 'tag') */
|
|
97
|
+
tag?: string;
|
|
98
|
+
/** Provider name (present when groupBy is 'provider') */
|
|
99
|
+
provider?: string;
|
|
100
|
+
/** Credential type (present when groupBy is 'credential_type') */
|
|
101
|
+
credentialType?: 'byok' | 'system';
|
|
102
|
+
/** Total cost in USD */
|
|
103
|
+
totalCost: number;
|
|
104
|
+
/** Market cost in USD */
|
|
105
|
+
marketCost?: number;
|
|
106
|
+
/** Number of input tokens */
|
|
107
|
+
inputTokens?: number;
|
|
108
|
+
/** Number of output tokens */
|
|
109
|
+
outputTokens?: number;
|
|
110
|
+
/** Number of cached input tokens */
|
|
111
|
+
cachedInputTokens?: number;
|
|
112
|
+
/** Number of cache creation input tokens */
|
|
113
|
+
cacheCreationInputTokens?: number;
|
|
114
|
+
/** Number of reasoning tokens */
|
|
115
|
+
reasoningTokens?: number;
|
|
116
|
+
/** Number of requests */
|
|
117
|
+
requestCount?: number;
|
|
118
|
+
}
|
|
119
|
+
interface GatewaySpendReportResponse {
|
|
120
|
+
results: GatewaySpendReportRow[];
|
|
121
|
+
}
|
|
122
|
+
|
|
67
123
|
type GatewayEmbeddingModelId = 'alibaba/qwen3-embedding-0.6b' | 'alibaba/qwen3-embedding-4b' | 'alibaba/qwen3-embedding-8b' | 'amazon/titan-embed-text-v2' | 'cohere/embed-v4.0' | 'google/gemini-embedding-001' | 'google/gemini-embedding-2' | 'google/text-embedding-005' | 'google/text-multilingual-embedding-002' | 'mistral/codestral-embed' | 'mistral/mistral-embed' | 'openai/text-embedding-3-large' | 'openai/text-embedding-3-small' | 'openai/text-embedding-ada-002' | 'voyage/voyage-3-large' | 'voyage/voyage-3.5' | 'voyage/voyage-3.5-lite' | 'voyage/voyage-4' | 'voyage/voyage-4-large' | 'voyage/voyage-4-lite' | 'voyage/voyage-code-2' | 'voyage/voyage-code-3' | 'voyage/voyage-finance-2' | 'voyage/voyage-law-2' | (string & {});
|
|
68
124
|
|
|
69
125
|
type GatewayImageModelId = 'bfl/flux-2-flex' | 'bfl/flux-2-klein-4b' | 'bfl/flux-2-klein-9b' | 'bfl/flux-2-max' | 'bfl/flux-2-pro' | 'bfl/flux-kontext-max' | 'bfl/flux-kontext-pro' | 'bfl/flux-pro-1.0-fill' | 'bfl/flux-pro-1.1' | 'bfl/flux-pro-1.1-ultra' | 'google/imagen-4.0-fast-generate-001' | 'google/imagen-4.0-generate-001' | 'google/imagen-4.0-ultra-generate-001' | 'openai/gpt-image-1' | 'openai/gpt-image-1-mini' | 'openai/gpt-image-1.5' | 'prodia/flux-fast-schnell' | 'recraft/recraft-v2' | 'recraft/recraft-v3' | 'recraft/recraft-v4' | 'recraft/recraft-v4-pro' | 'xai/grok-imagine-image' | 'xai/grok-imagine-image-pro' | (string & {});
|
|
@@ -370,6 +426,11 @@ interface GatewayProvider extends ProviderV4 {
|
|
|
370
426
|
* Returns credit information for the authenticated user.
|
|
371
427
|
*/
|
|
372
428
|
getCredits(): Promise<GatewayCreditsResponse>;
|
|
429
|
+
/**
|
|
430
|
+
* Returns a spend report with cost, token, and request count data,
|
|
431
|
+
* aggregated by the specified dimension.
|
|
432
|
+
*/
|
|
433
|
+
getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
|
|
373
434
|
/**
|
|
374
435
|
* Creates a model for generating text embeddings.
|
|
375
436
|
*/
|
|
@@ -599,4 +660,4 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
599
660
|
static isInstance(error: unknown): error is GatewayResponseError;
|
|
600
661
|
}
|
|
601
662
|
|
|
602
|
-
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, GatewayResponseError, type GatewayVideoModelId, createGatewayProvider as createGateway, createGatewayProvider, gateway };
|
|
663
|
+
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, GatewayInternalServerError, GatewayInvalidRequestError, type GatewayLanguageModelEntry, type GatewayProviderOptions as GatewayLanguageModelOptions, type GatewayLanguageModelSpecification, type GatewayLanguageModelEntry as GatewayModelEntry, type GatewayModelId, GatewayModelNotFoundError, type GatewayProvider, type GatewayProviderOptions, type GatewayProviderSettings, GatewayRateLimitError, GatewayResponseError, type GatewaySpendReportParams, type GatewaySpendReportResponse, type GatewaySpendReportRow, type GatewayVideoModelId, createGatewayProvider as createGateway, createGatewayProvider, gateway };
|