@ai-sdk/gateway 4.0.0-beta.23 → 4.0.0-beta.25
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 +12 -0
- package/dist/index.d.mts +110 -1
- package/dist/index.d.ts +110 -1
- package/dist/index.js +346 -131
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +405 -176
- package/dist/index.mjs.map +1 -1
- package/docs/00-ai-gateway.mdx +148 -3
- package/package.json +1 -1
- package/src/gateway-generation-info.ts +147 -0
- package/src/gateway-provider.ts +58 -0
- package/src/gateway-spend-report.ts +191 -0
- package/src/index.ts +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @ai-sdk/gateway
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.25
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 435895b: feat (provider/gateway): add get-generation support
|
|
8
|
+
|
|
9
|
+
## 4.0.0-beta.24
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- d30466c: feat (provider/gateway): add spend reporting support
|
|
14
|
+
|
|
3
15
|
## 4.0.0-beta.23
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
|
@@ -64,6 +64,105 @@ 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
|
+
|
|
123
|
+
interface GatewayGenerationInfoParams {
|
|
124
|
+
/** The generation ID to look up (format: gen_<ulid>) */
|
|
125
|
+
id: string;
|
|
126
|
+
}
|
|
127
|
+
interface GatewayGenerationInfo {
|
|
128
|
+
/** The generation ID */
|
|
129
|
+
id: string;
|
|
130
|
+
/** Total cost in USD */
|
|
131
|
+
totalCost: number;
|
|
132
|
+
/** Upstream inference cost in USD (BYOK only) */
|
|
133
|
+
upstreamInferenceCost: number;
|
|
134
|
+
/** Usage cost in USD (same as totalCost) */
|
|
135
|
+
usage: number;
|
|
136
|
+
/** ISO 8601 timestamp when the generation was created */
|
|
137
|
+
createdAt: string;
|
|
138
|
+
/** Model identifier */
|
|
139
|
+
model: string;
|
|
140
|
+
/** Whether BYOK credentials were used */
|
|
141
|
+
isByok: boolean;
|
|
142
|
+
/** Provider that served this generation */
|
|
143
|
+
providerName: string;
|
|
144
|
+
/** Whether streaming was used */
|
|
145
|
+
streamed: boolean;
|
|
146
|
+
/** Finish reason (e.g. 'stop') */
|
|
147
|
+
finishReason: string;
|
|
148
|
+
/** Time to first token in milliseconds */
|
|
149
|
+
latency: number;
|
|
150
|
+
/** Total generation time in milliseconds */
|
|
151
|
+
generationTime: number;
|
|
152
|
+
/** Number of prompt tokens */
|
|
153
|
+
promptTokens: number;
|
|
154
|
+
/** Number of completion tokens */
|
|
155
|
+
completionTokens: number;
|
|
156
|
+
/** Reasoning tokens used */
|
|
157
|
+
reasoningTokens: number;
|
|
158
|
+
/** Cached tokens used */
|
|
159
|
+
cachedTokens: number;
|
|
160
|
+
/** Cache creation input tokens */
|
|
161
|
+
cacheCreationTokens: number;
|
|
162
|
+
/** Billable web search calls */
|
|
163
|
+
billableWebSearchCalls: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
67
166
|
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
167
|
|
|
69
168
|
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 +469,16 @@ interface GatewayProvider extends ProviderV4 {
|
|
|
370
469
|
* Returns credit information for the authenticated user.
|
|
371
470
|
*/
|
|
372
471
|
getCredits(): Promise<GatewayCreditsResponse>;
|
|
472
|
+
/**
|
|
473
|
+
* Returns a spend report with cost, token, and request count data,
|
|
474
|
+
* aggregated by the specified dimension.
|
|
475
|
+
*/
|
|
476
|
+
getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
|
|
477
|
+
/**
|
|
478
|
+
* Returns detailed information about a specific generation by its ID,
|
|
479
|
+
* including cost, token usage, latency, and provider details.
|
|
480
|
+
*/
|
|
481
|
+
getGenerationInfo(params: GatewayGenerationInfoParams): Promise<GatewayGenerationInfo>;
|
|
373
482
|
/**
|
|
374
483
|
* Creates a model for generating text embeddings.
|
|
375
484
|
*/
|
|
@@ -599,4 +708,4 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
599
708
|
static isInstance(error: unknown): error is GatewayResponseError;
|
|
600
709
|
}
|
|
601
710
|
|
|
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 };
|
|
711
|
+
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, type GatewayGenerationInfo, type GatewayGenerationInfoParams, 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,105 @@ 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
|
+
|
|
123
|
+
interface GatewayGenerationInfoParams {
|
|
124
|
+
/** The generation ID to look up (format: gen_<ulid>) */
|
|
125
|
+
id: string;
|
|
126
|
+
}
|
|
127
|
+
interface GatewayGenerationInfo {
|
|
128
|
+
/** The generation ID */
|
|
129
|
+
id: string;
|
|
130
|
+
/** Total cost in USD */
|
|
131
|
+
totalCost: number;
|
|
132
|
+
/** Upstream inference cost in USD (BYOK only) */
|
|
133
|
+
upstreamInferenceCost: number;
|
|
134
|
+
/** Usage cost in USD (same as totalCost) */
|
|
135
|
+
usage: number;
|
|
136
|
+
/** ISO 8601 timestamp when the generation was created */
|
|
137
|
+
createdAt: string;
|
|
138
|
+
/** Model identifier */
|
|
139
|
+
model: string;
|
|
140
|
+
/** Whether BYOK credentials were used */
|
|
141
|
+
isByok: boolean;
|
|
142
|
+
/** Provider that served this generation */
|
|
143
|
+
providerName: string;
|
|
144
|
+
/** Whether streaming was used */
|
|
145
|
+
streamed: boolean;
|
|
146
|
+
/** Finish reason (e.g. 'stop') */
|
|
147
|
+
finishReason: string;
|
|
148
|
+
/** Time to first token in milliseconds */
|
|
149
|
+
latency: number;
|
|
150
|
+
/** Total generation time in milliseconds */
|
|
151
|
+
generationTime: number;
|
|
152
|
+
/** Number of prompt tokens */
|
|
153
|
+
promptTokens: number;
|
|
154
|
+
/** Number of completion tokens */
|
|
155
|
+
completionTokens: number;
|
|
156
|
+
/** Reasoning tokens used */
|
|
157
|
+
reasoningTokens: number;
|
|
158
|
+
/** Cached tokens used */
|
|
159
|
+
cachedTokens: number;
|
|
160
|
+
/** Cache creation input tokens */
|
|
161
|
+
cacheCreationTokens: number;
|
|
162
|
+
/** Billable web search calls */
|
|
163
|
+
billableWebSearchCalls: number;
|
|
164
|
+
}
|
|
165
|
+
|
|
67
166
|
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
167
|
|
|
69
168
|
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 +469,16 @@ interface GatewayProvider extends ProviderV4 {
|
|
|
370
469
|
* Returns credit information for the authenticated user.
|
|
371
470
|
*/
|
|
372
471
|
getCredits(): Promise<GatewayCreditsResponse>;
|
|
472
|
+
/**
|
|
473
|
+
* Returns a spend report with cost, token, and request count data,
|
|
474
|
+
* aggregated by the specified dimension.
|
|
475
|
+
*/
|
|
476
|
+
getSpendReport(params: GatewaySpendReportParams): Promise<GatewaySpendReportResponse>;
|
|
477
|
+
/**
|
|
478
|
+
* Returns detailed information about a specific generation by its ID,
|
|
479
|
+
* including cost, token usage, latency, and provider details.
|
|
480
|
+
*/
|
|
481
|
+
getGenerationInfo(params: GatewayGenerationInfoParams): Promise<GatewayGenerationInfo>;
|
|
373
482
|
/**
|
|
374
483
|
* Creates a model for generating text embeddings.
|
|
375
484
|
*/
|
|
@@ -599,4 +708,4 @@ declare class GatewayResponseError extends GatewayError {
|
|
|
599
708
|
static isInstance(error: unknown): error is GatewayResponseError;
|
|
600
709
|
}
|
|
601
710
|
|
|
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 };
|
|
711
|
+
export { GatewayAuthenticationError, type GatewayCreditsResponse, GatewayError, type GatewayErrorResponse, type GatewayGenerationInfo, type GatewayGenerationInfoParams, 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 };
|