@ai-sdk/gateway 4.0.0-beta.3 → 4.0.0-beta.31

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.
@@ -0,0 +1,147 @@
1
+ import {
2
+ createJsonErrorResponseHandler,
3
+ createJsonResponseHandler,
4
+ getFromApi,
5
+ lazySchema,
6
+ resolve,
7
+ zodSchema,
8
+ } from '@ai-sdk/provider-utils';
9
+ import { z } from 'zod/v4';
10
+ import { asGatewayError } from './errors';
11
+ import type { GatewayConfig } from './gateway-config';
12
+
13
+ export interface GatewayGenerationInfoParams {
14
+ /** The generation ID to look up (format: gen_<ulid>) */
15
+ id: string;
16
+ }
17
+
18
+ export interface GatewayGenerationInfo {
19
+ /** The generation ID */
20
+ id: string;
21
+ /** Total cost in USD */
22
+ totalCost: number;
23
+ /** Upstream inference cost in USD (BYOK only) */
24
+ upstreamInferenceCost: number;
25
+ /** Usage cost in USD (same as totalCost) */
26
+ usage: number;
27
+ /** ISO 8601 timestamp when the generation was created */
28
+ createdAt: string;
29
+ /** Model identifier */
30
+ model: string;
31
+ /** Whether BYOK credentials were used */
32
+ isByok: boolean;
33
+ /** Provider that served this generation */
34
+ providerName: string;
35
+ /** Whether streaming was used */
36
+ streamed: boolean;
37
+ /** Finish reason (e.g. 'stop') */
38
+ finishReason: string;
39
+ /** Time to first token in milliseconds */
40
+ latency: number;
41
+ /** Total generation time in milliseconds */
42
+ generationTime: number;
43
+ /** Number of prompt tokens */
44
+ promptTokens: number;
45
+ /** Number of completion tokens */
46
+ completionTokens: number;
47
+ /** Reasoning tokens used */
48
+ reasoningTokens: number;
49
+ /** Cached tokens used */
50
+ cachedTokens: number;
51
+ /** Cache creation input tokens */
52
+ cacheCreationTokens: number;
53
+ /** Billable web search calls */
54
+ billableWebSearchCalls: number;
55
+ }
56
+
57
+ export class GatewayGenerationInfoFetcher {
58
+ constructor(private readonly config: GatewayConfig) {}
59
+
60
+ async getGenerationInfo(
61
+ params: GatewayGenerationInfoParams,
62
+ ): Promise<GatewayGenerationInfo> {
63
+ try {
64
+ const baseUrl = new URL(this.config.baseURL);
65
+
66
+ const { value } = await getFromApi({
67
+ url: `${baseUrl.origin}/v1/generation?id=${encodeURIComponent(params.id)}`,
68
+ headers: await resolve(this.config.headers()),
69
+ successfulResponseHandler: createJsonResponseHandler(
70
+ gatewayGenerationInfoResponseSchema,
71
+ ),
72
+ failedResponseHandler: createJsonErrorResponseHandler({
73
+ errorSchema: z.any(),
74
+ errorToMessage: data => data,
75
+ }),
76
+ fetch: this.config.fetch,
77
+ });
78
+
79
+ return value;
80
+ } catch (error) {
81
+ throw await asGatewayError(error);
82
+ }
83
+ }
84
+ }
85
+
86
+ const gatewayGenerationInfoResponseSchema = lazySchema(() =>
87
+ zodSchema(
88
+ z
89
+ .object({
90
+ data: z
91
+ .object({
92
+ id: z.string(),
93
+ total_cost: z.number(),
94
+ upstream_inference_cost: z.number(),
95
+ usage: z.number(),
96
+ created_at: z.string(),
97
+ model: z.string(),
98
+ is_byok: z.boolean(),
99
+ provider_name: z.string(),
100
+ streamed: z.boolean(),
101
+ finish_reason: z.string(),
102
+ latency: z.number(),
103
+ generation_time: z.number(),
104
+ native_tokens_prompt: z.number(),
105
+ native_tokens_completion: z.number(),
106
+ native_tokens_reasoning: z.number(),
107
+ native_tokens_cached: z.number(),
108
+ native_tokens_cache_creation: z.number(),
109
+ billable_web_search_calls: z.number(),
110
+ })
111
+ .transform(
112
+ ({
113
+ total_cost,
114
+ upstream_inference_cost,
115
+ created_at,
116
+ is_byok,
117
+ provider_name,
118
+ finish_reason,
119
+ generation_time,
120
+ native_tokens_prompt,
121
+ native_tokens_completion,
122
+ native_tokens_reasoning,
123
+ native_tokens_cached,
124
+ native_tokens_cache_creation,
125
+ billable_web_search_calls,
126
+ ...rest
127
+ }) => ({
128
+ ...rest,
129
+ totalCost: total_cost,
130
+ upstreamInferenceCost: upstream_inference_cost,
131
+ createdAt: created_at,
132
+ isByok: is_byok,
133
+ providerName: provider_name,
134
+ finishReason: finish_reason,
135
+ generationTime: generation_time,
136
+ promptTokens: native_tokens_prompt,
137
+ completionTokens: native_tokens_completion,
138
+ reasoningTokens: native_tokens_reasoning,
139
+ cachedTokens: native_tokens_cached,
140
+ cacheCreationTokens: native_tokens_cache_creation,
141
+ billableWebSearchCalls: billable_web_search_calls,
142
+ }),
143
+ ),
144
+ })
145
+ .transform(({ data }) => data),
146
+ ),
147
+ );
@@ -1,4 +1,9 @@
1
1
  export type GatewayImageModelId =
