@ai-sdk/gateway 4.0.139 → 4.0.142

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.
@@ -1256,7 +1256,7 @@ console.log('Tool calls:', JSON.stringify(result.toolCalls, null, 2));
1256
1256
  console.log('Tool results:', JSON.stringify(result.toolResults, null, 2));
1257
1257
  ```
1258
1258
 
1259
- Configure the search with effort, source selection, and localization defaults. These defaults override values the model includes in a tool call:
1259
+ Configure the search with effort, source selection, and localization defaults. These defaults override values the model includes in a tool call. `variableCost`, `maxVariableCostUsd`, and `extraBody` are developer-only: the model can't see or set them.
1260
1260
 
1261
1261
  ```ts
1262
1262
  import { gateway, generateText } from 'ai';
@@ -1311,6 +1311,43 @@ The Tako Search tool supports these optional configuration options:
1311
1311
  - **timezone** _string_ - IANA timezone, such as `'America/New_York'`.
1312
1312
  - **outputSettings** _object_ - Card rendering controls. `forceRefresh` is available only with `'instant'` effort.
1313
1313
  - **includeRelated** _number_ - Number of related search suggestions to include (1-20).
1314
+ - **variableCost** _boolean_ - Serve data from sources priced per unit, such as web traffic and SEO. Each such card adds a charge, and the total per call is capped by `maxVariableCostUsd`. Defaults to `true`. Set it to `false` to opt out; those cards then come back as placeholders. Only searches that include the data index (`sources.data` set, or `sources` omitted) return these cards.
1315
+ - **maxVariableCostUsd** _number | null_ - The most one search call can be charged in variable cost, in USD.
1316
+ - Defaults to `0.25`, and `null` removes the cap.
1317
+ - Tako checks each card's maximum charge (`content.export_pricing.variable_cost_max_usd`) in rank order. A card that doesn't fit comes back as a placeholder with `reason: 'over_cap'`, even if its actual charge would have fit.
1318
+ - `0` returns only the cards whose charge the base price already covers.
1319
+ - It can't be combined with `variableCost: false`.
1320
+ - **extraBody** _Record<string, unknown>_ - Extra Tako request fields, in snake_case, deep-merged into the request body last. Objects merge, and scalars and arrays replace. Use it for Tako parameters this tool doesn't model yet. Its limits:
1321
+ - It can't set a field the tool already models, including the `sources.data` variable-cost fields. The gateway answers `invalid_input`.
1322
+ - Tako rejects unknown keys, so a typo comes back as an `api_error`.
1323
+ - It's limited to 16,384 serialized characters.
1324
+
1325
+ When Tako withholds a card's data, it returns a placeholder card instead. A placeholder keeps its title and a description but carries no data. `placeholder.withheld_source` names the source, and `placeholder.reason` is `'not_served'` (variable cost is off, or the account isn't served that source) or `'over_cap'`. `usage.variable_cost.cost_usd` reports the variable-cost charge for the call:
1326
+
1327
+ ```ts
1328
+ import { gateway, generateText } from 'ai';
1329
+
1330
+ const result = await generateText({
1331
+ model: 'openai/gpt-5.4-nano',
1332
+ prompt: 'How much monthly web traffic does vercel.com get?',
1333
+ tools: {
1334
+ tako_search: gateway.tools.takoSearch({
1335
+ sources: { data: {}, web: {} },
1336
+ maxVariableCostUsd: 0.1,
1337
+ }),
1338
+ },
1339
+ });
1340
+
1341
+ for (const toolResult of result.toolResults) {
1342
+ if (toolResult.dynamic || 'error' in toolResult.output) continue;
1343
+ for (const card of toolResult.output.cards ?? []) {
1344
+ if (card.placeholder) {
1345
+ const reason = card.placeholder.reason ?? 'not_served';
1346
+ console.log(`Withheld (${reason}):`, card.title);
1347
+ }
1348
+ }
1349
+ }
1350
+ ```
1314
1351
 
