@ai-sdk/anthropic 4.0.84 → 4.0.86

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.
@@ -1,3 +1,8 @@
1
+ import {
2
+ lazySchema,
3
+ zodSchema,
4
+ type InferSchema,
5
+ } from '@ai-sdk/provider-utils';
1
6
  import { z } from 'zod/v4';
2
7
 
3
8
  // https://docs.claude.com/en/docs/about-claude/models/overview
@@ -32,447 +37,461 @@ export type AnthropicModelId =
32
37
  * Anthropic file part provider options for document-specific features.
33
38
  * These options apply to individual file parts (documents).
34
39
  */
35
- export const anthropicFilePartProviderOptions = z.object({
36
- /**
37
- * Upload this file into the code execution container instead of sending it as
38
- * a normal document or image content block.
39
- */
40
- containerUpload: z.boolean().optional(),
40
+ export const anthropicFilePartProviderOptions = lazySchema(() =>
41
+ zodSchema(
42
+ z.object({
43
+ /**
44
+ * Upload this file into the code execution container instead of sending it as
45
+ * a normal document or image content block.
46
+ */
47
+ containerUpload: z.boolean().optional(),
41
48
 
42
- /**
43
- * Citation configuration for this document.
44
- * When enabled, this document will generate citations in the response.
45
- */
46
- citations: z
47
- .object({
48
49
  /**
49
- * Enable citations for this document
50
+ * Citation configuration for this document.
51
+ * When enabled, this document will generate citations in the response.
50
52
  */
51
- enabled: z.boolean(),
52
- })
53
- .optional(),
53
+ citations: z
54
+ .object({
55
+ /**
56
+ * Enable citations for this document
57
+ */
58
+ enabled: z.boolean(),
59
+ })
60
+ .optional(),
54
61
 
55
- /**
56
- * Custom title for the document.
57
- * If not provided, the filename will be used.
58
- */
59
- title: z.string().optional(),
62
+ /**
63
+ * Custom title for the document.
64
+ * If not provided, the filename will be used.
65
+ */
66
+ title: z.string().optional(),
60
67
 
61
- /**
62
- * Context about the document that will be passed to the model
63
- * but not used towards cited content.
64
- * Useful for storing document metadata as text or stringified JSON.
65
- */
66
- context: z.string().optional(),
67
- });
68
+ /**
69
+ * Context about the document that will be passed to the model
70
+ * but not used towards cited content.
71
+ * Useful for storing document metadata as text or stringified JSON.
72
+ */
73
+ context: z.string().optional(),
74
+ }),
75
+ ),
76
+ );
68
77
 
69
- export type AnthropicFilePartProviderOptions = z.infer<
78
+ export type AnthropicFilePartProviderOptions = InferSchema<
70
79
  typeof anthropicFilePartProviderOptions
71
80
  >;
72
81
 
73
82
  /**
74
83
  * Anthropic provider options for system messages.
75
84
  */
