@ai-sdk/gateway 4.0.139 → 4.0.141
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 +22 -0
- package/dist/index.d.ts +43 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -9
- package/dist/index.js.map +1 -1
- package/docs/00-ai-gateway.mdx +38 -1
- package/package.json +2 -2
- package/src/gateway-decision-model-settings.ts +1 -0
- package/src/gateway-language-model-settings.ts +5 -0
- package/src/tool/tako-search.ts +71 -5
package/docs/00-ai-gateway.mdx
CHANGED
|
@@ -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.
|
|
4
|
+
"version": "4.0.141",
|
|
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.
|
|
34
|
+
"@ai-sdk/provider-utils": "5.0.78",
|
|
35
35
|
"@vercel/oidc": "3.2.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
@@ -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'
|
|
@@ -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'
|
|
@@ -108,6 +111,7 @@ export type GatewayModelId =
|
|
|
108
111
|
| 'google/gemini-omni-flash-preview'
|
|
109
112
|
| 'google/gemma-4-26b-a4b-it'
|
|
110
113
|
| 'google/gemma-4-31b-it'
|
|
114
|
+
| 'humansand/ampersand-v0.1'
|
|
111
115
|
| 'inception/mercury-2'
|
|
112
116
|
| 'inception/mercury-2.5'
|
|
113
117
|
| 'inception/mercury-3'
|
|
@@ -128,6 +132,7 @@ export type GatewayModelId =
|
|
|
128
132
|
| 'meta/llama-3.3-70b'
|
|
129
133
|
| 'meta/llama-4-maverick'
|
|
130
134
|
| 'meta/llama-4-scout'
|
|
135
|
+
| 'meta/muse-ember'
|
|
131
136
|
| 'meta/muse-glimmer-30b'
|
|
132
137
|
| 'meta/muse-spark-1.1'
|
|
133
138
|
| 'meta/muse-spark-1.2'
|
package/src/tool/tako-search.ts
CHANGED
|
@@ -97,6 +97,23 @@ export interface TakoSearchConfig {
|
|
|
97
97
|
};
|
|
98
98
|
/** Maximum related search suggestions to include (1-20). */
|
|
99
99
|
includeRelated?: number;
|
|
100
|
+
/**
|
|
101
|
+
* Serve per-unit-priced data, such as web traffic and SEO. Each such card adds
|
|
102
|
+
* a charge, capped by maxVariableCostUsd. On by default; set false to opt out,
|
|
103
|
+
* and those cards come back as placeholders.
|
|
104
|
+
*/
|
|
105
|
+
variableCost?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Most one call can be charged in variable cost, in USD. Defaults to 0.25;
|
|
108
|
+
* null removes the cap. Cards that don't fit come back as placeholders with
|
|
109
|
+
* reason 'over_cap'. Can't be combined with variableCost: false.
|
|
110
|
+
*/
|
|
111
|
+
maxVariableCostUsd?: number | null;
|
|
112
|
+
/**
|
|
113
|
+
* Extra Tako request fields in snake_case, deep-merged into the body last.
|
|
114
|
+
* Can't set fields this tool models; Tako rejects unknown keys (api_error).
|
|
115
|
+
*/
|
|
116
|
+
extraBody?: Record<string, unknown>;
|
|
100
117
|
}
|
|
101
118
|
|
|
102
119
|
export interface TakoSearchInput {
|
|
@@ -168,11 +185,20 @@ export interface TakoResultContent {
|
|
|
168
185
|
expires_at?: string | null;
|
|
169
186
|
total_rows?: number | null;
|
|
170
187
|
truncated?: boolean;
|
|
188
|
+
/** Distinct records per premium class (e.g. company_record) among delivered rows. */
|
|
189
|
+
premium_rows?: Record<string, number> | null;
|
|
190
|
+
/** Column header → 0-based delivered-row positions whose premium value was withheld. */
|
|
191
|
+
redacted_cells?: Record<string, number[]> | null;
|
|
192
|
+
/** Full set size when the card lists only a capped slice of it. */
|
|
193
|
+
total_matching?: number | null;
|
|
171
194
|
export_pricing?: {
|
|
172
195
|
baseline_usd: number;
|
|
173
|
-
free_rows: number;
|
|
174
196
|
max_rows_ceiling: number;
|
|
175
197
|
row_cpm_usd: number;
|
|
198
|
+
/** USD per 1,000 premium records by class, added to row_cpm_usd when premium. */
|
|
199
|
+
premium_row_cpm_usd?: Record<string, number> | null;
|
|
200
|
+
/** Upper bound on this card's variable-cost charge; set only for per-unit-priced sources. */
|
|
201
|
+
variable_cost_max_usd?: number | null;
|
|
176
202
|
} | null;
|
|
177
203
|
manifest?: Array<{
|
|
178
204
|
dtype?: 'boolean' | 'date' | 'datetime' | 'number' | 'string' | null;
|
|
@@ -205,6 +231,8 @@ export interface TakoCard {
|
|
|
205
231
|
source_indexes?: Array<'data' | 'web'> | null;
|
|
206
232
|
card_type?: string | null;
|
|
207
233
|
relevance?: 'High' | 'Low' | 'Medium' | null;
|
|
234
|
+
/** Relevance to the query, 1.0-5.0. Null unless the account is entitled. */
|
|
235
|
+
relevance_score?: number | null;
|
|
208
236
|
content?: TakoResultContent | null;
|
|
209
237
|
exportable?: boolean;
|
|
210
238
|
nodes?: Array<{
|
|
@@ -222,6 +250,14 @@ export interface TakoCard {
|
|
|
222
250
|
data_as_of?: string | null;
|
|
223
251
|
last_updated?: string | null;
|
|
224
252
|
} | null;
|
|
253
|
+
/**
|
|
254
|
+
* Set when Tako withholds the card's data: variable cost off or not served
|
|
255
|
+
* (`not_served`), or over maxVariableCostUsd (`over_cap`).
|
|
256
|
+
*/
|
|
257
|
+
placeholder?: {
|
|
258
|
+
withheld_source: string;
|
|
259
|
+
reason?: 'not_served' | 'over_cap' | null;
|
|
260
|
+
} | null;
|
|
225
261
|
}
|
|
226
262
|
|
|
227
263
|
export interface TakoWebResult {
|
|
@@ -245,6 +281,10 @@ export interface TakoSearchResponse {
|
|
|
245
281
|
data?: {
|
|
246
282
|
cost_usd: number;
|
|
247
283
|
datasets: number;
|
|
284
|
+
data_points?: number | null;
|
|
285
|
+
} | null;
|
|
286
|
+
variable_cost?: {
|
|
287
|
+
cost_usd: number;
|
|
248
288
|
} | null;
|
|
249
289
|
} | null;
|
|
250
290
|
related?: Array<Record<string, unknown>> | null;
|
|
@@ -413,7 +453,7 @@ const takoSearchInputSchema = lazySchema(() =>
|
|
|
413
453
|
const takoDatasetCellSchema = () =>
|
|
414
454
|
z.union([z.boolean(), z.number(), z.string()]).nullable();
|
|
415
455
|
|
|
416
|
-
const takoResultContentSchema = () =>
|
|
456
|
+
export const takoResultContentSchema = () =>
|
|
417
457
|
z
|
|
418
458
|
.object({
|
|
419
459
|
content_format: z
|
|
@@ -450,13 +490,18 @@ const takoResultContentSchema = () =>
|
|
|
450
490
|
expires_at: z.string().nullish(),
|
|
451
491
|
total_rows: z.number().nullish(),
|
|
452
492
|
truncated: z.boolean().optional(),
|
|
493
|
+
premium_rows: z.record(z.string(), z.number()).nullish(),
|
|
494
|
+
redacted_cells: z.record(z.string(), z.array(z.number())).nullish(),
|
|
495
|
+
total_matching: z.number().nullish(),
|
|
453
496
|
export_pricing: z
|
|
454
497
|
.object({
|
|
455
498
|
baseline_usd: z.number(),
|
|
456
|
-
free_rows: z.number(),
|
|
457
499
|
max_rows_ceiling: z.number(),
|
|
458
500
|
row_cpm_usd: z.number(),
|
|
501
|
+
premium_row_cpm_usd: z.record(z.string(), z.number()).nullish(),
|
|
502
|
+
variable_cost_max_usd: z.number().nullish(),
|
|
459
503
|
})
|
|
504
|
+
.passthrough()
|
|
460
505
|
.nullish(),
|
|
461
506
|
manifest: z
|
|
462
507
|
.array(
|
|
@@ -506,6 +551,7 @@ const takoCardSchema = () =>
|
|
|
506
551
|
source_indexes: z.array(z.enum(['data', 'web'])).nullish(),
|
|
507
552
|
card_type: z.string().nullish(),
|
|
508
553
|
relevance: z.enum(['High', 'Low', 'Medium']).nullish(),
|
|
554
|
+
relevance_score: z.number().nullish(),
|
|
509
555
|
content: takoResultContentSchema().nullish(),
|
|
510
556
|
exportable: z.boolean().optional(),
|
|
511
557
|
nodes: z
|
|
@@ -528,6 +574,13 @@ const takoCardSchema = () =>
|
|
|
528
574
|
last_updated: z.string().nullish(),
|
|
529
575
|
})
|
|
530
576
|
.nullish(),
|
|
577
|
+
placeholder: z
|
|
578
|
+
.object({
|
|
579
|
+
withheld_source: z.string(),
|
|
580
|
+
reason: z.enum(['not_served', 'over_cap']).nullish(),
|
|
581
|
+
})
|
|
582
|
+
.passthrough()
|
|
583
|
+
.nullish(),
|
|
531
584
|
})
|
|
532
585
|
.passthrough();
|
|
533
586
|
|
|
@@ -554,11 +607,24 @@ const takoSearchOutputSchema = lazySchema(() =>
|
|
|
554
607
|
usage: z
|
|
555
608
|
.object({
|
|
556
609
|
total_cost_usd: z.number(),
|
|
557
|
-
compute: z
|
|
610
|
+
compute: z
|
|
611
|
+
.object({ cost_usd: z.number() })
|
|
612
|
+
.passthrough()
|
|
613
|
+
.nullish(),
|
|
558
614
|
data: z
|
|
559
|
-
.object({
|
|
615
|
+
.object({
|
|
616
|
+
cost_usd: z.number(),
|
|
617
|
+
datasets: z.number(),
|
|
618
|
+
data_points: z.number().nullish(),
|
|
619
|
+
})
|
|
620
|
+
.passthrough()
|
|
621
|
+
.nullish(),
|
|
622
|
+
variable_cost: z
|
|
623
|
+
.object({ cost_usd: z.number() })
|
|
624
|
+
.passthrough()
|
|
560
625
|
.nullish(),
|
|
561
626
|
})
|
|
627
|
+
.passthrough()
|
|
562
628
|
.nullish(),
|
|
563
629
|
related: z.array(z.object({}).passthrough()).nullish(),
|
|
564
630
|
})
|