1315
1352
  For precise entity matching, quote a phrase in the query and optionally append a label: `"Tesla":PRODUCT price`. Tako treats the quoted phrase as one entity before searching.
1316
1353
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-sdk/gateway",
3
3
  "private": false,
4
- "version": "4.0.139",
4
+ "version": "4.0.142",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
7
7
  "sideEffects": false,
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@ai-sdk/provider": "4.0.37",
34
- "@ai-sdk/provider-utils": "5.0.76",
34
+ "@ai-sdk/provider-utils": "5.0.79",
35
35
  "@vercel/oidc": "3.2.0"
36
36
  },
37
37
  "devDependencies": {
@@ -42,7 +42,7 @@
42
42
  "tsdown": "^0.23.0",
43
43
  "tsx": "4.23.12",
44
44
  "typescript": "6.0.3",
45
- "zod": "3.25.76"
45
+ "zod": "4.6.7"
46
46
  },
47
47
  "peerDependencies": {
48
48
  "zod": "^3.25.76 || ^4.1.8"
@@ -153,11 +153,11 @@ const gatewayErrorResponseSchema = lazySchema(() =>
153
153
  z.object({
154
154
  error: z.object({
155
155
  message: z.string(),
156
- type: z.string().nullish(),
157
- param: z.unknown().nullish(),
158
- code: z.union([z.string(), z.number()]).nullish(),
156
+ type: z.nullish(z.string()),
157
+ param: z.nullish(z.unknown()),
158
+ code: z.nullish(z.union([z.string(), z.number()])),
159
159
  }),
160
- generationId: z.string().nullish(),
160
+ generationId: z.nullish(z.string()),
161
161
  }),
162
162
  ),
163
163
  );