76
- export const anthropicSystemMessageProviderOptions = z.object({
77
- /**
78
- * Controls when an ephemeral mid-conversation system message is cleared.
79
- *
80
- * Only supported on system messages that appear mid-conversation.
81
- * The required `mid-conversation-system-clear-at-2026-08-21` beta is
82
- * added automatically.
83
- */
84
- clearAt: z.literal('next_user_message').optional(),
85
+ export const anthropicSystemMessageProviderOptions = lazySchema(() =>
86
+ zodSchema(
87
+ z.object({
88
+ /**
89
+ * Controls when an ephemeral mid-conversation system message is cleared.
90
+ *
91
+ * Only supported on system messages that appear mid-conversation.
92
+ * The required `mid-conversation-system-clear-at-2026-08-21` beta is
93
+ * added automatically.
94
+ */
95
+ clearAt: z.literal('next_user_message').optional(),
85
96
 
86
- /**
87
- * Sets the model effort from the next user turn until a later message
88
- * changes it. An effort-only system message with empty content can appear
89
- * first. The required `mid-conversation-output-config-2026-07-01` beta is
90
- * added automatically.
91
- */
92
- effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
97
+ /**
98
+ * Sets the model effort from the next user turn until a later message
99
+ * changes it. An effort-only system message with empty content can appear
100
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
101
+ * added automatically.
102
+ */
103
+ effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
93
104
 
94
- /**
95
- * Mid-conversation tool changes. Adds or removes tools from the
96
- * conversation's tool set between turns without invalidating the prompt
97
- * cache.
98
- *
99
- * Only supported on system messages that appear mid-conversation (not the
100
- * initial system prompt). A system message carrying tool changes must come
101
- * right before an assistant message or at the end of the messages.
102
- *
103
- * Tools referenced by a `tool_addition` must be declared in the `tools`
104
- * option (typically with `deferLoading: true` so they are not loaded until
105
- * the addition surfaces them). The required
106
- * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
107
- */
108
- toolChanges: z
109
- .array(
110
- z.discriminatedUnion('type', [
111
- z.object({
112
- type: z.literal('tool_addition'),
113
- toolName: z.string(),
114
- }),
115
- z.object({
116
- type: z.literal('tool_removal'),
117
- toolName: z.string(),
118
- }),
119
- ]),
120
- )
121
- .optional(),
122
- });
105
+ /**
106
+ * Mid-conversation tool changes. Adds or removes tools from the
107
+ * conversation's tool set between turns without invalidating the prompt
108
+ * cache.
109
+ *
110
+ * Only supported on system messages that appear mid-conversation (not the
111
+ * initial system prompt). A system message carrying tool changes must come
112
+ * right before an assistant message or at the end of the messages.
113
+ *
114
+ * Tools referenced by a `tool_addition` must be declared in the `tools`
115
+ * option (typically with `deferLoading: true` so they are not loaded until
116
+ * the addition surfaces them). The required
117
+ * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
118
+ */
119
+ toolChanges: z
120
+ .array(
121
+ z.discriminatedUnion('type', [
122
+ z.object({
123
+ type: z.literal('tool_addition'),
124
+ toolName: z.string(),
125
+ }),
126
+ z.object({
127
+ type: z.literal('tool_removal'),
128
+ toolName: z.string(),
129
+ }),
130
+ ]),
131
+ )
132
+ .optional(),
133
+ }),
134
+ ),
135
+ );
123
136
 
124
- export type AnthropicSystemMessageProviderOptions = z.infer<
137
+ export type AnthropicSystemMessageProviderOptions = InferSchema<
125
138
  typeof anthropicSystemMessageProviderOptions
126
139
  >;
127
140
 
