@ai-sdk/anthropic 4.0.58 → 4.0.60

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.
@@ -197,17 +197,27 @@ const result = streamText({
197
197
  });
198
198
  ```
199
199
 
200
- For `claude-fable-5-1`, the default `"auto"` mode uses native structured
201
- outputs through `output_config.format`. Fable 5.1 rejects forced tool use, so
202
- do not use `"jsonTool"` or a required or named tool choice to implement
203
- structured output with this model.
200
+ For `claude-opus-5-5` and `claude-fable-5-1`, the default `"auto"` mode uses
201
+ native structured outputs through `output_config.format`. These models reject
202
+ forced tool use, so the `"jsonTool"` mode cannot be used with them. If you
203
+ request `"jsonTool"` anyway, the provider falls back to `"outputFormat"` and
204
+ emits a warning. Likewise, a `required` or named `toolChoice` is downgraded to
205
+ `auto` with a warning; instruct the model to use the tool in your prompt and
206
+ verify that a tool call was made.
204
207
 
205
208
  ### Effort
206
209
 
207
- Anthropic introduced an `effort` option with `claude-opus-4-5` that affects thinking, text responses, and function calls. Effort defaults to `high` and you can set it to `medium` or `low` to save tokens and to lower time-to-last-token latency (TTLT). `claude-opus-4-7`, `claude-opus-4-8`, `claude-opus-5`, `claude-fable-5`, `claude-fable-5-1`, and `claude-sonnet-5` additionally support `xhigh` for maximum reasoning effort.
210
+ Anthropic introduced an `effort` option with `claude-opus-4-5` that affects thinking, text responses, and function calls. Effort defaults to `high` and you can set it to `medium` or `low` to save tokens and to lower time-to-last-token latency (TTLT). `claude-opus-4-7`, `claude-opus-4-8`, `claude-opus-5`, `claude-opus-5-5`, `claude-fable-5`, `claude-fable-5-1`, and `claude-sonnet-5` additionally support `xhigh` for maximum reasoning effort.
208
211
 
209
212
  On `claude-opus-5`, thinking can only be disabled at effort levels up to and including `high`. When you combine `thinking: { type: 'disabled' }` with `effort: 'xhigh'` or `effort: 'max'`, the AI SDK lowers the effort to `high` and emits a warning instead of sending a request that the API would reject.
210
213
 
214
+ On `claude-opus-5-5`, thinking is always adaptive and cannot be disabled, so
215
+ `effort` is the main control for latency and cost. The API default effort for
216
+ `claude-opus-5-5` is `medium`. Start there and test other levels rather than
217
+ carrying over the setting you used on `claude-opus-5`. Set `maxOutputTokens`
218
+ with room for thinking as well as the reply; thinking counts toward the limit
219
+ even when its content is not returned.
220
+
211
221
  ```ts highlight="8-10"
212
222
  import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
213
223
  import { generateText } from 'ai';