@@ -489,30 +489,31 @@ async function* convertGatewayBatchResultLines(
489
489
 
490
490
  const gatewayBatchItemResultLineSchema = lazySchema(() =>
491
491
  zodSchema(
492
- z
493
- .object({
492
+ z.catchall(
493
+ z.object({
494
494
  type: z.literal('text'),
495
495
  id: z.string(),
496
496
  status: z.enum(['cancelled', 'expired', 'failed', 'succeeded']),
497
- })
498
- .catchall(z.unknown()),
497
+ }),
498
+ z.unknown(),
499
+ ),
499
500
  ),
500
501
  );
501
502
 
502
503
  const gatewayBatchErrorSchema = () =>
503
504
  z.object({
504
505
  message: z.string(),
505
- type: z.string().nullish(),
506
- code: z.string().nullish(),
507
- statusCode: z.number().nullish(),
506
+ type: z.nullish(z.string()),
507
+ code: z.nullish(z.string()),
508
+ statusCode: z.nullish(z.number()),
508
509
  });
509
510
 
510
511
  const gatewayBatchRequestCountsSchema = () =>
511
512
  z.object({
512
- total: z.number().nullish(),
513
- pending: z.number().nullish(),
514
- completed: z.number().nullish(),
515
- failed: z.number().nullish(),
513
+ total: z.nullish(z.number()),
514
+ pending: z.nullish(z.number()),
515
+ completed: z.nullish(z.number()),
516
+ failed: z.nullish(z.number()),
516
517
  });
517
518
 
518
519
  const gatewayBatchProviderMetadataSchema = () =>
@@ -521,28 +522,29 @@ const gatewayBatchProviderMetadataSchema = () =>
521
522
  const gatewayBatchStatusFieldsSchema = () =>
522
523
  z.object({
523
524
  status: z.enum(['completed', 'failed', 'pending']),
524
- rawStatus: z.string().nullish(),
525
- requestCounts: gatewayBatchRequestCountsSchema().nullish(),
526
- error: gatewayBatchErrorSchema().nullish(),
527
- createdAt: z.string().nullish(),
528
- expiresAt: z.string().nullish(),
529
- providerMetadata: gatewayBatchProviderMetadataSchema().nullish(),
525
+ rawStatus: z.nullish(z.string()),
526
+ requestCounts: z.nullish(gatewayBatchRequestCountsSchema()),
527
+ error: z.nullish(gatewayBatchErrorSchema()),
528
+ createdAt: z.nullish(z.string()),
529
+ expiresAt: z.nullish(z.string()),
530
+ providerMetadata: z.nullish(gatewayBatchProviderMetadataSchema()),
530
531
  });
531
532
 
532
533
  const gatewayBatchStartResponseSchema = lazySchema(() =>
533
534
  zodSchema(
534
- gatewayBatchStatusFieldsSchema().extend({
535
+ z.extend(gatewayBatchStatusFieldsSchema(), {
535
536
  batchId: z.string(),
536
- warnings: z
537
- .array(
538
- z
539
- .object({
540
- requestId: z.string().nullish(),
537
+ warnings: z.nullish(
538
+ z.array(
539
+ z.catchall(
540
+ z.object({
541
+ requestId: z.nullish(z.string()),
541
542
  warning: z.unknown(),
542
- })
543
- .catchall(z.unknown()),
544
- )
545
- .nullish(),
543
+ }),
544
+ z.unknown(),
545
+ ),
546
+ ),
547
+ ),
546
548
  }),
547
549
  ),
548
550
  );
@@ -7,6 +7,7 @@ export type GatewayDecisionModelId =
7
7
  | 'liquid/d1-ultra'
8
8
  | 'microsoft/microsoft-decision-1'
9
9
  | 'openai/gpt-6-luna-decisions'
10
+ | 'parallel/parallel-decisions-fast'
10
11
  | 'perplexity/pplx-decider-flash-v1.2'
11
12
  | 'perplexity/pplx-decider-v1.2'
12
13
  | 'scaledown/scaledown-classify-1'
@@ -140,12 +140,12 @@ const gatewayDecisionAnswerSchema = () =>
140
140
  z.object({
141
141
  type: z.literal('choice'),
142
142
  choice: z.string(),
143
- probabilities: z.record(z.string(), z.number()).optional(),
143
+ probabilities: z.optional(z.record(z.string(), z.number())),
144
144
  }),
145
145
  z.object({
146
146
  type: z.literal('score'),
147
147
  score: z.number(),
148
- probabilities: z.record(z.string(), z.number()).optional(),
148
+ probabilities: z.optional(z.record(z.string(), z.number())),
149
149
  }),
150
150
  z.object({
151
151
  type: z.literal('boolean'),
@@ -161,12 +161,12 @@ const gatewayDecisionWarningSchema = () =>
161
161
  z.object({
162
162
  type: z.literal('unsupported'),
163
163
  feature: z.string(),
164
- details: z.string().optional(),
164
+ details: z.optional(z.string()),
165
165
  }),
166
166
  z.object({
167
167
  type: z.literal('compatibility'),
168
168
  feature: z.string(),
169
- details: z.string().optional(),
169
+ details: z.optional(z.string()),
170
170
  }),
171
171
  z.object({
172
172
  type: z.literal('deprecated'),
@@ -183,23 +183,23 @@ const gatewayDecisionResponseSchema = lazySchema(() =>
183
183
  zodSchema(
184
184
  z.object({
185
185
  answers: z.record(z.string(), gatewayDecisionAnswerSchema()),
186
- model: z.string().optional(),
187
- rounding: z
188
- .object({
189
- probabilityDecimals: z.number().optional(),
190
- scoreDecimals: z.number().optional(),
191
- })
192
- .optional(),
193
- usage: z
194
- .object({
195
- inputTokens: z.number().optional(),
196
- outputTokens: z.number().optional(),
197
- })
198
- .optional(),
199
- warnings: z.array(gatewayDecisionWarningSchema()).optional(),
200
- providerMetadata: z
201
- .record(z.string(), z.record(z.string(), z.unknown()))
202
- .optional(),
186
+ model: z.optional(z.string()),
187
+ rounding: z.optional(
188
+ z.object({
189
+ probabilityDecimals: z.optional(z.number()),
190
+ scoreDecimals: z.optional(z.number()),
191
+ }),
192
+ ),
193
+ usage: z.optional(
194
+ z.object({
195
+ inputTokens: z.optional(z.number()),
196
+ outputTokens: z.optional(z.number()),
197
+ }),
198
+ ),
199
+ warnings: z.optional(z.array(gatewayDecisionWarningSchema())),
200
+ providerMetadata: z.optional(
201
+ z.record(z.string(), z.record(z.string(), z.unknown())),
202
+ ),
203
203
  }),
204
204
  ),
205
205
  );
@@ -128,12 +128,12 @@ const gatewayEmbeddingWarningSchema = () =>
128
128
  z.object({
129
129
  type: z.literal('unsupported'),
130
130
  feature: z.string(),
131
- details: z.string().optional(),
131
+ details: z.optional(z.string()),
132
132
  }),
133
133
  z.object({
134
134
  type: z.literal('compatibility'),
135
135
  feature: z.string(),
136
- details: z.string().optional(),
136
+ details: z.optional(z.string()),
137
137
  }),
138
138
  z.object({
139
139
  type: z.literal('deprecated'),
@@ -150,11 +150,11 @@ const gatewayEmbeddingResponseSchema = lazySchema(() =>
150
150
  zodSchema(
151
151
  z.object({
152
152
  embeddings: z.array(z.array(z.number())),
153
- usage: z.object({ tokens: z.number() }).nullish(),
154
- warnings: z.array(gatewayEmbeddingWarningSchema()).optional(),
155
- providerMetadata: z
156
- .record(z.string(), z.record(z.string(), z.unknown()))
157
- .optional(),
153
+ usage: z.nullish(z.object({ tokens: z.number() })),
154
+ warnings: z.optional(z.array(gatewayEmbeddingWarningSchema())),
155
+ providerMetadata: z.optional(
156
+ z.record(z.string(), z.record(z.string(), z.unknown())),
157
+ ),
158
158
  }),
159
159
  ),
160
160
  );
@@ -112,61 +112,65 @@ function getTeamIdOrSlug(
112
112
  const gatewayAvailableModelsResponseSchema = lazySchema(() =>
113
113
  zodSchema(
114
114
  z.object({
115
- models: z
116
- .array(
115
+ models: z.pipe(
116
+ z.array(
117
117
  z.object({
118
118
  id: z.string(),
119
119
  name: z.string(),
120
- description: z.string().nullish(),
121
- pricing: z
122
- .object({
123
- input: z.string(),
124
- output: z.string(),
125
- input_cache_read: z.string().nullish(),
126
- input_cache_write: z.string().nullish(),
127
- })
128
- .transform(
129
- ({ input, output, input_cache_read, input_cache_write }) => ({
130
- input,
131
- output,
132
- ...(input_cache_read
133
- ? { cachedInputTokens: input_cache_read }
134
- : {}),
135
- ...(input_cache_write
136
- ? { cacheCreationInputTokens: input_cache_write }
137
- : {}),
120
+ description: z.nullish(z.string()),
121
+ pricing: z.nullish(
122
+ z.pipe(
123
+ z.object({
124
+ input: z.string(),
125
+ output: z.string(),
126
+ input_cache_read: z.nullish(z.string()),
127
+ input_cache_write: z.nullish(z.string()),
138
128
  }),
139
- )
140
- .nullish(),
129
+ z.transform(
130
+ ({ input, output, input_cache_read, input_cache_write }) => ({
131
+ input,
132
+ output,
133
+ ...(input_cache_read
134
+ ? { cachedInputTokens: input_cache_read }
135
+ : {}),
136
+ ...(input_cache_write
137
+ ? { cacheCreationInputTokens: input_cache_write }
138
+ : {}),
139
+ }),
140
+ ),
141
+ ),
142
+ ),
141
143
  specification: z.object({
142
144
  specificationVersion: z.literal('v4'),
143
145
  provider: z.string(),
144
146
  modelId: z.string(),
145
147
  }),
146
- modelType: z.string().nullish(),
148
+ modelType: z.nullish(z.string()),
147
149
  }),
148
- )
149
- .transform(models =>
150
+ ),
151
+ z.transform(models =>
150
152
  models.filter(
151
153
  (m): m is typeof m & { modelType?: KnownModelType | null } =>
152
154
  m.modelType == null ||
153
155
  KNOWN_MODEL_TYPES.includes(m.modelType as KnownModelType),
154
156
  ),
155
157
  ),
158
+ ),
156
159
  }),
157
160
  ),
158
161
  );
159
162
 
160
163
  const gatewayCreditsResponseSchema = lazySchema(() =>
161
164
  zodSchema(
162
- z
163
- .object({
165
+ z.pipe(
166
+ z.object({
164
167
  balance: z.string(),
165
168
  total_used: z.string(),
166
- })
167
- .transform(({ balance, total_used }) => ({
169
+ }),
170
+ z.transform(({ balance, total_used }) => ({
168
171
  balance,
169
172
  totalUsed: total_used,
170
173
  })),
174
+ ),
171
175
  ),
172
176
  );
@@ -95,15 +95,15 @@ export class GatewayGenerationInfoFetcher {
95
95
 
96
96
  const gatewayGenerationInfoResponseSchema = lazySchema(() =>
97
97
  zodSchema(
98
- z
99
- .object({
100
- data: z
101
- .object({
98
+ z.pipe(
99
+ z.object({
100
+ data: z.pipe(
101
+ z.object({
102
102
  id: z.string(),
103
103
  total_cost: z.number(),
104
- market_cost: z.number().nullish(),
105
- surcharge_cost: z.number().nullish(),
106
- gateway_cost: z.number().nullish(),
104
+ market_cost: z.nullish(z.number()),
105
+ surcharge_cost: z.nullish(z.number()),
106
+ gateway_cost: z.nullish(z.number()),
107
107
  upstream_inference_cost: z.number(),
108
108
  usage: z.number(),
109
109
  created_at: z.string(),
@@ -120,8 +120,8 @@ const gatewayGenerationInfoResponseSchema = lazySchema(() =>
120
120
  native_tokens_cached: z.number(),
121
121
  native_tokens_cache_creation: z.number(),
122
122
  billable_web_search_calls: z.number(),
123
- })
124
- .transform(
123
+ }),
124
+ z.transform(
125
125
  ({
126
126
  total_cost,
127
127
  market_cost,
@@ -162,7 +162,9 @@ const gatewayGenerationInfoResponseSchema = lazySchema(() =>
162
162
  billableWebSearchCalls: billable_web_search_calls,
163
163
  }),
164
164
  ),
165
- })
166
- .transform(({ data }) => data),
165
+ ),
166
+ }),
167
+ z.transform(({ data }) => data),
168
+ ),
167
169
  ),
168
170
  );
@@ -199,23 +199,24 @@ function toImageModelImages(
199
199
  }
200
200
 
201
201
  const providerMetadataEntrySchema = () =>
202
- z
203
- .object({
204
- images: z.array(z.unknown()).optional(),
205
- })
206
- .catchall(z.unknown());
202
+ z.catchall(
203
+ z.object({
204
+ images: z.optional(z.array(z.unknown())),
205
+ }),
206
+ z.unknown(),
207
+ );
207
208
 
208
209
  const gatewayImageWarningSchema = () =>
209
210
  z.discriminatedUnion('type', [
210
211
  z.object({
211
212
  type: z.literal('unsupported'),
212
213
  feature: z.string(),
213
- details: z.string().optional(),
214
+ details: z.optional(z.string()),
214
215
  }),
215
216
  z.object({
216
217
  type: z.literal('compatibility'),
217
218
  feature: z.string(),
218
- details: z.string().optional(),
219
+ details: z.optional(z.string()),
219
220
  }),
220
221
  z.object({
221
222
  type: z.literal('deprecated'),
@@ -230,9 +231,9 @@ const gatewayImageWarningSchema = () =>
230
231
 
231
232
  const gatewayImageUsageSchema = () =>
232
233
  z.object({
233
- inputTokens: z.number().nullish(),
234
- outputTokens: z.number().nullish(),
235
- totalTokens: z.number().nullish(),
234
+ inputTokens: z.nullish(z.number()),
235
+ outputTokens: z.nullish(z.number()),
236
+ totalTokens: z.nullish(z.number()),
236
237
  });
237
238
 
238
239
  const gatewayImageResponseSchema = lazySchema(() =>
@@ -242,12 +243,12 @@ const gatewayImageResponseSchema = lazySchema(() =>
242
243
  // response is read (`experimental_binaryFields`), see
243
244
  // `toImageModelImages`.
244
245
  images: z.array(z.union([z.string(), z.instanceof(Uint8Array)])),
245
- isRetryable: z.boolean().optional(),
246
- warnings: z.array(gatewayImageWarningSchema()).optional(),
247
- providerMetadata: z
248
- .record(z.string(), providerMetadataEntrySchema())
249
- .optional(),
250
- usage: gatewayImageUsageSchema().optional(),
246
+ isRetryable: z.optional(z.boolean()),
247
+ warnings: z.optional(z.array(gatewayImageWarningSchema())),
248
+ providerMetadata: z.optional(
249
+ z.record(z.string(), providerMetadataEntrySchema()),
250
+ ),
251
+ usage: z.optional(gatewayImageUsageSchema()),
251
252
  }),
252
253
  ),
253
254
  );
@@ -31,7 +31,9 @@ export type GatewayModelId =
31
31
  | 'anthropic/claude-fable-5'
32
32
  | 'anthropic/claude-fable-5-batch'
33
33
  | 'anthropic/claude-fable-5.1'
34
+ | 'anthropic/claude-fable-5.2'
34
35
  | 'anthropic/claude-fable-5.1-batch'
36
+ | 'anthropic/claude-fable-5.2-batch'
35
37
  | 'anthropic/claude-haiku-4.5'
36
38
  | 'anthropic/claude-haiku-4.5-batch'
37
39
  | 'anthropic/claude-haiku-5.5'
@@ -76,6 +78,7 @@ export type GatewayModelId =
76
78
  | 'deepseek/deepseek-v4.1-flash'
77
79
  | 'deepseek/deepseek-v4.1-flash-1017'
78
80
  | 'deepseek/deepseek-v4.1-flash-1017-fast'
81
+ | 'deepseek/deepseek-v4.1-flash-1017-ultrafast'
79
82
  | 'deepseek/deepseek-v4.1-flash-fast'
80
83
  | 'elorian/glimpse'
81
84
  | 'fireworks/ember-1'
@@ -103,11 +106,13 @@ export type GatewayModelId =
103
106
  | 'google/gemini-3.7-flash'
104
107
  | 'google/gemini-3.8-flash'
105
108
  | 'google/gemini-4-argon'
109
+ | 'google/gemini-4-carbon'
106
110
  | 'google/gemini-nano-banana-2.1'
107
111
  | 'google/gemini-omni-1.2-flash'
108
112
  | 'google/gemini-omni-flash-preview'
109
113
  | 'google/gemma-4-26b-a4b-it'
110
114
  | 'google/gemma-4-31b-it'
115
+ | 'humansand/ampersand-v0.1'
111
116
  | 'inception/mercury-2'
112
117
  | 'inception/mercury-2.5'
113
118
  | 'inception/mercury-3'
@@ -128,6 +133,7 @@ export type GatewayModelId =
128
133
  | 'meta/llama-3.3-70b'
129
134
  | 'meta/llama-4-maverick'
130
135
  | 'meta/llama-4-scout'
136
+ | 'meta/muse-ember'
131
137
  | 'meta/muse-glimmer-30b'
132
138
  | 'meta/muse-spark-1.1'
133
139
  | 'meta/muse-spark-1.2'