2
+ | 'bfl/flux-2-flex'
3
+ | 'bfl/flux-2-klein-4b'
4
+ | 'bfl/flux-2-klein-9b'
5
+ | 'bfl/flux-2-max'
6
+ | 'bfl/flux-2-pro'
2
7
  | 'bfl/flux-kontext-max'
3
8
  | 'bfl/flux-kontext-pro'
4
9
  | 'bfl/flux-pro-1.0-fill'
@@ -10,6 +15,7 @@ export type GatewayImageModelId =
10
15
  | 'openai/gpt-image-1'
11
16
  | 'openai/gpt-image-1-mini'
12
17
  | 'openai/gpt-image-1.5'
18
+ | 'prodia/flux-fast-schnell'
13
19
  | 'recraft/recraft-v2'
14
20
  | 'recraft/recraft-v3'
15
21
  | 'recraft/recraft-v4'
@@ -1,7 +1,7 @@
1
1
  import type {
2
- ImageModelV3,
3
- ImageModelV3File,
4
- ImageModelV3ProviderMetadata,
2
+ ImageModelV4,
3
+ ImageModelV4File,
4
+ ImageModelV4ProviderMetadata,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
7
  combineHeaders,
@@ -17,8 +17,8 @@ import type { GatewayConfig } from './gateway-config';
17
17
  import { asGatewayError } from './errors';
18
18
  import { parseAuthMethod } from './errors/parse-auth-method';
19
19
 
20
- export class GatewayImageModel implements ImageModelV3 {
21
- readonly specificationVersion = 'v3' as const;
20
+ export class GatewayImageModel implements ImageModelV4 {
21
+ readonly specificationVersion = 'v4' as const;
22
22
  // Set a very large number to prevent client-side splitting of requests
23
23
  readonly maxImagesPerCall = Number.MAX_SAFE_INTEGER;
24
24
 
@@ -45,8 +45,8 @@ export class GatewayImageModel implements ImageModelV3 {
45
45
  providerOptions,
46
46
  headers,
47
47
  abortSignal,
48
- }: Parameters<ImageModelV3['doGenerate']>[0]): Promise<
49
- Awaited<ReturnType<ImageModelV3['doGenerate']>>
48
+ }: Parameters<ImageModelV4['doGenerate']>[0]): Promise<
49
+ Awaited<ReturnType<ImageModelV4['doGenerate']>>
50
50
  > {
51
51
  const resolvedHeaders = await resolve(this.config.headers());
52
52
  try {
@@ -89,7 +89,7 @@ export class GatewayImageModel implements ImageModelV3 {
89
89
  images: responseBody.images, // Always base64 strings from server
90
90
  warnings: responseBody.warnings ?? [],
91
91
  providerMetadata:
92
- responseBody.providerMetadata as ImageModelV3ProviderMetadata,
92
+ responseBody.providerMetadata as ImageModelV4ProviderMetadata,
93
93
  response: {
94
94
  timestamp: new Date(),
95
95
  modelId: this.modelId,
@@ -114,13 +114,13 @@ export class GatewayImageModel implements ImageModelV3 {
114
114
 
115
115
  private getModelConfigHeaders() {
116
116
  return {
117
- 'ai-image-model-specification-version': '3',
117
+ 'ai-image-model-specification-version': '4',
118
118
  'ai-model-id': this.modelId,
119
119
  };
120
120
  }
121
121
  }
122
122
 
123
- function maybeEncodeImageFile(file: ImageModelV3File) {
123
+ function maybeEncodeImageFile(file: ImageModelV4File) {
124
124
  if (file.type === 'file' && file.data instanceof Uint8Array) {
125
125
  return {
126
126
  ...file,
@@ -51,8 +51,6 @@ export type GatewayModelId =
51
51
  | 'google/gemini-2.5-flash'
52
52
  | 'google/gemini-2.5-flash-image'
53
53
  | 'google/gemini-2.5-flash-lite'
54
- | 'google/gemini-2.5-flash-lite-preview-09-2025'
55
- | 'google/gemini-2.5-flash-preview-09-2025'
56
54
  | 'google/gemini-2.5-pro'
57
55
  | 'google/gemini-3-flash'
58
56
  | 'google/gemini-3-pro-image'
@@ -63,8 +61,10 @@ export type GatewayModelId =
63
61
  | 'inception/mercury-2'
64
62
  | 'inception/mercury-coder-small'
65
63
  | 'kwaipilot/kat-coder-pro-v1'
64
+ | 'kwaipilot/kat-coder-pro-v2'
66
65
  | 'meituan/longcat-flash-chat'
67
66
  | 'meituan/longcat-flash-thinking'
67
+ | 'meituan/longcat-flash-thinking-2601'
68
68
  | 'meta/llama-3.1-70b'
69
69
  | 'meta/llama-3.1-8b'
70
70
  | 'meta/llama-3.2-11b'
@@ -78,6 +78,9 @@ export type GatewayModelId =
78
78
  | 'minimax/minimax-m2.1'
79
79
  | 'minimax/minimax-m2.1-lightning'
80
80
  | 'minimax/minimax-m2.5'
81
+ | 'minimax/minimax-m2.5-highspeed'
82
+ | 'minimax/minimax-m2.7'
83
+ | 'minimax/minimax-m2.7-highspeed'
81
84
  | 'mistral/codestral'
82
85
  | 'mistral/devstral-2'
83
86
  | 'mistral/devstral-small'
@@ -103,9 +106,9 @@ export type GatewayModelId =
103
106
  | 'morph/morph-v3-fast'
104
107
  | 'morph/morph-v3-large'
105
108
  | 'nvidia/nemotron-3-nano-30b-a3b'
109
+ | 'nvidia/nemotron-3-super-120b-a12b'
106
110
  | 'nvidia/nemotron-nano-12b-v2-vl'
107
111
  | 'nvidia/nemotron-nano-9b-v2'
108
- | 'openai/codex-mini'
109
112
  | 'openai/gpt-3.5-turbo'
110
113
  | 'openai/gpt-3.5-turbo-instruct'
111
114
  | 'openai/gpt-4-turbo'
@@ -133,6 +136,8 @@ export type GatewayModelId =
133
136
  | 'openai/gpt-5.3-chat'
134
137
  | 'openai/gpt-5.3-codex'
135
138
  | 'openai/gpt-5.4'
139
+ | 'openai/gpt-5.4-mini'
140
+ | 'openai/gpt-5.4-nano'
136
141
  | 'openai/gpt-5.4-pro'
137
142
  | 'openai/gpt-oss-120b'
138
143
  | 'openai/gpt-oss-20b'
@@ -145,11 +150,8 @@ export type GatewayModelId =
145
150
  | 'openai/o4-mini'
146
151
  | 'perplexity/sonar'
147
152
  | 'perplexity/sonar-pro'
148
- | 'perplexity/sonar-reasoning'
149
153
  | 'perplexity/sonar-reasoning-pro'
150
154
  | 'prime-intellect/intellect-3'
151
- | 'vercel/v0-1.0-md'
152
- | 'vercel/v0-1.5-md'
153
155
  | 'xai/grok-2-vision'
154
156
  | 'xai/grok-3'
155
157
  | 'xai/grok-3-fast'
@@ -160,8 +162,15 @@ export type GatewayModelId =
160
162
  | 'xai/grok-4-fast-reasoning'
161
163
  | 'xai/grok-4.1-fast-non-reasoning'
162
164
  | 'xai/grok-4.1-fast-reasoning'
165
+ | 'xai/grok-4.20-multi-agent'
166
+ | 'xai/grok-4.20-multi-agent-beta'
167
+ | 'xai/grok-4.20-non-reasoning'
168
+ | 'xai/grok-4.20-non-reasoning-beta'
169
+ | 'xai/grok-4.20-reasoning'
170
+ | 'xai/grok-4.20-reasoning-beta'
163
171
  | 'xai/grok-code-fast-1'
164
172
  | 'xiaomi/mimo-v2-flash'
173
+ | 'xiaomi/mimo-v2-pro'
165
174
  | 'zai/glm-4.5'
166
175
  | 'zai/glm-4.5-air'
167
176
  | 'zai/glm-4.5v'
@@ -169,6 +178,9 @@ export type GatewayModelId =
169
178
  | 'zai/glm-4.6v'
170
179
  | 'zai/glm-4.6v-flash'
171
180
  | 'zai/glm-4.7'
181
+ | 'zai/glm-4.7-flash'
172
182
  | 'zai/glm-4.7-flashx'
173
183
  | 'zai/glm-5'
184
+ | 'zai/glm-5-turbo'
185
+ | 'zai/glm-5v-turbo'
174
186
  | (string & {});
@@ -1,11 +1,11 @@
1
1
  import type {
2
- LanguageModelV3,
3
- LanguageModelV3CallOptions,
4
- SharedV3Warning,
5
- LanguageModelV3FilePart,
6
- LanguageModelV3StreamPart,
7
- LanguageModelV3GenerateResult,
8
- LanguageModelV3StreamResult,
2
+ LanguageModelV4,
3
+ LanguageModelV4CallOptions,
4
+ SharedV4Warning,
5
+ LanguageModelV4FilePart,
6
+ LanguageModelV4StreamPart,
7
+ LanguageModelV4GenerateResult,
8
+ LanguageModelV4StreamResult,
9
9
  } from '@ai-sdk/provider';
10
10
  import {
11
11
  combineHeaders,
@@ -28,8 +28,8 @@ type GatewayChatConfig = GatewayConfig & {
28
28
  o11yHeaders: Resolvable<Record<string, string>>;
29
29
  };
30
30
 
31
- export class GatewayLanguageModel implements LanguageModelV3 {
32
- readonly specificationVersion = 'v3';
31
+ export class GatewayLanguageModel implements LanguageModelV4 {
32
+ readonly specificationVersion = 'v4';
33
33
  readonly supportedUrls = { '*/*': [/.*/] };
34
34
 
35
35
  constructor(
@@ -41,7 +41,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
41
41
  return this.config.provider;
42
42
  }
43
43
 
44
- private async getArgs(options: LanguageModelV3CallOptions) {
44
+ private async getArgs(options: LanguageModelV4CallOptions) {
45
45
  const { abortSignal: _abortSignal, ...optionsWithoutSignal } = options;
46
46
 
47
47
  return {
@@ -51,8 +51,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
51
51
  }
52
52
 
53
53
  async doGenerate(
54
- options: LanguageModelV3CallOptions,
55
- ): Promise<LanguageModelV3GenerateResult> {
54
+ options: LanguageModelV4CallOptions,
55
+ ): Promise<LanguageModelV4GenerateResult> {
56
56
  const { args, warnings } = await this.getArgs(options);
57
57
  const { abortSignal } = options;
58
58
 
@@ -93,8 +93,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
93
93
  }
94
94
 
95
95
  async doStream(
96
- options: LanguageModelV3CallOptions,
97
- ): Promise<LanguageModelV3StreamResult> {
96
+ options: LanguageModelV4CallOptions,
97
+ ): Promise<LanguageModelV4StreamResult> {
98
98
  const { args, warnings } = await this.getArgs(options);
99
99
  const { abortSignal } = options;
100
100
 
@@ -122,8 +122,8 @@ export class GatewayLanguageModel implements LanguageModelV3 {
122
122
  return {
123
123
  stream: response.pipeThrough(
124
124
  new TransformStream<
125
- ParseResult<LanguageModelV3StreamPart>,
126
- LanguageModelV3StreamPart
125
+ ParseResult<LanguageModelV4StreamPart>,
126
+ LanguageModelV4StreamPart
127
127
  >({
128
128
  start(controller) {
129
129
  if (warnings.length > 0) {
@@ -177,11 +177,11 @@ export class GatewayLanguageModel implements LanguageModelV3 {
177
177
  * @param options - The options to encode.
178
178
  * @returns The options with the file parts encoded.
179
179
  */
180
- private maybeEncodeFileParts(options: LanguageModelV3CallOptions) {
180
+ private maybeEncodeFileParts(options: LanguageModelV4CallOptions) {
181
181
  for (const message of options.prompt) {
182
182
  for (const part of message.content) {
183
183
  if (this.isFilePart(part)) {
184
- const filePart = part as LanguageModelV3FilePart;
184
+ const filePart = part as LanguageModelV4FilePart;
185
185
  // If the file part is a URL it will get cleanly converted to a string.
186
186
  // If it's a binary file attachment we convert it to a data url.
187
187
  // In either case, server-side we should only ever see URLs as strings.
@@ -204,7 +204,7 @@ export class GatewayLanguageModel implements LanguageModelV3 {
204
204
 
205
205
  private getModelConfigHeaders(modelId: string, streaming: boolean) {
206
206
  return {
207
- 'ai-language-model-specification-version': '3',
207
+ 'ai-language-model-specification-version': '4',
208
208
  'ai-language-model-id': modelId,
209
209
  'ai-language-model-streaming': String(streaming),
210
210
  };
@@ -1,4 +1,4 @@
1
- import type { LanguageModelV3 } from '@ai-sdk/provider';
1
+ import type { LanguageModelV4 } from '@ai-sdk/provider';
2
2
 
3
3
  export interface GatewayLanguageModelEntry {
4
4
  /**
@@ -53,6 +53,6 @@ export interface GatewayLanguageModelEntry {
53
53
  }
54
54
 
55
55
  export type GatewayLanguageModelSpecification = Pick<
56
- LanguageModelV3,
56
+ LanguageModelV4,
57
57
  'specificationVersion' | 'provider' | 'modelId'
58
58
  >;
@@ -2,7 +2,7 @@ import { InferSchema, lazySchema, zodSchema } from '@ai-sdk/provider-utils';
2
2
  import { z } from 'zod/v4';
3
3
 
4
4
  // https://vercel.com/docs/ai-gateway/provider-options
5
- const gatewayLanguageModelOptions = lazySchema(() =>
5
+ const gatewayProviderOptions = lazySchema(() =>
6
6
  zodSchema(
7
7
  z.object({
8
8
  /**
@@ -59,6 +59,12 @@ const gatewayLanguageModelOptions = lazySchema(() =>
59
59
  * used.
60
60
  */
61
61
  zeroDataRetention: z.boolean().optional(),
62
+ /**
63
+ * Whether to filter by only providers that do not train on prompt data.
64
+ * When enabled, only providers that have agreements with Vercel AI Gateway
65
+ * to not use prompts for model training will be used.
66
+ */
67
+ disallowPromptTraining: z.boolean().optional(),
62
68
  /**
63
69
  * Per-provider timeouts for BYOK credentials in milliseconds.
64
70
  * Controls how long to wait for a provider to start responding
@@ -75,6 +81,4 @@ const gatewayLanguageModelOptions = lazySchema(() =>
75
81
  ),
76
82
  );
77
83
 
78
- export type GatewayLanguageModelOptions = InferSchema<
79
- typeof gatewayLanguageModelOptions
80
- >;
84
+ export type GatewayProviderOptions = InferSchema<typeof gatewayProviderOptions>;
@@ -13,6 +13,16 @@ import {
13
13
  type GatewayFetchMetadataResponse,
14
14
  type GatewayCreditsResponse,
15
15
  } from './gateway-fetch-metadata';
16
+ import {
17
+ GatewaySpendReport,
18
+ type GatewaySpendReportParams,
19
+ type GatewaySpendReportResponse,
20
+ } from './gateway-spend-report';
21
+ import {
22
+ GatewayGenerationInfoFetcher,
23
+ type GatewayGenerationInfoParams,
24
+ type GatewayGenerationInfo,
25
+ } from './gateway-generation-info';
16
26
  import { GatewayLanguageModel } from './gateway-language-model';
17
27
  import { GatewayEmbeddingModel } from './gateway-embedding-model';
18
28
  import { GatewayImageModel } from './gateway-image-model';
@@ -24,27 +34,27 @@ import { gatewayTools } from './gateway-tools';
24
34
  import { getVercelOidcToken, getVercelRequestId } from './vercel-environment';
25
35
  import type { GatewayModelId } from './gateway-language-model-settings';
26
36
  import type {
27
- LanguageModelV3,
28
- EmbeddingModelV3,
29
- ImageModelV3,
30
- Experimental_VideoModelV3,
31
- ProviderV3,
37
+ LanguageModelV4,
38
+ EmbeddingModelV4,
39
+ ImageModelV4,
40
+ Experimental_VideoModelV4,
41
+ ProviderV4,
32
42
  } from '@ai-sdk/provider';
33
43
  import { withUserAgentSuffix } from '@ai-sdk/provider-utils';
34
44
  import { VERSION } from './version';
35
45
 
36
- export interface GatewayProvider extends ProviderV3 {
37
- (modelId: GatewayModelId): LanguageModelV3;
46
+ export interface GatewayProvider extends ProviderV4 {
47
+ (modelId: GatewayModelId): LanguageModelV4;
38
48
 
39
49
  /**
40
50
  * Creates a model for text generation.
41
51
  */
42
- chat(modelId: GatewayModelId): LanguageModelV3;
52
+ chat(modelId: GatewayModelId): LanguageModelV4;
43
53
 
44
54
  /**
45
55
  * Creates a model for text generation.
46
56
  */
47
- languageModel(modelId: GatewayModelId): LanguageModelV3;
57
+ languageModel(modelId: GatewayModelId): LanguageModelV4;
48
58
 
49
59
  /**
50
60
  * Returns available providers and models for use with the remote provider.
@@ -56,40 +66,56 @@ export interface GatewayProvider extends ProviderV3 {
56
66
  */
57
67
  getCredits(): Promise<GatewayCreditsResponse>;
58
68
 
69
+ /**
70
+ * Returns a spend report with cost, token, and request count data,
71
+ * aggregated by the specified dimension.
72
+ */
73
+ getSpendReport(
74
+ params: GatewaySpendReportParams,
75
+ ): Promise<GatewaySpendReportResponse>;
76
+
77
+ /**
78
+ * Returns detailed information about a specific generation by its ID,
79
+ * including cost, token usage, latency, and provider details.
80
+ */
81
+ getGenerationInfo(
82
+ params: GatewayGenerationInfoParams,
83
+ ): Promise<GatewayGenerationInfo>;
84
+
59
85
  /**
60
86
  * Creates a model for generating text embeddings.
61
87
  */
62
- embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
88
+ embedding(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
63
89
 
64
90
  /**
65
91
  * Creates a model for generating text embeddings.
66
92
  */
67
- embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
93
+ embeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
68
94
 
69
95
  /**
70
96
  * @deprecated Use `embeddingModel` instead.
71
97
  */
72
- textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV3;
98
+ textEmbeddingModel(modelId: GatewayEmbeddingModelId): EmbeddingModelV4;
73
99
 
74
100
  /**
75
101
  * Creates a model for generating images.
76
102
  */
77
- image(modelId: GatewayImageModelId): ImageModelV3;
103
+ image(modelId: GatewayImageModelId): ImageModelV4;
78
104
 
79
105
  /**
80
106
  * Creates a model for generating images.
81
107
  */
82
- imageModel(modelId: GatewayImageModelId): ImageModelV3;
108
+ imageModel(modelId: GatewayImageModelId): ImageModelV4;
83
109
 
84
110
  /**
85
111
  * Creates a model for generating videos.
86
112
  */
87
- video(modelId: GatewayVideoModelId): Experimental_VideoModelV3;
113
+ video(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
88
114
 
89
115
  /**
90
116
  * Creates a model for generating videos.
91
117
  */
92
- videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV3;
118
+ videoModel(modelId: GatewayVideoModelId): Experimental_VideoModelV4;
93
119
 
94
120
  /**
95
121
  * Gateway-specific tools executed server-side.
@@ -253,6 +279,36 @@ export function createGatewayProvider(
253
279
  });
254
280
  };
255
281
 
282
+ const getSpendReport = async (params: GatewaySpendReportParams) => {
283
+ return new GatewaySpendReport({
284
+ baseURL,
285
+ headers: getHeaders,
286
+ fetch: options.fetch,
287
+ })
288
+ .getSpendReport(params)
289
+ .catch(async (error: unknown) => {
290
+ throw await asGatewayError(
291
+ error,
292
+ await parseAuthMethod(await getHeaders()),
293
+ );
294
+ });
295
+ };
296
+
297
+ const getGenerationInfo = async (params: GatewayGenerationInfoParams) => {
298
+ return new GatewayGenerationInfoFetcher({
299
+ baseURL,
300
+ headers: getHeaders,
301
+ fetch: options.fetch,
302
+ })
303
+ .getGenerationInfo(params)
304
+ .catch(async (error: unknown) => {
305
+ throw await asGatewayError(
306
+ error,
307
+ await parseAuthMethod(await getHeaders()),
308
+ );
309
+ });
310
+ };
311
+
256
312
  const provider = function (modelId: GatewayModelId) {
257
313
  if (new.target) {
258
314
  throw new Error(
@@ -263,9 +319,11 @@ export function createGatewayProvider(
263
319
  return createLanguageModel(modelId);
264
320
  };
265
321
 
266
- provider.specificationVersion = 'v3' as const;
322
+ provider.specificationVersion = 'v4' as const;
267
323
  provider.getAvailableModels = getAvailableModels;
268
324
  provider.getCredits = getCredits;
325
+ provider.getSpendReport = getSpendReport;
326
+ provider.getGenerationInfo = getGenerationInfo;
269
327
  provider.imageModel = (modelId: GatewayImageModelId) => {
270
328
  return new GatewayImageModel(modelId, {
271
329
  provider: 'gateway',