@@ -385,6 +395,57 @@ const servedByFallback = iterations?.some(
385
395
  console.log('Served by fallback:', servedByFallback);
386
396
  ```
387
397
 
398
+ ### Dangerous Tool Use Safeguard
399
+
400
+ The `safeguards` option asks the API to run additional server-side checks as part of the request. The `dangerous_tool_use` safeguard classifies every `tool_use` block in the response for dangerous actions, such as destructive shell commands or data exfiltration, and returns a verdict per tool call. This is the check that Claude Code's auto mode relies on. The `dangerous-tool-use-2026-09-03` beta header is added for you.
401
+
402
+ ```ts highlight="9-16"
403
+ import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
404
+ import { generateText, tool } from 'ai';
405
+ import { z } from 'zod';
406
+
407
+ const result = await generateText({
408
+ model: anthropic('claude-sonnet-4-5'),
409
+ prompt: 'Use the bash tool to run: echo hello',
410
+ tools: { bash: tool({ inputSchema: z.object({ command: z.string() }) }) },
411
+ providerOptions: {
412
+ anthropic: {
413
+ safeguards: [
414
+ {
415
+ type: 'dangerous_tool_use',
416
+ classifierContext: { v: 1, permission_mode: 'auto' },
417
+ },
418
+ ],
419
+ } satisfies AnthropicLanguageModelOptions,
420
+ },
421
+ });
422
+
423
+ console.log(result.providerMetadata?.anthropic?.safeguardResults);
424
+ ```
425
+
426
+ The verdicts are available on `providerMetadata.anthropic.safeguardResults`, one entry per requested safeguard, in the API's wire shape:
427
+
428
+ ```json
429
+ [
430
+ {
431
+ "type": "dangerous_tool_use",
432
+ "status": {
433
+ "type": "available",
434
+ "tool_uses": {
435
+ "toolu_01Ti4QpUfhLV6QqCTFVY8C7w": {
436
+ "type": "evaluated",
437
+ "outcome": "not_flagged"
438
+ }
439
+ }
440
+ }
441
+ }
442
+ ]
443
+ ```
444
+
445
+ `status.type` is `available` when the classifier ran; `unsupported` means the API key is not enabled for the beta. Inside `status.tool_uses`, each tool call id maps to `evaluated` (with an `outcome` of `not_flagged` or `flagged`, the latter with an `explanation` such as `[Data Exfiltration]`), `skipped`, or `unavailable` (a transient classifier failure). When streaming, the verdicts arrive on the final `message_delta` event and are exposed on the `finish` part's provider metadata.
446
+
447
+ Anthropic's platform reference does not document the beta yet; the feature is described from the client side in the Claude Code [auto mode classifier](https://code.claude.com/docs/en/auto-mode-classifier-billing) and [gateway compatibility](https://code.claude.com/docs/en/llm-gateway-protocol#feature-pass-through) guides.
448
+
388
449
  ### Reasoning
389
450
 
390
451
  Anthropic models support extended thinking, where Claude shows its reasoning process before providing a final answer.
@@ -428,6 +489,41 @@ const { text } = await generateText({
428
489
  });
429
490
  ```
430
491
 
492
+ ##### Adaptive-Only Models
493
+
494
+ `claude-opus-5-5`, `claude-fable-5`, and `claude-fable-5-1` always run adaptive
495
+ thinking. The API rejects `thinking: { type: 'disabled' }` and budget-based
496
+ `thinking: { type: 'enabled' }` for these models. To keep existing code working,
497
+ the provider:
498
+
499
+ - removes `thinking: { type: 'disabled' }` and emits a warning,
500
+ - converts `thinking: { type: 'enabled', budgetTokens }` to `{ type: 'adaptive' }` and emits a warning,
501
+ - maps the top-level `reasoning: 'none'` option to `effort: 'low'` and emits a warning.
502
+
503
+ Use `effort` to control how much these models think. On `claude-opus-5-5`, set
504
+ `effort: 'low'` when time to first token matters, and move to `medium` if
505
+ quality drops:
506
+
507
+ ```ts highlight="6-9"
508
+ const { text } = await generateText({
509
+ model: anthropic('claude-opus-5-5'),
510
+ prompt: 'Summarize this ticket in one sentence.',
511
+ providerOptions: {
512
+ anthropic: {
513
+ // thinking stays adaptive; effort controls how much the model thinks
514
+ effort: 'low',
515
+ } satisfies AnthropicLanguageModelOptions,
516
+ },
517
+ });
518
+ ```
519
+
520
+ <Note>
521
+ Responses from adaptive-only models can begin with a thinking block. Read the
522
+ response by content type (`text`, `reasoning`, `tool-call`) rather than
523
+ assuming the first part is text. Under the default `display: 'omitted'`
524
+ setting, thinking blocks are returned with empty text.
525
+ </Note>
526
+
431
527
  ##### Thinking Display (Opus 4.7+)
432
528
 
433
529
  Starting with `claude-opus-4-7`, thinking content is omitted from the response by default — thinking blocks are present in the stream but their text is empty. To receive reasoning output, set `display: 'summarized'`:
@@ -455,8 +551,10 @@ console.log(text);
455
551
 
456
552
  ##### Thinking Updates
457
553
 
458
- Use `display: 'updates'` with `claude-fable-5-1` to stream thinking summaries
459
- between tool calls. The provider adds the required
554
+ Use `display: 'updates'` with `claude-opus-5-5` or `claude-fable-5-1` to stream
555
+ thinking summaries between tool calls. These models return progress notes
556
+ between tool calls as thinking blocks rather than text, so without this setting
557
+ a long tool-calling turn can look silent. The provider adds the required
460
558
  `thinking-display-updates-2026-08-18` beta header automatically:
461
559
 
462
560
  ```ts highlight="12-16"
@@ -1026,11 +1124,74 @@ const computerTool = anthropic.tools.computer_20251124({
1026
1124
  ```
1027
1125
 
1028
1126
  <Note>
1029
- Use `computer_20251124` for Claude Opus 4.5 which supports the zoom action.
1030
- Use `computer_20250124` for Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4,
1031
- Opus 4, and Sonnet 3.7.
1127
+ Use `computerToolset_20260801` for Claude Opus 5.5 (required), Opus 5, Sonnet
1128
+ 5, Fable 5, Fable 5.1, and Opus 4.8. Use `computer_20251124` for Claude Opus
1129
+ 4.5 through Opus 4.7, which support the zoom action. Use `computer_20250124`
1130
+ for Claude Sonnet 4.5, Haiku 4.5, Opus 4.1, Sonnet 4, Opus 4, and Sonnet 3.7.
1032
1131
  </Note>
1033
1132
 
1133
+ #### Computer Toolset
1134
+
1135
+ Newer models use the computer toolset instead of a versioned computer tool.
1136
+ `claude-opus-5-5` accepts computer use only through the toolset and rejects the
1137
+ older `computer_*` tool types with a 400. The toolset does not require a beta
1138
+ header and has no display size parameters: coordinates are always in the pixel
1139
+ space of the screenshots you return. Zoom is enabled by default, and Claude can
1140
+ return several actions in one turn, each as its own tool call.
1141
+
1142
+ The API returns each action as a separate `tool_use` block with
1143
+ `toolset_name: 'computer'`. The AI SDK maps every action to the toolset tool and
1144
+ passes the action name as `action`, so `execute` receives the same input shape
1145
+ as the older computer tools:
1146
+
1147
+ ```ts
1148
+ const computerTool = anthropic.tools.computerToolset_20260801({
1149
+ // optional: turn individual actions on or off
1150
+ configs: {
1151
+ zoom: { enabled: false },
1152
+ },
1153
+
1154
+ execute: async ({ action, coordinate, text, region }) => {
1155
+ switch (action) {
1156
+ case 'screenshot': {
1157
+ return {
1158
+ type: 'image',
1159
+ data: fs.readFileSync('./data/screenshot.png').toString('base64'),
1160
+ };
1161
+ }
1162
+ default: {
1163
+ console.log('Action:', action, coordinate, text, region);
1164
+ return `executed ${action}`;
1165
+ }
1166
+ }
1167
+ },
1168
+
1169
+ toModelOutput({ output }) {
1170
+ return typeof output === 'string'
1171
+ ? [{ type: 'text', text: output }]
1172
+ : [{ type: 'file-data', data: output.data, mediaType: 'image/png' }];
1173
+ },
1174
+ });
1175
+ ```
1176
+
1177
+ Parameters:
1178
+
1179
+ - `action` ('screenshot' | 'zoom' | 'left_click' | 'right_click' | 'middle_click' | 'double_click' | 'triple_click' | 'left_click_drag' | 'mouse_move' | 'left_mouse_down' | 'left_mouse_up' | 'cursor_position' | 'scroll' | 'type' | 'key' | 'hold_key' | 'wait'): The member tool that Claude invoked.
1180
+ - `coordinate` (number[], optional): The (x, y) pixel coordinates for click, move, and scroll actions.
1181
+ - `start_coordinate` (number[], optional): Where a `left_click_drag` starts.
1182
+ - `region` (number[], optional): `[x1, y1, x2, y2]` for the `zoom` action.
1183
+ - `text` (string, optional): Text to type, the key combination for `key` and `hold_key`, or modifier keys to hold during click and scroll actions.
1184
+ - `repeat` (number, optional): How many times to press the key for `key`.
1185
+ - `duration` (number, optional): Seconds for `hold_key` and `wait`.
1186
+ - `scroll_direction` ('up' | 'down' | 'left' | 'right', optional) and `scroll_amount` (number, optional): For the `scroll` action.
1187
+ - `configs` (object, optional): Per-action settings keyed by action name. Each entry accepts `enabled` (default `true`) and `deferLoading` (default `false`, for tool search).
1188
+
1189
+ Tool calls and results of the toolset are serialized with `toolset_name` when
1190
+ you pass the message history back. Keep the toolset tool in `tools` on
1191
+ follow-up requests, or the provider falls back to the `toolsetName` provider
1192
+ metadata on the tool calls of previous responses. Do not declare the toolset
1193
+ together with an older `computer_*` tool.
1194
+
1034
1195
  Parameters:
1035
1196
 
1036
1197
  - `action` ('key' | 'type' | 'mouse_move' | 'left_click' | 'left_click_drag' | 'right_click' | 'middle_click' | 'double_click' | 'screenshot' | 'cursor_position' | 'zoom'): The action to perform. The `zoom` action is only available with `computer_20251124`.
@@ -1329,11 +1490,11 @@ This sends `tool_reference` blocks to Anthropic, which loads the corresponding d
1329
1490
 
1330
1491
  ### Mid-Conversation System Controls
1331
1492
 
1332
- With `claude-fable-5-1`, a mid-conversation system message can be cleared
1333
- before the next user message with `clearAt: 'next_user_message'`, or set the
1334
- effort for the next turn. The provider adds the required
1493
+ With `claude-opus-5-5` and `claude-fable-5-1`, a mid-conversation system message
1494
+ can be cleared before the next user message with `clearAt: 'next_user_message'`,
1495
+ or set the effort for the next turn without invalidating the prompt cache. The provider adds the required
1335
1496
  `mid-conversation-system-clear-at-2026-08-21` and
1336
- `mid-conversation-effort-2026-08-01` beta headers automatically.
1497
+ `mid-conversation-output-config-2026-07-01` beta headers automatically.
1337
1498
 
1338
1499
  ```ts highlight="17-25"
1339
1500
  import { anthropic } from '@ai-sdk/anthropic';
@@ -1872,6 +2033,7 @@ and the `mediaType` should be set to `'application/pdf'`.
1872
2033
 
1873
2034
  | Model | Image Input | Object Generation | Tool Usage | Computer Use | Web Search | Tool Search | Compaction |
1874
2035
  | ------------------- | ----------- | ----------------- | ---------- | ------------ | ---------- | ----------- | ---------- |
2036
+ | `claude-opus-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
1875
2037
  | `claude-opus-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
1876
2038
  | `claude-sonnet-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
1877
2039
  | `claude-fable-5-1` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "4.0.58",
3
+ "version": "4.0.60",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -173,6 +173,11 @@ export interface AnthropicToolCallContent {
173
173
  * (e.g., code execution calling a user-defined tool programmatically).
174
174
  */
175
175
  caller?: AnthropicToolCallCaller;
176
+ /**
177
+ * Present when this tool call is a member call of a toolset
178
+ * (e.g. `computer` for the computer toolset). `name` is then the member name.
179
+ */
180
+ toolset_name?: string;
176
181
  cache_control: AnthropicCacheControl | undefined;
177
182
  }
178
183
 
@@ -228,6 +233,10 @@ export interface AnthropicToolReferenceContent {
228
233
  export interface AnthropicToolResultContent {
229
234
  type: 'tool_result';
230
235
  tool_use_id: string;
236
+ /**
237
+ * Required for results of toolset member calls (e.g. `computer`).
238
+ */
239
+ toolset_name?: string;
231
240
  content:
232
241
  | string
233
242
  | Array<
@@ -484,6 +493,15 @@ export type AnthropicTool =
484
493
  enable_zoom?: boolean;
485
494
  cache_control: AnthropicCacheControl | undefined;
486
495
  }
496
+ | {
497
+ /**
498
+ * Computer toolset. Declared without a `name`; the API returns member
499
+ * tool calls (e.g. `left_click`) with `toolset_name: 'computer'`.
500
+ */
501
+ type: 'computer_toolset_20260801';
502
+ configs?: Record<string, { enabled?: boolean; defer_loading?: boolean }>;
503
+ cache_control: AnthropicCacheControl | undefined;
504
+ }
487
505
  | {
488
506
  name: string;
489
507
  type:
@@ -657,6 +675,27 @@ const anthropicStopDetailsSchema = z.object({
657
675
 
658
676
  export type AnthropicStopDetails = z.infer<typeof anthropicStopDetailsSchema>;
659
677
 
678
+ const anthropicSafeguardResultSchema = z.object({
679
+ type: z.string(),
680
+ status: z.object({
681
+ type: z.string(),
682
+ tool_uses: z
683
+ .record(
684
+ z.string(),
685
+ z.object({
686
+ type: z.string(),
687
+ outcome: z.string().nullish(),
688
+ explanation: z.string().nullish(),
689
+ }),
690
+ )
691
+ .nullish(),
692
+ }),
693
+ });
694
+
695
+ export type AnthropicSafeguardResult = z.infer<
696
+ typeof anthropicSafeguardResultSchema
697
+ >;
698
+
660
699
  const anthropicToolCallCallerSchema = z.union([
661
700
  z.object({
662
701
  type: z.literal('code_execution_20250825'),
@@ -774,6 +813,8 @@ export const anthropicResponseSchema = lazySchema(() =>
774
813
  input: z.unknown(),
775
814
  // Programmatic tool calling: caller info when triggered from code execution
776
815
  caller: anthropicToolCallCallerSchema.optional(),
816
+ // Toolsets (e.g. computer toolset): name of the toolset this member call belongs to
817
+ toolset_name: z.string().nullish(),
777
818
  }),
778
819
  z.object({
779
820
  type: z.literal('server_tool_use'),
@@ -1004,6 +1045,7 @@ export const anthropicResponseSchema = lazySchema(() =>
1004
1045
  input_transformations: z
1005
1046
  .array(anthropicInputTransformationSchema)
1006
1047
  .nullish(),
1048
+ safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
1007
1049
  usage: z.looseObject({
1008
1050
  input_tokens: z.number(),
1009
1051
  output_tokens: z.number(),
@@ -1098,6 +1140,7 @@ export const anthropicChunkSchema = lazySchema(() =>
1098
1140
  name: z.string(),
1099
1141
  input: z.unknown(),
1100
1142
  caller: anthropicToolCallCallerSchema.optional(),
1143
+ toolset_name: z.string().nullish(),
1101
1144
  }),
1102
1145
  ]),
1103
1146
  )
@@ -1134,6 +1177,8 @@ export const anthropicChunkSchema = lazySchema(() =>
1134
1177
  input: z.record(z.string(), z.unknown()).optional(),
1135
1178
  // Programmatic tool calling: caller info when triggered from code execution
1136
1179
  caller: anthropicToolCallCallerSchema.optional(),
1180
+ // Toolsets (e.g. computer toolset): name of the toolset this member call belongs to
1181
+ toolset_name: z.string().nullish(),
1137
1182
  }),
1138
1183
  z.object({
1139
1184
  type: z.literal('redacted_thinking'),
@@ -1412,6 +1457,7 @@ export const anthropicChunkSchema = lazySchema(() =>
1412
1457
  stop_reason: z.string().nullish(),
1413
1458
  stop_sequence: z.string().nullish(),
1414
1459
  stop_details: anthropicStopDetailsSchema.nullish(),
1460
+ safeguard_results: z.array(anthropicSafeguardResultSchema).nullish(),
1415
1461
  container: z
1416
1462
  .object({
1417
1463
  expires_at: z.string(),
@@ -1098,6 +1098,9 @@ function convertAnthropicMessageMetadata(response: AnthropicResponse) {
1098
1098
  ...(response.input_transformations != null
1099
1099
  ? { inputTransformations: response.input_transformations }
1100
1100
  : {}),
1101
+ ...(response.safeguard_results != null
1102
+ ? { safeguardResults: response.safeguard_results }
1103
+ : {}),
1101
1104
  iterations: response.usage.iterations
1102
1105
  ? response.usage.iterations.map(
1103
1106
  iteration =>
@@ -20,6 +20,7 @@ export type AnthropicModelId =
20
20
  | 'claude-opus-4-7'
21
21
  | 'claude-opus-4-8'
22
22
  | 'claude-opus-5'
23
+ | 'claude-opus-5-5'
23
24
  | 'claude-fable-5'
24
25
  | 'claude-fable-5-1'
25
26
  | 'claude-sonnet-5'
@@ -82,8 +83,8 @@ export const anthropicSystemMessageProviderOptions = z.object({
82
83
 
83
84
  /**
84
85
  * Sets the model effort for the turn that follows this mid-conversation
85
- * system message. The required `mid-conversation-effort-2026-08-01` beta
86
- * is added automatically.
86
+ * system message. The required `mid-conversation-output-config-2026-07-01`
87
+ * beta is added automatically.
87
88
  */
88
89
  effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
89
90
 
@@ -143,6 +144,11 @@ export const anthropicLanguageModelOptions = z.object({
143
144
  *
144
145
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
145
146
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
147
+ *
148
+ * Models that always use adaptive thinking (e.g. `claude-opus-5-5`,
149
+ * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
150
+ * provider drops the unsupported setting, emits a warning, and sends an
151
+ * adaptive thinking request. Use `effort` to control how much they think.
146
152
  */
147
153
  thinking: z
148
154
  .union([
@@ -278,7 +284,11 @@ export const anthropicLanguageModelOptions = z.object({
278
284
  toolStreaming: z.boolean().optional(),
279
285
 
280
286
  /**
281
- * @default 'high'
287
+ * Controls how much effort the model spends on thinking, text responses,
288
+ * and tool calls. On models that always use adaptive thinking
289
+ * (e.g. `claude-opus-5-5`), effort is the main lever for latency and cost.
290
+ *
291
+ * The API default is `high` for most models and `medium` for `claude-opus-5-5`.
282
292
  */
283
293
  effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
284
294
 
@@ -355,6 +365,25 @@ export const anthropicLanguageModelOptions = z.object({
355
365
  */
356
366
  anthropicBeta: z.array(z.string()).optional(),
357
367
 
368
+ /**
369
+ * Server-side safeguards to run as part of the request.
370
+ *
371
+ * `dangerous_tool_use` asks the API to classify every `tool_use` block in
372
+ * the response for dangerous actions (the check Claude Code's auto mode
373
+ * relies on). The per-call verdicts are returned in
374
+ * `providerMetadata.anthropic.safeguardResults`, keyed by tool call id.
375
+ * `classifierContext` is passed through to the API as `classifier_context`.
376
+ * The `dangerous-tool-use-2026-09-03` beta is added automatically.
377
+ */
378
+ safeguards: z
379
+ .array(
380
+ z.object({
381
+ type: z.literal('dangerous_tool_use'),
382
+ classifierContext: z.record(z.string(), z.unknown()).optional(),
383
+ }),
384
+ )
385
+ .optional(),
386
+
358
387
  contextManagement: z
359
388
  .object({
360
389
  edits: z.array(