@ai-sdk/anthropic 3.0.68 → 3.0.70

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.
@@ -122,14 +122,22 @@ The following optional provider options are available for Anthropic models:
122
122
  If you are experiencing issues with the model handling requests involving
123
123
  reasoning content, you can set this to `false` to omit them from the request.
124
124
 
125
- - `effort` _"high" | "medium" | "low"_
125
+ - `effort` _"low" | "medium" | "high" | "xhigh" | "max"_
126
126
 
127
127
  Optional. See [Effort section](#effort) for more details.
128
128
 
129
+ - `taskBudget` _object_
130
+
131
+ Optional. See [Task Budgets section](#task-budgets) for more details.
132
+
129
133
  - `speed` _"fast" | "standard"_
130
134
 
131
135
  Optional. See [Fast Mode section](#fast-mode) for more details.
132
136
 
137
+ - `inferenceGeo` _"us" | "global"_
138
+
139
+ Optional. See [Data Residency section](#data-residency) for more details.
140
+
133
141
  - `thinking` _object_
134
142
 
135
143
  Optional. See [Reasoning section](#reasoning) for more details.
@@ -183,7 +191,7 @@ const result = streamText({
183
191
 
184
192
  ### Effort
185
193
 
186
- 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).
194
+ 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` additionally supports `xhigh` for maximum reasoning effort.
187
195
 
188
196
  ```ts highlight="8-10"
189
197
  import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
@@ -224,6 +232,67 @@ const { text } = await generateText({
224
232
 
225
233
  The `speed` option accepts `'fast'` or `'standard'` (default behavior).
226
234
 
235
+ ### Task Budgets
236
+
237
+ `claude-opus-4-7` supports a `taskBudget` option that informs the model of the total token budget available for an agentic turn. The model uses this information to prioritize work, plan ahead, and wind down gracefully as the budget is consumed.
238
+
239
+ Task budgets are advisory — they do not enforce a hard token limit. The model will attempt to stay within budget, but actual usage may vary.
240
+
241
+ ```ts highlight="8-13"
242
+ import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
243
+ import { generateText } from 'ai';
244
+
245
+ const { text } = await generateText({
246
+ model: anthropic('claude-opus-4-7'),
247
+ prompt: 'Research the pros and cons of Rust vs Go for building CLI tools.',
248
+ providerOptions: {
249
+ anthropic: {
250
+ taskBudget: {
251
+ type: 'tokens',
252
+ total: 400000,
253
+ },
254
+ } satisfies AnthropicLanguageModelOptions,
255
+ },
256
+ });
257
+ ```
258
+
259
+ For long-running agents that compact and restart context, you can carry the remaining budget forward using the `remaining` field:
260
+
261
+ ```ts
262
+ taskBudget: {
263
+ type: 'tokens',
264
+ total: 400000,
265
+ remaining: 215000, // budget left after prior compacted-away contexts
266
+ }
267
+ ```
268
+
269
+ The `taskBudget` object accepts:
270
+
271
+ - `type` _"tokens"_ - Budget type. Currently only `"tokens"` is supported.
272
+ - `total` _number_ - Total task budget for the agentic turn. Minimum 20,000.
273
+ - `remaining` _number_ - Budget left after prior compacted-away contexts. Must be between 0 and `total`. Defaults to `total` if omitted.
274
+
275
+ ### Data Residency
276
+
277
+ Anthropic supports an [`inferenceGeo` option](https://platform.claude.com/docs/en/build-with-claude/data-residency) that controls where model inference runs for a request.
278
+
279
+ ```ts highlight="8-10"
280
+ import { anthropic, AnthropicLanguageModelOptions } from '@ai-sdk/anthropic';
281
+ import { generateText } from 'ai';
282
+
283
+ const { text } = await generateText({
284
+ model: anthropic('claude-opus-4-6'),
285
+ prompt: 'Summarize the key points of this document.',
286
+ providerOptions: {
287
+ anthropic: {
288
+ inferenceGeo: 'us',
289
+ } satisfies AnthropicLanguageModelOptions,
290
+ },
291
+ });
292
+ ```
293
+
294
+ The `inferenceGeo` option accepts `'us'` (US-only infrastructure) or `'global'` (default, any available geography).
295
+
227
296
  ### Reasoning
228
297
 
229
298
  Anthropic models support extended thinking, where Claude shows its reasoning process before providing a final answer.
@@ -267,6 +336,31 @@ const { text } = await generateText({
267
336
  });
268
337
  ```
269
338
 
339
+ ##### Thinking Display (Opus 4.7+)
340
+
341
+ 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'`:
342
+
343
+ ```ts highlight="5"
344
+ const { text, reasoningText } = await generateText({
345
+ model: anthropic('claude-opus-4-7'),
346
+ providerOptions: {
347
+ anthropic: {
348
+ thinking: { type: 'adaptive', display: 'summarized' },
349
+ } satisfies AnthropicLanguageModelOptions,
350
+ },
351
+ prompt: 'How many people will live in the world in 2040?',
352
+ });
353
+
354
+ console.log(reasoningText); // reasoning text (empty without display: 'summarized')
355
+ console.log(text);
356
+ ```
357
+
358
+ <Note>
359
+ If you stream reasoning to users with `claude-opus-4-7`, the default `"omitted"` display will
360
+ cause a long pause before output begins. Set `display: "summarized"` to restore visible
361
+ progress during thinking.
362
+ </Note>
363
+
270
364
  #### Budget-Based Thinking
271
365
 
272
366
  For earlier models (`claude-opus-4-20250514`, `claude-sonnet-4-20250514`, `claude-sonnet-4-5-20250929`),
@@ -1351,6 +1445,7 @@ and the `mediaType` should be set to `'application/pdf'`.
1351
1445
 
1352
1446
  | Model | Image Input | Object Generation | Tool Usage | Computer Use | Web Search | Tool Search | Compaction |
1353
1447
  | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- | ------------------- |
1448
+ | `claude-opus-4-7` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1354
1449
  | `claude-opus-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> |
1355
1450
  | `claude-sonnet-4-6` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
1356
1451
  | `claude-opus-4-5` | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | <Check size={18} /> | |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/anthropic",
3
- "version": "3.0.68",
3
+ "version": "3.0.70",
4
4
  "license": "Apache-2.0",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/index.js",
@@ -269,9 +269,37 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
269
269
  const {
270
270
  maxOutputTokens: maxOutputTokensForModel,
271
271
  supportsStructuredOutput: modelSupportsStructuredOutput,
272
+ rejectsSamplingParameters,
272
273
  isKnownModel,
273
274
  } = getModelCapabilities(this.modelId);
274
275
 
276
+ if (rejectsSamplingParameters) {
277
+ if (temperature != null) {
278
+ warnings.push({
279
+ type: 'unsupported',
280
+ feature: 'temperature',
281
+ details: `temperature is not supported by ${this.modelId} and will be ignored`,
282
+ });
283
+ temperature = undefined;
284
+ }
285
+ if (topK != null) {
286
+ warnings.push({
287
+ type: 'unsupported',
288
+ feature: 'topK',
289
+ details: `topK is not supported by ${this.modelId} and will be ignored`,
290
+ });
291
+ topK = undefined;
292
+ }
293
+ if (topP != null) {
294
+ warnings.push({
295
+ type: 'unsupported',
296
+ feature: 'topP',
297
+ details: `topP is not supported by ${this.modelId} and will be ignored`,
298
+ });
299
+ topP = undefined;
300
+ }
301
+ }
302
+
275
303
  const isAnthropicModel = isKnownModel || this.modelId.startsWith('claude-');
276
304
 
277
305
  const supportsStructuredOutput =
@@ -345,6 +373,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
345
373
  thinkingType === 'enabled'
346
374
  ? anthropicOptions?.thinking?.budgetTokens
347
375
  : undefined;
376
+ const thinkingDisplay =
377
+ thinkingType === 'adaptive'
378
+ ? anthropicOptions?.thinking?.display
379
+ : undefined;
348
380
 
349
381
  const maxTokens = maxOutputTokens ?? maxOutputTokensForModel;
350
382
 
@@ -364,9 +396,11 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
364
396
  thinking: {
365
397
  type: thinkingType,
366
398
  ...(thinkingBudget != null && { budget_tokens: thinkingBudget }),
399
+ ...(thinkingDisplay != null && { display: thinkingDisplay }),
367
400
  },
368
401
  }),
369
402
  ...((anthropicOptions?.effort ||
403
+ anthropicOptions?.taskBudget ||
370
404
  (useStructuredOutput &&
371
405
  responseFormat?.type === 'json' &&
372
406
  responseFormat.schema != null)) && {
@@ -374,6 +408,15 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
374
408
  ...(anthropicOptions?.effort && {
375
409
  effort: anthropicOptions.effort,
376
410
  }),
411
+ ...(anthropicOptions?.taskBudget && {
412
+ task_budget: {
413
+ type: anthropicOptions.taskBudget.type,
414
+ total: anthropicOptions.taskBudget.total,
415
+ ...(anthropicOptions.taskBudget.remaining != null && {
416
+ remaining: anthropicOptions.taskBudget.remaining,
417
+ }),
418
+ },
419
+ }),
377
420
  ...(useStructuredOutput &&
378
421
  responseFormat?.type === 'json' &&
379
422
  responseFormat.schema != null && {
@@ -387,6 +430,9 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
387
430
  ...(anthropicOptions?.speed && {
388
431
  speed: anthropicOptions.speed,
389
432
  }),
433
+ ...(anthropicOptions?.inferenceGeo && {
434
+ inference_geo: anthropicOptions.inferenceGeo,
435
+ }),
390
436
  ...(anthropicOptions?.cacheControl && {
391
437
  cache_control: anthropicOptions.cacheControl,
392
438
  }),
@@ -609,6 +655,10 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
609
655
  betas.add('effort-2025-11-24');
610
656
  }
611
657
 
658
+ if (anthropicOptions?.taskBudget) {
659
+ betas.add('task-budgets-2026-03-13');
660
+ }
661
+
612
662
  if (anthropicOptions?.speed === 'fast') {
613
663
  betas.add('fast-mode-2026-02-01');
614
664
  }
@@ -2281,15 +2331,24 @@ export class AnthropicMessagesLanguageModel implements LanguageModelV3 {
2281
2331
  function getModelCapabilities(modelId: string): {
2282
2332
  maxOutputTokens: number;
2283
2333
  supportsStructuredOutput: boolean;
2334
+ rejectsSamplingParameters: boolean;
2284
2335
  isKnownModel: boolean;
2285
2336
  } {
2286
- if (
2337
+ if (modelId.includes('claude-opus-4-7')) {
2338
+ return {
2339
+ maxOutputTokens: 128000,
2340
+ supportsStructuredOutput: true,
2341
+ rejectsSamplingParameters: true,
2342
+ isKnownModel: true,
2343
+ };
2344
+ } else if (
2287
2345
  modelId.includes('claude-sonnet-4-6') ||
2288
2346
  modelId.includes('claude-opus-4-6')
2289
2347
  ) {
2290
2348
  return {
2291
2349
  maxOutputTokens: 128000,
2292
2350
  supportsStructuredOutput: true,
2351
+ rejectsSamplingParameters: false,
2293
2352
  isKnownModel: true,
2294
2353
  };
2295
2354
  } else if (
@@ -2300,36 +2359,42 @@ function getModelCapabilities(modelId: string): {
2300
2359
  return {
2301
2360
  maxOutputTokens: 64000,
2302
2361
  supportsStructuredOutput: true,
2362
+ rejectsSamplingParameters: false,
2303
2363
  isKnownModel: true,
2304
2364
  };
2305
2365
  } else if (modelId.includes('claude-opus-4-1')) {
2306
2366
  return {
2307
2367
  maxOutputTokens: 32000,
2308
2368
  supportsStructuredOutput: true,
2369
+ rejectsSamplingParameters: false,
2309
2370
  isKnownModel: true,
2310
2371
  };
2311
2372
  } else if (modelId.includes('claude-sonnet-4-')) {
2312
2373
  return {
2313
2374
  maxOutputTokens: 64000,
2314
2375
  supportsStructuredOutput: false,
2376
+ rejectsSamplingParameters: false,
2315
2377
  isKnownModel: true,
2316
2378
  };
2317
2379
  } else if (modelId.includes('claude-opus-4-')) {
2318
2380
  return {
2319
2381
  maxOutputTokens: 32000,
2320
2382
  supportsStructuredOutput: false,
2383
+ rejectsSamplingParameters: false,
2321
2384
  isKnownModel: true,
2322
2385
  };
2323
2386
  } else if (modelId.includes('claude-3-haiku')) {
2324
2387
  return {
2325
2388
  maxOutputTokens: 4096,
2326
2389
  supportsStructuredOutput: false,
2390
+ rejectsSamplingParameters: false,
2327
2391
  isKnownModel: true,
2328
2392
  };
2329
2393
  } else {
2330
2394
  return {
2331
2395
  maxOutputTokens: 4096,
2332
2396
  supportsStructuredOutput: false,
2397
+ rejectsSamplingParameters: false,
2333
2398
  isKnownModel: false,
2334
2399
  };
2335
2400
  }
@@ -17,6 +17,7 @@ export type AnthropicMessagesModelId =
17
17
  | 'claude-sonnet-4-5'
18
18
  | 'claude-sonnet-4-6'
19
19
  | 'claude-opus-4-6'
20
+ | 'claude-opus-4-7'
20
21
  | (string & {});
21
22
 
22
23
  /**
@@ -83,6 +84,12 @@ export const anthropicLanguageModelOptions = z.object({
83
84
  z.object({
84
85
  /** for Sonnet 4.6, Opus 4.6, and newer models */
85
86
  type: z.literal('adaptive'),
87
+ /**
88
+ * Controls whether thinking content is included in the response.
89
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
90
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
91
+ */
92
+ display: z.enum(['omitted', 'summarized']).optional(),
86
93
  }),
87
94
  z.object({
88
95
  /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
@@ -182,7 +189,22 @@ export const anthropicLanguageModelOptions = z.object({
182
189
  /**
183
190
  * @default 'high'
184
191
  */
185
- effort: z.enum(['low', 'medium', 'high', 'max']).optional(),
192
+ effort: z.enum(['low', 'medium', 'high', 'xhigh', 'max']).optional(),
193
+
194
+ /**
195
+ * Task budget for agentic turns. Informs the model of the total token budget
196
+ * available for the current task, allowing it to prioritize work and wind down
197
+ * gracefully as the budget is consumed.
198
+ *
199
+ * Advisory only — does not enforce a hard token limit.
200
+ */
201
+ taskBudget: z
202
+ .object({
203
+ type: z.literal('tokens'),
204
+ total: z.number().int().min(20000),
205
+ remaining: z.number().int().min(0).optional(),
206
+ })
207
+ .optional(),
186
208
 
187
209
  /**
188
210
  * Enable fast mode for faster inference (2.5x faster output token speeds).
@@ -190,6 +212,16 @@ export const anthropicLanguageModelOptions = z.object({
190
212
  */
191
213
  speed: z.enum(['fast', 'standard']).optional(),
192
214
 
215
+ /**
216
+ * Controls where model inference runs for this request.
217
+ *
218
+ * - `"global"`: Inference may run in any available geography (default).
219
+ * - `"us"`: Inference runs only in US-based infrastructure.
220
+ *
221
+ * See https://platform.claude.com/docs/en/build-with-claude/data-residency
222
+ */
223
+ inferenceGeo: z.enum(['us', 'global']).optional(),
224
+
193
225
  /**
194
226
  * A set of beta features to enable.
195
227
  * Allow a provider to receive the full `betas` set if it needs it.