128
- export const anthropicLanguageModelOptions = z.object({
129
- /**
130
- * Whether to send reasoning to the model.
131
- *
132
- * This allows you to deactivate reasoning inputs for models that do not support them.
133
- */
134
- sendReasoning: z.boolean().optional(),
135
-
136
- /**
137
- * Determines how structured outputs are generated.
138
- *
139
- * - `outputFormat`: Use the `output_config.format` parameter to specify the structured output format.
140
- * - `jsonTool`: Use a special 'json' tool to specify the structured output format.
141
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
142
- */
143
- structuredOutputMode: z.enum(['outputFormat', 'jsonTool', 'auto']).optional(),
144
-
145
- /**
146
- * Configuration for enabling Claude's extended thinking.
147
- *
148
- * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
149
- * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
150
- *
151
- * Models that always use adaptive thinking (e.g. `claude-opus-5-5`,
152
- * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
153
- * provider drops the unsupported setting, emits a warning, and sends an
154
- * adaptive thinking request. Use `effort` to control how much they think.
155
- *
156
- * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
157
- * and the provider uses it in place of `disabled` for that model.
158
- */
159
- thinking: z
160
- .union([
161
- z.discriminatedUnion('type', [
162
- z.object({
163
- /** for Sonnet 4.6, Opus 4.6, and newer models */
164
- type: z.literal('adaptive'),
165
- /**
166
- * Controls whether thinking content is included in the response.
167
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
168
- * - `"summarized"`: Thinking content is returned.
169
- * - `"updates"`: Thinking updates are returned between tool calls.
170
- */
171
- display: z.enum(['omitted', 'summarized', 'updates']).optional(),
172
- /**
173
- * Controls how thinking blocks are bound to an existing thinking
174
- * prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
175
- */
176
- blockBinding: z
177
- .object({
178
- prefixMismatchBehavior: z.enum(['error', 'drop_block']),
179
- })
180
- .optional(),
181
- }),
182
- z.object({
183
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
184
- type: z.literal('enabled'),
185
- budgetTokens: z.number().optional(),
186
- }),
187
- z.object({
188
- type: z.literal('disabled'),
189
- }),
190
- z.object({
191
- /**
192
- * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
193
- * between tool calls are returned as summarized thinking blocks.
194
- * Only supported at `low`, `medium`, and `high` effort.
195
- */
196
- type: z.literal('between_tools'),
197
- }),
198
- ]),
199
- z.object({
200
- type: z.never().optional(),
201
- blockBinding: z.object({
202
- prefixMismatchBehavior: z.enum(['error', 'drop_block']),
203
- }),
204
- }),
205
- ])
206
- .optional(),
207
-
208
- /**
209
- * Whether to disable parallel function calling during tool use. Default is false.
210
- * When set to true, Claude will use at most one tool per response.
211
- */
212
- disableParallelToolUse: z.boolean().optional(),
213
-
214
- /**
215
- * Cache control settings for this message.
216
- * See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
217
- */
218
- cacheControl: z
219
- .object({
220
- type: z.literal('ephemeral'),
221
- ttl: z.union([z.literal('5m'), z.literal('1h')]).optional(),
222
- })
223
- .optional(),
224
-
225
- /**
226
- * Metadata to include with the request.
227
- *
228
- * See https://platform.claude.com/docs/en/api/messages/create for details.
229
- */
230
- metadata: z
231
- .object({
141
+ export const anthropicLanguageModelOptions = lazySchema(() =>
142
+ zodSchema(
143
+ z.object({
232
144
  /**
233
- * An external identifier for the user associated with the request.
145
+ * Whether to send reasoning to the model.
234
146
  *
235
- * Should be a UUID, hash value, or other opaque identifier.
236
- * Must not contain PII (name, email, phone number, etc.).
147
+ * This allows you to deactivate reasoning inputs for models that do not support them.
237
148
  */
238
- userId: z.string().optional(),
239
- })
240
- .optional(),
149
+ sendReasoning: z.boolean().optional(),
241
150
 
242
- /**
243
- * MCP servers to be utilized in this request.
244
- */
245
- mcpServers: z
246
- .array(
247
- z.object({
248
- type: z.literal('url'),
249
- name: z.string(),
250
- url: z.string(),
251
- authorizationToken: z.string().nullish(),
252
- toolConfiguration: z
253
- .object({
254
- enabled: z.boolean().nullish(),
255
- allowedTools: z.array(z.string()).nullish(),
256
- })
257
- .nullish(),
258
- }),
259
- )
260
- .optional(),
151
+ /**
152
+ * Determines how structured outputs are generated.
153
+ *
154
+ * - `outputFormat`: Use the `output_config.format` parameter to specify the structured output format.
155
+ * - `jsonTool`: Use a special 'json' tool to specify the structured output format.
156
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default).
157
+ */
158
+ structuredOutputMode: z
159
+ .enum(['outputFormat', 'jsonTool', 'auto'])
160
+ .optional(),
261
161
 
262
- /**
263
- * Agent Skills configuration. Skills enable Claude to perform specialized tasks
264
- * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
265
- * Requires code execution tool to be enabled.
266
- */
267
- container: z
268
- .object({
269
- id: z.string().optional(),
270
- skills: z
271
- .array(
162
+ /**
163
+ * Configuration for enabling Claude's extended thinking.
164
+ *
165
+ * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
166
+ * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
167
+ *
168
+ * Models that always use adaptive thinking (e.g. `claude-opus-5-5`,
169
+ * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
170
+ * provider drops the unsupported setting, emits a warning, and sends an
171
+ * adaptive thinking request. Use `effort` to control how much they think.
172
+ *
173
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
174
+ * and the provider uses it in place of `disabled` for that model.
175
+ */
176
+ thinking: z
177
+ .union([
272
178
  z.discriminatedUnion('type', [
273
179
  z.object({
274
- type: z.literal('anthropic'),
275
- skillId: z.string(),
276
- version: z.string().optional(),
180
+ /** for Sonnet 4.6, Opus 4.6, and newer models */
181
+ type: z.literal('adaptive'),
182
+ /**
183
+ * Controls whether thinking content is included in the response.
184
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
185
+ * - `"summarized"`: Thinking content is returned.
186
+ * - `"updates"`: Thinking updates are returned between tool calls.
187
+ */
188
+ display: z.enum(['omitted', 'summarized', 'updates']).optional(),
189
+ /**
190
+ * Controls how thinking blocks are bound to an existing thinking
191
+ * prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
192
+ */
193
+ blockBinding: z
194
+ .object({
195
+ prefixMismatchBehavior: z.enum(['error', 'drop_block']),
196
+ })
197
+ .optional(),
198
+ }),
199
+ z.object({
200
+ /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
201
+ type: z.literal('enabled'),
202
+ budgetTokens: z.number().optional(),
203
+ }),
204
+ z.object({
205
+ type: z.literal('disabled'),
277
206
  }),
278
207
  z.object({
279
- type: z.literal('custom'),
280
- providerReference: z.record(z.string(), z.string()),
281
- version: z.string().optional(),
208
+ /**
209
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
210
+ * between tool calls are returned as summarized thinking blocks.
211
+ * Only supported at `low`, `medium`, and `high` effort.
212
+ */
213
+ type: z.literal('between_tools'),
282
214
  }),
283
215
  ]),
284
- )
216
+ z.object({
217
+ type: z.never().optional(),
218
+ blockBinding: z.object({
219
+ prefixMismatchBehavior: z.enum(['error', 'drop_block']),
220
+ }),
221
+ }),
222
+ ])
223
+ .optional(),
224
+
225
+ /**
226
+ * Whether to disable parallel function calling during tool use. Default is false.
227
+ * When set to true, Claude will use at most one tool per response.
228
+ */
229
+ disableParallelToolUse: z.boolean().optional(),
230
+
231
+ /**
232
+ * Cache control settings for this message.
233
+ * See https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
234
+ */
235
+ cacheControl: z
236
+ .object({
237
+ type: z.literal('ephemeral'),
238
+ ttl: z.union([z.literal('5m'), z.literal('1h')]).optional(),
239
+ })
240
+ .optional(),
241
+
242
+ /**
243
+ * Metadata to include with the request.
244
+ *
245
+ * See https://platform.claude.com/docs/en/api/messages/create for details.
246
+ */
247
+ metadata: z
248
+ .object({
249
+ /**
250
+ * An external identifier for the user associated with the request.
251
+ *
252
+ * Should be a UUID, hash value, or other opaque identifier.
253
+ * Must not contain PII (name, email, phone number, etc.).
254
+ */
255
+ userId: z.string().optional(),
256
+ })
285
257
  .optional(),
286
- })
287
- .optional(),
288
258
 
289
- /**
290
- * Whether to enable fine-grained (eager) streaming of tool call inputs
291
- * and structured outputs for every function tool in the request. When
292
- * true (the default), each function tool receives a default of
293
- * `eager_input_streaming: true` unless it explicitly sets
294
- * `providerOptions.anthropic.eagerInputStreaming`.
295
- *
296
- * @default true
297
- */
298
- toolStreaming: z.boolean().optional(),
259
+ /**
260
+ * MCP servers to be utilized in this request.
261
+ */
262
+ mcpServers: z
263
+ .array(
264
+ z.object({
265
+ type: z.literal('url'),
266
+ name: z.string(),
267
+ url: z.string(),
268
+ authorizationToken: z.string().nullish(),
269
+ toolConfiguration: z
270
+ .object({
271
+ enabled: z.boolean().nullish(),
272
+ allowedTools: z.array(z.string()).nullish(),
273
+ })
274
+ .nullish(),
275
+ }),
276
+ )
277
+ .optional(),
299
278
 
300
- /**
301
- * Controls how much effort the model spends on thinking, text responses,
302
- * and tool calls. On models that always use adaptive thinking
303
- * (e.g. `claude-opus-5-5`), effort is the main lever for latency and cost.
304
- *
305
- * The API default is `high` for most models and `medium` for `claude-opus-5-5`.
306
- */
307
- effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
279
+ /**
280
+ * Agent Skills configuration. Skills enable Claude to perform specialized tasks
281
+ * like document processing (PPTX, DOCX, PDF, XLSX) and data analysis.
282
+ * Requires code execution tool to be enabled.
283
+ */
284
+ container: z
285
+ .object({
286
+ id: z.string().optional(),
287
+ skills: z
288
+ .array(
289
+ z.discriminatedUnion('type', [
290
+ z.object({
291
+ type: z.literal('anthropic'),
292
+ skillId: z.string(),
293
+ version: z.string().optional(),
294
+ }),
295
+ z.object({
296
+ type: z.literal('custom'),
297
+ providerReference: z.record(z.string(), z.string()),
298
+ version: z.string().optional(),
299
+ }),
300
+ ]),
301
+ )
302
+ .optional(),
303
+ })
304
+ .optional(),
308
305
 
309
- /**
310
- * Task budget for agentic turns. Informs the model of the total token budget
311
- * available for the current task, allowing it to prioritize work and wind down
312
- * gracefully as the budget is consumed.
313
- *
314
- * Advisory only — does not enforce a hard token limit.
315
- */
316
- taskBudget: z
317
- .object({
318
- type: z.literal('tokens'),
319
- total: z.number().int().min(20000),
320
- remaining: z.number().int().min(0).optional(),
321
- })
322
- .optional(),
306
+ /**
307
+ * Whether to enable fine-grained (eager) streaming of tool call inputs
308
+ * and structured outputs for every function tool in the request. When
309
+ * true (the default), each function tool receives a default of
310
+ * `eager_input_streaming: true` unless it explicitly sets
311
+ * `providerOptions.anthropic.eagerInputStreaming`.
312
+ *
313
+ * @default true
314
+ */
315
+ toolStreaming: z.boolean().optional(),
323
316
 
324
- /**
325
- * Enable fast mode for faster inference (2.5x faster output token speeds).
326
- * Only supported with claude-opus-4-6.
327
- */
328
- speed: z.enum(['fast', 'standard']).optional(),
317
+ /**
318
+ * Controls how much effort the model spends on thinking, text responses,
319
+ * and tool calls. On models that always use adaptive thinking
320
+ * (e.g. `claude-opus-5-5`), effort is the main lever for latency and cost.
321
+ *
322
+ * The API default is `high` for most models and `medium` for `claude-opus-5-5`.
323
+ */
324
+ effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
329
325
 
330
- /** Selects Anthropic's service tier for the request. */
331
- serviceTier: z.enum(['auto', 'standard_only']).optional(),
326
+ /**
327
+ * Task budget for agentic turns. Informs the model of the total token budget
328
+ * available for the current task, allowing it to prioritize work and wind down
329
+ * gracefully as the budget is consumed.
330
+ *
331
+ * Advisory only — does not enforce a hard token limit.
332
+ */
333
+ taskBudget: z
334
+ .object({
335
+ type: z.literal('tokens'),
336
+ total: z.number().int().min(20000),
337
+ remaining: z.number().int().min(0).optional(),
338
+ })
339
+ .optional(),
332
340
 
333
- /**
334
- * Controls where model inference runs for this request.
335
- *
336
- * - `"global"`: Inference may run in any available geography (default).
337
- * - `"us"`: Inference runs only in US-based infrastructure.
338
- *
339
- * See https://platform.claude.com/docs/en/build-with-claude/data-residency
340
- */
341
- inferenceGeo: z.enum(['us', 'global']).optional(),
341
+ /**
342
+ * Enable fast mode for faster inference (2.5x faster output token speeds).
343
+ * Only supported with claude-opus-4-6.
344
+ */
345
+ speed: z.enum(['fast', 'standard']).optional(),
342
346
 
343
- /**
344
- * Server-side fallback configuration.
345
- *
346
- * When the primary model's safety classifiers block a turn, the API
347
- * automatically retries it server-side on a fallback model. A
348
- * `content-filter` finish reason means the fallback(s) refused as well.
349
- *
350
- * - `'default'` (recommended): the API routes the retry to Anthropic's
351
- * recommended fallback model based on the refusal category. Requires the
352
- * `server-side-fallback-2026-07-01` beta, which is added automatically.
353
- * - Array form: an explicit fallback chain. Each entry is merged into the
354
- * request as a direct request to that entry's model, so it must be
355
- * formatted accordingly: `model` is required, and an entry may
356
- * additionally override `max_tokens`, `thinking`, `output_config`, and
357
- * `speed` for that attempt only (`speed` additionally requires the speed
358
- * beta). The value is passed through to the API as-is, and the
359
- * `server-side-fallback-2026-06-01` beta is added automatically.
360
- */
361
- fallbacks: z
362
- .union([
363
- z.literal('default'),
364
- z.array(
365
- z.object({
366
- model: z.string(),
367
- max_tokens: z.number().int().optional(),
368
- thinking: z.record(z.string(), z.unknown()).optional(),
369
- output_config: z.record(z.string(), z.unknown()).optional(),
370
- speed: z.enum(['fast', 'standard']).optional(),
371
- }),
372
- ),
373
- ])
374
- .optional(),
347
+ /** Selects Anthropic's service tier for the request. */
348
+ serviceTier: z.enum(['auto', 'standard_only']).optional(),
375
349
 
376
- /**
377
- * A set of beta features to enable.
378
- * Allow a provider to receive the full `betas` set if it needs it.
379
- */
380
- anthropicBeta: z.array(z.string()).optional(),
350
+ /**
351
+ * Controls where model inference runs for this request.
352
+ *
353
+ * - `"global"`: Inference may run in any available geography (default).
354
+ * - `"us"`: Inference runs only in US-based infrastructure.
355
+ *
356
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
357
+ */
358
+ inferenceGeo: z.enum(['us', 'global']).optional(),
381
359
 
382
- /**
383
- * Server-side safeguards to run as part of the request.
384
- *
385
- * `dangerous_tool_use` asks the API to classify every `tool_use` block in
386
- * the response for dangerous actions (the check Claude Code's auto mode
387
- * relies on). The per-call verdicts are returned in
388
- * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
389
- * `classifierContext` is passed through to the API as `classifier_context`.
390
- * The `dangerous-tool-use-2026-09-03` beta is added automatically.
391
- */
392
- safeguards: z
393
- .array(
394
- z.object({
395
- type: z.literal('dangerous_tool_use'),
396
- classifierContext: z.record(z.string(), z.unknown()).optional(),
397
- }),
398
- )
399
- .optional(),
360
+ /**
361
+ * Server-side fallback configuration.
362
+ *
363
+ * When the primary model's safety classifiers block a turn, the API
364
+ * automatically retries it server-side on a fallback model. A
365
+ * `content-filter` finish reason means the fallback(s) refused as well.
366
+ *
367
+ * - `'default'` (recommended): the API routes the retry to Anthropic's
368
+ * recommended fallback model based on the refusal category. Requires the
369
+ * `server-side-fallback-2026-07-01` beta, which is added automatically.
370
+ * - Array form: an explicit fallback chain. Each entry is merged into the
371
+ * request as a direct request to that entry's model, so it must be
372
+ * formatted accordingly: `model` is required, and an entry may
373
+ * additionally override `max_tokens`, `thinking`, `output_config`, and
374
+ * `speed` for that attempt only (`speed` additionally requires the speed
375
+ * beta). The value is passed through to the API as-is, and the
376
+ * `server-side-fallback-2026-06-01` beta is added automatically.
377
+ */
378
+ fallbacks: z
379
+ .union([
380
+ z.literal('default'),
381
+ z.array(
382
+ z.object({
383
+ model: z.string(),
384
+ max_tokens: z.number().int().optional(),
385
+ thinking: z.record(z.string(), z.unknown()).optional(),
386
+ output_config: z.record(z.string(), z.unknown()).optional(),
387
+ speed: z.enum(['fast', 'standard']).optional(),
388
+ }),
389
+ ),
390
+ ])
391
+ .optional(),
400
392
 
401
- /**
402
- * Requests an on-demand summary of the supplied conversation.
403
- *
404
- * The required `compact-2026-09-04` beta is added automatically.
405
- * Cannot be combined with `contextManagement`.
406
- */
407
- compaction: z
408
- .object({
409
- type: z.literal('summarize'),
410
- instructions: z.string().optional(),
411
- })
412
- .optional(),
393
+ /**
394
+ * A set of beta features to enable.
395
+ * Allow a provider to receive the full `betas` set if it needs it.
396
+ */
397
+ anthropicBeta: z.array(z.string()).optional(),
413
398
 
414
- contextManagement: z
415
- .object({
416
- edits: z.array(
417
- z.discriminatedUnion('type', [
418
- z.object({
419
- type: z.literal('clear_tool_uses_20250919'),
420
- trigger: z
421
- .discriminatedUnion('type', [
422
- z.object({
423
- type: z.literal('input_tokens'),
424
- value: z.number(),
425
- }),
426
- z.object({
427
- type: z.literal('tool_uses'),
428
- value: z.number(),
429
- }),
430
- ])
431
- .optional(),
432
- keep: z
433
- .object({
434
- type: z.literal('tool_uses'),
435
- value: z.number(),
436
- })
437
- .optional(),
438
- clearAtLeast: z
439
- .object({
440
- type: z.literal('input_tokens'),
441
- value: z.number(),
442
- })
443
- .optional(),
444
- clearToolInputs: z.boolean().optional(),
445
- excludeTools: z.array(z.string()).optional(),
446
- }),
447
- z.object({
448
- type: z.literal('clear_thinking_20251015'),
449
- keep: z
450
- .union([
451
- z.literal('all'),
452
- z.object({
453
- type: z.literal('thinking_turns'),
454
- value: z.number(),
455
- }),
456
- ])
457
- .optional(),
458
- }),
399
+ /**
400
+ * Server-side safeguards to run as part of the request.
401
+ *
402
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
403
+ * the response for dangerous actions (the check Claude Code's auto mode
404
+ * relies on). The per-call verdicts are returned in
405
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
406
+ * `classifierContext` is passed through to the API as `classifier_context`.
407
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
408
+ */
409
+ safeguards: z
410
+ .array(
459
411
  z.object({
460
- type: z.literal('compact_20260112'),
461
- trigger: z
462
- .object({
463
- type: z.literal('input_tokens'),
464
- value: z.number(),
465
- })
466
- .optional(),
467
- pauseAfterCompaction: z.boolean().optional(),
468
- instructions: z.string().optional(),
412
+ type: z.literal('dangerous_tool_use'),
413
+ classifierContext: z.record(z.string(), z.unknown()).optional(),
469
414
  }),
470
- ]),
471
- ),
472
- })
473
- .optional(),
474
- });
415
+ )
416
+ .optional(),
417
+
418
+ /**
419
+ * Requests an on-demand summary of the supplied conversation.
420
+ *
421
+ * The required `compact-2026-09-04` beta is added automatically.
422
+ * Cannot be combined with `contextManagement`.
423
+ */
424
+ compaction: z
425
+ .object({
426
+ type: z.literal('summarize'),
427
+ instructions: z.string().optional(),
428
+ })
429
+ .optional(),
430
+
431
+ contextManagement: z
432
+ .object({
433
+ edits: z.array(
434
+ z.discriminatedUnion('type', [
435
+ z.object({
436
+ type: z.literal('clear_tool_uses_20250919'),
437
+ trigger: z
438
+ .discriminatedUnion('type', [
439
+ z.object({
440
+ type: z.literal('input_tokens'),
441
+ value: z.number(),
442
+ }),
443
+ z.object({
444
+ type: z.literal('tool_uses'),
445
+ value: z.number(),
446
+ }),
447
+ ])
448
+ .optional(),
449
+ keep: z
450
+ .object({
451
+ type: z.literal('tool_uses'),
452
+ value: z.number(),
453
+ })
454
+ .optional(),
455
+ clearAtLeast: z
456
+ .object({
457
+ type: z.literal('input_tokens'),
458
+ value: z.number(),
459
+ })
460
+ .optional(),
461
+ clearToolInputs: z.boolean().optional(),
462
+ excludeTools: z.array(z.string()).optional(),
463
+ }),
464
+ z.object({
465
+ type: z.literal('clear_thinking_20251015'),
466
+ keep: z
467
+ .union([
468
+ z.literal('all'),
469
+ z.object({
470
+ type: z.literal('thinking_turns'),
471
+ value: z.number(),
472
+ }),
473
+ ])
474
+ .optional(),
475
+ }),
476
+ z.object({
477
+ type: z.literal('compact_20260112'),
478
+ trigger: z
479
+ .object({
480
+ type: z.literal('input_tokens'),
481
+ value: z.number(),
482
+ })
483
+ .optional(),
484
+ pauseAfterCompaction: z.boolean().optional(),
485
+ instructions: z.string().optional(),
486
+ }),
487
+ ]),
488
+ ),
489
+ })
490
+ .optional(),
491
+ }),
492
+ ),
493
+ );
475
494
 
476
- export type AnthropicLanguageModelOptions = z.infer<
495
+ export type AnthropicLanguageModelOptions = InferSchema<
477
496
  typeof anthropicLanguageModelOptions
478
497
  >;