@ai-sdk/anthropic 3.0.60 → 3.0.62

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.
@@ -220,17 +220,58 @@ The `speed` option accepts `'fast'` or `'standard'` (default behavior).
220
220
 
221
221
  ### Reasoning
222
222
 
223
- Anthropic has reasoning support for `claude-opus-4-20250514`, `claude-sonnet-4-20250514`, and `claude-sonnet-4-5-20250929` models.
223
+ Anthropic models support extended thinking, where Claude shows its reasoning process before providing a final answer.
224
224
 
225
- You can enable it using the `thinking` provider option
226
- and specifying a thinking budget in tokens.
225
+ #### Adaptive Thinking
226
+
227
+ For newer models (`claude-sonnet-4-6`, `claude-opus-4-6`, and later), use adaptive thinking.
228
+ Claude automatically determines how much reasoning to use based on the complexity of the prompt.
227
229
 
228
230
  ```ts highlight="4,8-10"
229
231
  import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
230
232
  import { generateText } from 'ai';
231
233
 
232
234
  const { text, reasoningText, reasoning } = await generateText({
233
- model: anthropic('claude-opus-4-20250514'),
235
+ model: anthropic('claude-opus-4-6'),
236
+ prompt: 'How many people will live in the world in 2040?',
237
+ providerOptions: {
238
+ anthropic: {
239
+ thinking: { type: 'adaptive' },
240
+ } satisfies AnthropicLanguageModelOptions,
241
+ },
242
+ });
243
+
244
+ console.log(reasoningText); // reasoning text
245
+ console.log(reasoning); // reasoning details including redacted reasoning
246
+ console.log(text); // text response
247
+ ```
248
+
249
+ You can combine adaptive thinking with the `effort` option to control how much reasoning Claude uses:
250
+
251
+ ```ts highlight="6-8"
252
+ const { text } = await generateText({
253
+ model: anthropic('claude-opus-4-6'),
254
+ prompt: 'Invent a new holiday and describe its traditions.',
255
+ providerOptions: {
256
+ anthropic: {
257
+ thinking: { type: 'adaptive' },
258
+ effort: 'max', // 'low' | 'medium' | 'high' | 'max'
259
+ } satisfies AnthropicLanguageModelOptions,
260
+ },
261
+ });
262
+ ```
263
+
264
+ #### Budget-Based Thinking
265
+
266
+ For earlier models (`claude-opus-4-20250514`, `claude-sonnet-4-20250514`, `claude-sonnet-4-5-20250929`),
267
+ use `type: 'enabled'` with an explicit token budget:
268
+
269
+ ```ts highlight="4,8-10"
270
+ import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
271
+ import { generateText } from 'ai';
272
+
273
+ const { text, reasoningText, reasoning } = await generateText({
274
+ model: anthropic('claude-sonnet-4-5-20250929'),
234
275
  prompt: 'How many people will live in the world in 2040?',
235
276
  providerOptions: {
236
277
  anthropic: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.60",
3
+ "version": "3.0.62",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -129,6 +129,12 @@ type AnthropicMessagesConfig = {
129
129
  * When false, the model will use JSON tool fallback for structured outputs.
130
130
  */
131
131
  supportsNativeStructuredOutput?: boolean;
132
+
133
+ /**
134
+ * When false, `strict` on tool definitions will be ignored and a warning emitted.
135
+ * Defaults to true.
136
+ */
137
+ supportsStrictTools?: boolean;
132
138
  };
133
139
 
134
140
  export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
@@ -270,6 +276,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
270
276
  (this.config.supportsNativeStructuredOutput ?? true) &&
271
277
  modelSupportsStructuredOutput;
272
278
 
279
+ const supportsStrictTools =
280
+ (this.config.supportsStrictTools ?? true) &&
281
+ modelSupportsStructuredOutput;
282
+
273
283
  const structureOutputMode =
274
284
  anthropicOptions?.structuredOutputMode ?? 'auto';
275
285
  const useStructuredOutput =
@@ -614,6 +624,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
614
624
  disableParallelToolUse: true,
615
625
  cacheControlValidator,
616
626
  supportsStructuredOutput: false,
627
+ supportsStrictTools,
617
628
  }
618
629
  : {
619
630
  tools: tools ?? [],
@@ -621,6 +632,7 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
621
632
  disableParallelToolUse: anthropicOptions?.disableParallelToolUse,
622
633
  cacheControlValidator,
623
634
  supportsStructuredOutput,
635
+ supportsStrictTools,
624
636
  },
625
637
  );
626
638
 
@@ -26,6 +26,7 @@ export async function prepareTools({
26
26
  disableParallelToolUse,
27
27
  cacheControlValidator,
28
28
  supportsStructuredOutput,
29
+ supportsStrictTools,
29
30
  }: {
30
31
  tools: LanguageModelV3CallOptions['tools'];
31
32
  toolChoice: LanguageModelV3CallOptions['toolChoice'] | undefined;
@@ -33,9 +34,14 @@ export async function prepareTools({
33
34
  cacheControlValidator?: CacheControlValidator;
34
35
 
35
36
  /**
36
- * Whether the model supports structured output.
37
+ * Whether the model supports native structured output response format.
37
38
  */
38
39
  supportsStructuredOutput: boolean;
40
+
41
+ /**
42
+ * Whether the model supports strict mode on tool definitions.
43
+ */
44
+ supportsStrictTools: boolean;
39
45
  }): Promise<{
40
46
  tools: Array<AnthropicTool> | undefined;
41
47
  toolChoice: AnthropicToolChoice | undefined;
@@ -72,13 +78,21 @@ export async function prepareTools({
72
78
  const deferLoading = anthropicOptions?.deferLoading;
73
79
  const allowedCallers = anthropicOptions?.allowedCallers;
74
80
 
81
+ if (!supportsStrictTools && tool.strict != null) {
82
+ toolWarnings.push({
83
+ type: 'unsupported',
84
+ feature: 'strict',
85
+ details: `Tool '${tool.name}' has strict: ${tool.strict}, but strict mode is not supported by this provider. The strict property will be ignored.`,
86
+ });
87
+ }
88
+
75
89
  anthropicTools.push({
76
90
  name: tool.name,
77
91
  description: tool.description,
78
92
  input_schema: tool.inputSchema,
79
93
  cache_control: cacheControl,
80
94
  ...(eagerInputStreaming ? { eager_input_streaming: true } : {}),
81
- ...(supportsStructuredOutput === true && tool.strict != null
95
+ ...(supportsStrictTools === true && tool.strict != null
82
96
  ? { strict: tool.strict }
83
97
  : {}),
84
98
  ...(deferLoading != null ? { defer_loading: deferLoading } : {}),
@@ -308,7 +322,6 @@ export async function prepareTools({
308
322
  }
309
323
 
310
324
  case 'anthropic.tool_search_regex_20251119': {
311
- betas.add('advanced-tool-use-2025-11-20');
312
325
  anthropicTools.push({
313
326
  type: 'tool_search_tool_regex_20251119',
314
327
  name: 'tool_search_tool_regex',
@@ -317,7 +330,6 @@ export async function prepareTools({
317
330
  }
318
331
 
319
332
  case 'anthropic.tool_search_bm25_20251119': {
320
- betas.add('advanced-tool-use-2025-11-20');
321
333
  anthropicTools.push({
322
334
  type: 'tool_search_tool_bm25_20251119',
323
335
  name: 'tool_search_tool_bm25',