@ai-sdk/gateway 3.0.201 → 3.0.202

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.
@@ -655,6 +655,132 @@ token-efficient content controls. Deep synthesis modes and generated summaries
655
655
  are intentionally not exposed yet because they have separate pricing from
656
656
  standard Search.
657
657
 
658
+ #### Browserbase Search
659
+
660
+ The Browserbase Search tool enables models to search the web using [Browserbase's Search API](https://docs.browserbase.com/reference/api/web-search). It is executed by AI Gateway and returns fast, structured search results without opening a browser session.
661
+
662
+ ```ts
663
+ import { gateway, generateText } from 'ai';
664
+
665
+ const result = await generateText({
666
+ model: 'openai/gpt-5.6-luna',
667
+ prompt:
668
+ 'Find official guidance on traveling with power banks on U.S. flights. Return the most relevant page titles and URLs.',
669
+ tools: {
670
+ browserbase_search: gateway.tools.browserbaseSearch(),
671
+ },
672
+ });
673
+
674
+ console.log(result.text);
675
+ console.log('Tool calls:', JSON.stringify(result.toolCalls, null, 2));
676
+ console.log('Tool results:', JSON.stringify(result.toolResults, null, 2));
677
+ ```
678
+
679
+ You can configure the maximum number of results returned by each search:
680
+
681
+ ```ts
682
+ import { gateway, generateText } from 'ai';
683
+
684
+ const result = await generateText({
685
+ model: 'openai/gpt-5.6-luna',
686
+ prompt:
687
+ 'Find three recent reviews comparing e-readers for outdoor reading. Return their titles and URLs.',
688
+ tools: {
689
+ browserbase_search: gateway.tools.browserbaseSearch({
690
+ numResults: 3,
691
+ }),
692
+ },
693
+ });
694
+
695
+ console.log(result.text);
696
+ ```
697
+
698
+ The Browserbase Search tool supports this optional configuration option:
699
+
700
+ - **numResults** _number_
701
+
702
+ Maximum number of search results to return (1-25, default: 10).
703
+
704
+ The tool works with both `generateText` and `streamText`.
705
+
706
+ #### Browserbase Fetch
707
+
708
+ The Browserbase Fetch tool enables models to retrieve page content using [Browserbase's Fetch API](https://docs.browserbase.com/platform/fetch/overview). It is a lightweight option for pages that do not require JavaScript execution or browser interaction, and it supports raw, Markdown, and schema-driven JSON output.
709
+
710
+ ```ts
711
+ import { gateway, generateText } from 'ai';
712
+
713
+ const result = await generateText({
714
+ model: 'openai/gpt-5.6-luna',
715
+ prompt:
716
+ 'Fetch https://www.nps.gov/yose/planyourvisit/halfdome.htm and summarize the permit requirements and main safety warnings.',
717
+ tools: {
718
+ browserbase_fetch: gateway.tools.browserbaseFetch(),
719
+ },
720
+ });
721
+
722
+ console.log(result.text);
723
+ console.log('Tool calls:', JSON.stringify(result.toolCalls, null, 2));
724
+ console.log('Tool results:', JSON.stringify(result.toolResults, null, 2));
725
+ ```
726
+
727
+ You can configure the output format and request behavior. For example, use JSON extraction to return content matching a JSON Schema:
728
+
729
+ ```ts
730
+ import { gateway, generateText } from 'ai';
731
+
732
+ const result = await generateText({
733
+ model: 'openai/gpt-5.6-luna',
734
+ prompt:
735
+ 'Fetch https://www.nps.gov/yose/planyourvisit/halfdome.htm and extract its page title, whether a permit is required, and three safety tips.',
736
+ tools: {
737
+ browserbase_fetch: gateway.tools.browserbaseFetch({
738
+ allowRedirects: true,
739
+ format: 'json',
740
+ schema: {
741
+ type: 'object',
742
+ properties: {
743
+ pageTitle: { type: 'string' },
744
+ permitRequired: { type: 'boolean' },
745
+ safetyTips: {
746
+ type: 'array',
747
+ items: { type: 'string' },
748
+ maxItems: 3,
749
+ },
750
+ },
751
+ required: ['pageTitle', 'permitRequired', 'safetyTips'],
752
+ },
753
+ }),
754
+ },
755
+ });
756
+
757
+ console.log(result.text);
758
+ ```
759
+
760
+ The Browserbase Fetch tool supports these optional configuration options:
761
+
762
+ - **format** _'raw' | 'markdown' | 'json'_
763
+
764
+ Output format for the fetched content. `raw` returns the upstream response body unchanged and is the default. `markdown` converts the page to Markdown. `json` performs structured extraction and requires `schema`.
765
+
766
+ - **schema** _object_
767
+
768
+ JSON Schema describing the desired structured content. Only used when `format` is `json`.
769
+
770
+ - **allowRedirects** _boolean_
771
+
772
+ Follow HTTP redirects. Defaults to `false`.
773
+
774
+ - **proxies** _boolean_
775
+
776
+ Route the request through Browserbase's proxy network. Defaults to `false`.
777
+
778
+ - **allowInsecureSsl** _boolean_
779
+
780
+ Bypass TLS certificate verification. Defaults to `false`; only enable it for trusted hosts.
781
+
782
+ The Fetch API does not execute JavaScript. Use a browser session for interactive or JavaScript-rendered pages. The tool works with both `generateText` and `streamText`.
783
+
658
784
  #### Tako Search
659
785
 
660
786
  The Tako Search tool enables models to search the web and Tako's curated knowledge graph in a single call using [Tako's Search API](https://docs.tako.com/documentation/integrating-tako/search/overview). This tool is executed by the AI Gateway and returns token-efficient web excerpts, plus knowledge-graph results that carry structured data, premium source attribution, and an embed-ready visualization.
@@ -1064,7 +1190,7 @@ The following gateway provider options are available:
1064
1190
 
1065
1191
  The unique identifier for the entity against which quota is tracked. Used for quota management and enforcement purposes.
1066
1192
 
1067
- - **has** _Array<'implicit-caching' | 'reasoning' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>_
1193
+ - **has** _Array<'implicit-caching' | 'reasoning' | 'structured-output' | 'tool-use' | 'vision' | `quantization:${string}` | `!quantization:${string}`>_
1068
1194
 
1069
1195
  Restricts routing to provider models that have all of the specified capabilities. Applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. If no provider model for the requested model satisfies the capabilities, the request fails. Unsupported values are rejected.
1070
1196
 
@@ -1072,6 +1198,7 @@ The following gateway provider options are available:
1072
1198
 
1073
1199
  - `'implicit-caching'` — models that perform automatic (implicit) prompt caching.
1074
1200
  - `'reasoning'` — models that support reasoning.
1201
+ - `'structured-output'` — models that support schema-constrained output.
1075
1202
  - `'tool-use'` — models that support tool calling.
1076
1203
  - `'vision'` — models that accept image input.
1077
1204
 
@@ -1215,7 +1342,7 @@ const { text } = await generateText({
1215
1342
 
1216
1343
  #### Filtering by Model Capability
1217
1344
 
1218
- Set `has` to restrict routing to provider models that have the specified capabilities. This applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. `'implicit-caching'` limits routing to models that perform automatic prompt caching, `'vision'` limits routing to models that accept image input, `'reasoning'` limits routing to models that support reasoning, and `'tool-use'` limits routing to models that support tool calling. Weight-format conditions (`'quantization:fp8'` to require, `'!quantization:fp8'` to exclude) limit routing by the serving provider's recorded weight format. If no provider model for the requested model satisfies the capabilities, the request fails.
1345
+ Set `has` to restrict routing to provider models that have the specified capabilities. This applies to both BYOK and system credentials, since the capability is a property of the model rather than the credential. `'implicit-caching'` limits routing to models that perform automatic prompt caching, `'vision'` limits routing to models that accept image input, `'reasoning'` limits routing to models that support reasoning, `'structured-output'` limits routing to models that support schema-constrained output, and `'tool-use'` limits routing to models that support tool calling. Weight-format conditions (`'quantization:fp8'` to require, `'!quantization:fp8'` to exclude) limit routing by the serving provider's recorded weight format. If no provider model for the requested model satisfies the capabilities, the request fails.
1219
1346
 
1220
1347
  ```ts
1221
1348
  import type { GatewayProviderOptions } from "@ai-sdk/gateway";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ai-sdk/gateway",
3
3
  "private": false,
4
- "version": "3.0.201",
4
+ "version": "3.0.202",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
7
7
  "main": "./dist/index.js",
@@ -117,6 +117,7 @@ const gatewayProviderOptions = lazySchema(() =>
117
117
  * - `'implicit-caching'`: models that perform automatic (implicit)
118
118
  * prompt caching
119
119
  * - `'reasoning'`: models that support reasoning
120
+ * - `'structured-output'`: models that support schema-constrained output
120
121
  * - `'tool-use'`: models that support tool calling
121
122
  * - `'vision'`: models that accept image input
122
123
  * - `'quantization:<value>'`: providers serving that weight format
@@ -130,7 +131,13 @@ const gatewayProviderOptions = lazySchema(() =>
130
131
  has: z
131
132
  .array(
132
133
  z.union([
133
- z.enum(['implicit-caching', 'reasoning', 'tool-use', 'vision']),
134
+ z.enum([
135
+ 'implicit-caching',
136
+ 'reasoning',
137
+ 'structured-output',
138
+ 'tool-use',
139
+ 'vision',
140
+ ]),
134
141
  z.templateLiteral(['quantization:', z.string()]),
135
142
  z.templateLiteral(['!quantization:', z.string()]),
136
143
  ]),
@@ -1,3 +1,5 @@
1
+ import { browserbaseFetch } from './tool/browserbase-fetch';
2
+ import { browserbaseSearch } from './tool/browserbase-search';
1
3
  import { exaSearch } from './tool/exa-search';
2
4
  import { parallelSearch } from './tool/parallel-search';
3
5
  import { perplexitySearch } from './tool/perplexity-search';
@@ -7,6 +9,22 @@ import { takoSearch } from './tool/tako-search';
7
9
  * Gateway-specific provider-defined tools.
8
10
  */
9
11
  export const gatewayTools = {
12
+ /**
13
+ * Fetch page content using Browserbase's lightweight Fetch API.
14
+ *
15
+ * Supports raw, Markdown, and schema-driven JSON output as well as redirects,
16
+ * proxy routing, and TLS controls.
17
+ */
18
+ browserbaseFetch,
19
+
20
+ /**
21
+ * Search the web using Browserbase's Search API for fast, structured results.
22
+ *
23
+ * Returns titles, URLs, and available publication metadata without requiring
24
+ * a browser session.
25
+ */
26
+ browserbaseSearch,
27
+
10
28
  /**
11
29
  * Search the web using Exa for current information and token-efficient
12
30
  * excerpts optimized for agent workflows.
@@ -0,0 +1,158 @@
1
+ import {
2
+ createProviderToolFactoryWithOutputSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod';
7
+
8
+ export type BrowserbaseFetchFormat = 'raw' | 'json' | 'markdown';
9
+
10
+ export interface BrowserbaseFetchConfig {
11
+ /** Whether to follow HTTP redirects (default: false). */
12
+ allowRedirects?: boolean;
13
+ /** Whether to bypass TLS certificate verification (default: false). */
14
+ allowInsecureSsl?: boolean;
15
+ /** Whether to route the request through Browserbase proxies (default: false). */
16
+ proxies?: boolean;
17
+ /** Output format for the response content (default: raw). */
18
+ format?: BrowserbaseFetchFormat;
19
+ /**
20
+ * JSON Schema describing the desired response content. Only used when format
21
+ * is json.
22
+ */
23
+ schema?: Record<string, unknown>;
24
+ }
25
+
26
+ export interface BrowserbaseFetchInput {
27
+ /** URL of the page to fetch. */
28
+ url: string;
29
+ /** Whether to follow HTTP redirects. */
30
+ allow_redirects?: boolean;
31
+ /** Whether to bypass TLS certificate verification. */
32
+ allow_insecure_ssl?: boolean;
33
+ /** Whether to route the request through Browserbase proxies. */
34
+ proxies?: boolean;
35
+ /** Output format for the response content. */
36
+ format?: BrowserbaseFetchFormat;
37
+ /**
38
+ * JSON Schema describing the desired response content. Only used when format
39
+ * is json.
40
+ */
41
+ schema?: Record<string, unknown>;
42
+ }
43
+
44
+ export interface BrowserbaseFetchResponse {
45
+ /** Unique identifier for the fetch request. */
46
+ id: string;
47
+ /**
48
+ * Response body. Raw and markdown responses return strings; JSON extraction
49
+ * returns an object matching the requested schema.
50
+ */
51
+ content: string | Record<string, unknown>;
52
+ /** MIME type of the response. */
53
+ contentType: string;
54
+ /** Character encoding of the response. */
55
+ encoding: string;
56
+ /** Response headers from the fetched page. */
57
+ headers: Record<string, string>;
58
+ /** HTTP status code returned by the fetched page. */
59
+ statusCode: number;
60
+ }
61
+
62
+ export interface BrowserbaseFetchError {
63
+ error:
64
+ | 'api_error'
65
+ | 'configuration_error'
66
+ | 'execution_error'
67
+ | 'invalid_input'
68
+ | 'rate_limit'
69
+ | 'timeout'
70
+ | 'unknown';
71
+ statusCode?: number;
72
+ message: string;
73
+ }
74
+
75
+ export type BrowserbaseFetchOutput =
76
+ | BrowserbaseFetchError
77
+ | BrowserbaseFetchResponse;
78
+
79
+ const jsonObjectSchema = z.record(z.string(), z.unknown());
80
+
81
+ const browserbaseFetchInputSchema = lazySchema(() =>
82
+ zodSchema(
83
+ z.object({
84
+ url: z.string().url().describe('URL of the page to fetch.'),
85
+ allow_redirects: z
86
+ .boolean()
87
+ .optional()
88
+ .describe('Whether to follow HTTP redirects (default: false).'),
89
+ allow_insecure_ssl: z
90
+ .boolean()
91
+ .optional()
92
+ .describe(
93
+ 'Whether to bypass TLS certificate verification (default: false). Only use for trusted hosts.',
94
+ ),
95
+ proxies: z
96
+ .boolean()
97
+ .optional()
98
+ .describe(
99
+ 'Whether to route the request through Browserbase proxies (default: false).',
100
+ ),
101
+ format: z
102
+ .enum(['raw', 'json', 'markdown'])
103
+ .optional()
104
+ .describe(
105
+ 'Output format. raw returns the response body unchanged, markdown returns page content as Markdown, and json returns structured content using schema.',
106
+ ),
107
+ schema: jsonObjectSchema
108
+ .optional()
109
+ .describe(
110
+ 'JSON Schema for structured extraction. Only use with format set to json.',
111
+ ),
112
+ }),
113
+ ),
114
+ );
115
+
116
+ const browserbaseFetchOutputSchema = lazySchema(() =>
117
+ zodSchema(
118
+ z.union([
119
+ z.object({
120
+ id: z.string(),
121
+ content: z.union([z.string(), jsonObjectSchema]),
122
+ contentType: z.string(),
123
+ encoding: z.string(),
124
+ headers: z.record(z.string(), z.string()),
125
+ statusCode: z.number(),
126
+ }),
127
+ z.object({
128
+ error: z.enum([
129
+ 'api_error',
130
+ 'configuration_error',
131
+ 'execution_error',
132
+ 'invalid_input',
133
+ 'rate_limit',
134
+ 'timeout',
135
+ 'unknown',
136
+ ]),
137
+ statusCode: z.number().optional(),
138
+ message: z.string(),
139
+ }),
140
+ ]),
141
+ ),
142
+ );
143
+
144
+ export const browserbaseFetchToolFactory =
145
+ createProviderToolFactoryWithOutputSchema<
146
+ BrowserbaseFetchInput,
147
+ BrowserbaseFetchOutput,
148
+ BrowserbaseFetchConfig
149
+ >({
150
+ id: 'gateway.browserbase_fetch',
151
+ inputSchema: browserbaseFetchInputSchema,
152
+ outputSchema: browserbaseFetchOutputSchema,
153
+ });
154
+
155
+ export const browserbaseFetch = (
156
+ config: BrowserbaseFetchConfig = {},
157
+ ): ReturnType<typeof browserbaseFetchToolFactory> =>
158
+ browserbaseFetchToolFactory(config);
@@ -0,0 +1,138 @@
1
+ import {
2
+ createProviderToolFactoryWithOutputSchema,
3
+ lazySchema,
4
+ zodSchema,
5
+ } from '@ai-sdk/provider-utils';
6
+ import { z } from 'zod';
7
+
8
+ export interface BrowserbaseSearchConfig {
9
+ /**
10
+ * Default maximum number of results to return (1-25, default: 10).
11
+ */
12
+ numResults?: number;
13
+ }
14
+
15
+ export interface BrowserbaseSearchInput {
16
+ /**
17
+ * Web search query (1-200 characters).
18
+ */
19
+ query: string;
20
+
21
+ /**
22
+ * Maximum number of results to return (1-25, default: 10).
23
+ */
24
+ num_results?: number;
25
+ }
26
+
27
+ export interface BrowserbaseSearchResult {
28
+ /** Unique identifier for the result. */
29
+ id: string;
30
+ /** Title of the search result. */
31
+ title: string;
32
+ /** URL of the search result. */
33
+ url: string;
34
+ /** Author of the content, when available. */
35
+ author?: string;
36
+ /** Favicon URL, when available. */
37
+ favicon?: string;
38
+ /** Image URL, when available. */
39
+ image?: string;
40
+ /** Publication date in ISO 8601 format, when available. */
41
+ publishedDate?: string;
42
+ }
43
+
44
+ export interface BrowserbaseSearchResponse {
45
+ /** The search query that was executed. */
46
+ query: string;
47
+ /** Unique identifier for the request. */
48
+ requestId: string;
49
+ /** Search results. */
50
+ results: BrowserbaseSearchResult[];
51
+ }
52
+
53
+ export interface BrowserbaseSearchError {
54
+ error:
55
+ | 'api_error'
56
+ | 'configuration_error'
57
+ | 'execution_error'
58
+ | 'invalid_input'
59
+ | 'rate_limit'
60
+ | 'timeout'
61
+ | 'unknown';
62
+ statusCode?: number;
63
+ message: string;
64
+ }
65
+
66
+ export type BrowserbaseSearchOutput =
67
+ | BrowserbaseSearchError
68
+ | BrowserbaseSearchResponse;
69
+
70
+ const browserbaseSearchInputSchema = lazySchema(() =>
71
+ zodSchema(
72
+ z.object({
73
+ query: z
74
+ .string()
75
+ .min(1)
76
+ .max(200)
77
+ .describe('Web search query. Must be between 1 and 200 characters.'),
78
+ num_results: z
79
+ .number()
80
+ .int()
81
+ .min(1)
82
+ .max(25)
83
+ .optional()
84
+ .describe('Maximum number of results to return (1-25, default: 10).'),
85
+ }),
86
+ ),
87
+ );
88
+
89
+ const browserbaseSearchOutputSchema = lazySchema(() =>
90
+ zodSchema(
91
+ z.union([
92
+ z.object({
93
+ query: z.string(),
94
+ requestId: z.string(),
95
+ results: z.array(
96
+ z.object({
97
+ id: z.string(),
98
+ title: z.string(),
99
+ url: z.string(),
100
+ author: z.string().optional(),
101
+ favicon: z.string().optional(),
102
+ image: z.string().optional(),
103
+ publishedDate: z.string().optional(),
104
+ }),
105
+ ),
106
+ }),
107
+ z.object({
108
+ error: z.enum([
109
+ 'api_error',
110
+ 'configuration_error',
111
+ 'execution_error',
112
+ 'invalid_input',
113
+ 'rate_limit',
114
+ 'timeout',
115
+ 'unknown',
116
+ ]),
117
+ statusCode: z.number().optional(),
118
+ message: z.string(),
119
+ }),
120
+ ]),
121
+ ),
122
+ );
123
+
124
+ export const browserbaseSearchToolFactory =
125
+ createProviderToolFactoryWithOutputSchema<
126
+ BrowserbaseSearchInput,
127
+ BrowserbaseSearchOutput,
128
+ BrowserbaseSearchConfig
129
+ >({
130
+ id: 'gateway.browserbase_search',
131
+ inputSchema: browserbaseSearchInputSchema,
132
+ outputSchema: browserbaseSearchOutputSchema,
133
+ });
134
+
135
+ export const browserbaseSearch = (
136
+ config: BrowserbaseSearchConfig = {},
137
+ ): ReturnType<typeof browserbaseSearchToolFactory> =>
138
+ browserbaseSearchToolFactory(config);