@ai-sdk/anthropic 4.0.73 → 4.0.75
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.
- package/CHANGELOG.md +19 -0
- package/README.md +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -9
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +6 -1
- package/dist/internal/index.d.ts.map +1 -1
- package/dist/internal/index.js +37 -8
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +21 -9
- package/package.json +3 -3
- package/src/anthropic-language-model-options.ts +1 -0
- package/src/anthropic-language-model.ts +58 -12
package/docs/05-anthropic.mdx
CHANGED
|
@@ -73,18 +73,18 @@ You can use the following optional settings to customize the Anthropic provider
|
|
|
73
73
|
## Language Models
|
|
74
74
|
|
|
75
75
|
You can create models that call the [Anthropic Messages API](https://docs.anthropic.com/claude/reference/messages_post) using the provider instance.
|
|
76
|
-
The first argument is the model id, e.g. `claude-haiku-
|
|
76
|
+
The first argument is the model id, e.g. `claude-haiku-5-5`.
|
|
77
77
|
Some models have multi-modal capabilities.
|
|
78
78
|
|
|
79
79
|
```ts
|
|
80
|
-
const model = anthropic('claude-haiku-
|
|
80
|
+
const model = anthropic('claude-haiku-5-5');
|
|
81
81
|
```
|
|
82
82
|
|
|
83
83
|
You can also use the following aliases for model creation:
|
|
84
84
|
|
|
85
|
-
- `anthropic.languageModel('claude-haiku-
|
|
86
|
-
- `anthropic.chat('claude-haiku-
|
|
87
|
-
- `anthropic.messages('claude-haiku-
|
|
85
|
+
- `anthropic.languageModel('claude-haiku-5-5')` - Creates a language model
|
|
86
|
+
- `anthropic.chat('claude-haiku-5-5')` - Alias for `languageModel`
|
|
87
|
+
- `anthropic.messages('claude-haiku-5-5')` - Alias for `languageModel`
|
|
88
88
|
|
|
89
89
|
You can use Anthropic language models to generate text with the `generateText` function:
|
|
90
90
|
|
|
@@ -93,7 +93,7 @@ import { anthropic } from '@ai-sdk/anthropic';
|
|
|
93
93
|
import { generateText } from 'ai';
|
|
94
94
|
|
|
95
95
|
const { text } = await generateText({
|
|
96
|
-
model: anthropic('claude-haiku-
|
|
96
|
+
model: anthropic('claude-haiku-5-5'),
|
|
97
97
|
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
98
98
|
});
|
|
99
99
|
```
|
|
@@ -113,7 +113,7 @@ import { anthropic } from '@ai-sdk/anthropic';
|
|
|
113
113
|
import { streamText } from 'ai';
|
|
114
114
|
|
|
115
115
|
const result = streamText({
|
|
116
|
-
model: anthropic('claude-haiku-
|
|
116
|
+
model: anthropic('claude-haiku-5-5'),
|
|
117
117
|
prompt: 'Say hi in one word.',
|
|
118
118
|
});
|
|
119
119
|
|
|
@@ -245,9 +245,18 @@ verify that a tool call was made.
|
|
|
245
245
|
|
|
246
246
|
### Effort
|
|
247
247
|
|
|
248
|
-
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`, `claude-sonnet-5`, and `claude-
|
|
248
|
+
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`, `claude-sonnet-5`, `claude-sonnet-5-5`, and `claude-haiku-5-5` additionally support `xhigh` for maximum reasoning effort.
|
|
249
249
|
|
|
250
|
-
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.
|
|
250
|
+
On `claude-opus-5` and `claude-haiku-5-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.
|
|
251
|
+
|
|
252
|
+
`claude-haiku-5-5` is the first Haiku model with effort levels and supports all
|
|
253
|
+
five of them. It uses adaptive thinking and does not support thinking token
|
|
254
|
+
budgets: the AI SDK converts `thinking: { type: 'enabled', budgetTokens }` to
|
|
255
|
+
`{ type: 'adaptive' }` and emits a warning. Use `effort` to control how much it
|
|
256
|
+
thinks. Unlike `claude-sonnet-5-5`, thinking can still be turned off with
|
|
257
|
+
`thinking: { type: 'disabled' }`, but only at `low`, `medium`, and `high` effort.
|
|
258
|
+
Start at `medium` effort and test other levels rather than carrying over the
|
|
259
|
+
settings you used on `claude-haiku-4-5`.
|
|
251
260
|
|
|
252
261
|
On `claude-opus-5-5`, thinking is always adaptive and cannot be disabled, so
|
|
253
262
|
`effort` is the main control for latency and cost. The API default effort for
|
|
@@ -370,6 +379,8 @@ The `inferenceGeo` option accepts `'us'` (US-only infrastructure) or `'global'`
|
|
|
370
379
|
|
|
371
380
|
Claude Fable 5 has safeguards that limit its performance in certain areas like cybersecurity, biology, and chemistry, and automated safety checks are run on every request.
|
|
372
381
|
|
|
382
|
+
Claude Haiku 5.5 has the same biology safeguards as Claude Sonnet 5 and 5.5, plus safeguards that prevent cyber misuse.
|
|
383
|
+
|
|
373
384
|
Claude Sonnet 5.5 also has safety classifiers enabled, including for cybersecurity, biology, and reasoning extraction. Requests that ask the model to reproduce its internal reasoning in the response text can be declined with the `reasoning_extraction` category; use `thinking: { type: 'adaptive', display: 'summarized' }` and read the reasoning parts instead.
|
|
374
385
|
|
|
375
386
|
When one of these checks blocks a request, the API does not answer it. Instead it returns a classifier block: a `200` response with a `refusal` stop reason and an optional `stop_details` object describing the category that triggered the block. The AI SDK surfaces this as a `content-filter` finish reason, with the details available on `providerMetadata.anthropic.stopDetails`.
|
|
@@ -2248,6 +2259,7 @@ and the `mediaType` should be set to `'application/pdf'`.
|
|
|
2248
2259
|
| `claude-opus-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2249
2260
|
| `claude-sonnet-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2250
2261
|
| `claude-sonnet-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2262
|
+
| `claude-haiku-5-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2251
2263
|
| `claude-fable-5-1` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2252
2264
|
| `claude-fable-5` | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> | <Check /> |
|
|
2253
2265
|
| `claude-opus-4-8` | <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.
|
|
3
|
+
"version": "4.0.75",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.24",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.56"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -406,6 +406,7 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
406
406
|
supportsXhighEffort,
|
|
407
407
|
rejectsThinkingDisabledAboveHighEffort,
|
|
408
408
|
rejectsThinkingDisabled,
|
|
409
|
+
rejectsBudgetThinking,
|
|
409
410
|
rejectsForcedToolUse,
|
|
410
411
|
supportsBetweenToolsThinking,
|
|
411
412
|
isKnownModel,
|
|
@@ -591,9 +592,9 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
591
592
|
}
|
|
592
593
|
}
|
|
593
594
|
|
|
594
|
-
// Some models always run adaptive thinking and reject `disabled`
|
|
595
|
-
//
|
|
596
|
-
//
|
|
595
|
+
// Some models always run adaptive thinking and reject `disabled` thinking
|
|
596
|
+
// with a 400. Drop the unsupported setting and keep the request adaptive
|
|
597
|
+
// so it still succeeds.
|
|
597
598
|
if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
|
|
598
599
|
const thinking = anthropicOptions.thinking;
|
|
599
600
|
|
|
@@ -615,18 +616,28 @@ export class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
615
616
|
`The thinking setting has been removed. Lower 'effort' to reduce thinking.`,
|
|
616
617
|
});
|
|
617
618
|
anthropicOptions.thinking = undefined;
|
|
618
|
-
} else if (thinking.type === 'enabled') {
|
|
619
|
-
warnings.push({
|
|
620
|
-
type: 'unsupported',
|
|
621
|
-
feature: 'providerOptions.anthropic.thinking',
|
|
622
|
-
details:
|
|
623
|
-
`budget-based thinking is not supported by ${modelId}; it always uses adaptive thinking. ` +
|
|
624
|
-
`Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`,
|
|
625
|
-
});
|
|
626
|
-
anthropicOptions.thinking = { type: 'adaptive' };
|
|
627
619
|
}
|
|
628
620
|
}
|
|
629
621
|
|
|
622
|
+
// Models that only support adaptive thinking reject budget-based thinking
|
|
623
|
+
// with a 400. Use adaptive thinking instead and let `effort` control how
|
|
624
|
+
// much the model thinks.
|
|
625
|
+
if (
|
|
626
|
+
rejectsBudgetThinking &&
|
|
627
|
+
anthropicOptions?.thinking?.type === 'enabled'
|
|
628
|
+
) {
|
|
629
|
+
warnings.push({
|
|
630
|
+
type: 'unsupported',
|
|
631
|
+
feature: 'providerOptions.anthropic.thinking',
|
|
632
|
+
details: rejectsThinkingDisabled
|
|
633
|
+
? `budget-based thinking is not supported by ${modelId}; it always uses adaptive thinking. ` +
|
|
634
|
+
`Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`
|
|
635
|
+
: `budget-based thinking is not supported by ${modelId}. ` +
|
|
636
|
+
`Using adaptive thinking instead. Use 'effort' to control how much the model thinks.`,
|
|
637
|
+
});
|
|
638
|
+
anthropicOptions.thinking = { type: 'adaptive' };
|
|
639
|
+
}
|
|
640
|
+
|
|
630
641
|
// Newer models only allow disabling thinking at effort levels up to and
|
|
631
642
|
// including `high`; at `xhigh` and `max` the API returns a 400. Lower
|
|
632
643
|
// the effort to `high` to preserve the explicit request to run without
|
|
@@ -3181,6 +3192,11 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3181
3192
|
* are rejected with a 400.
|
|
3182
3193
|
*/
|
|
3183
3194
|
rejectsThinkingDisabled: boolean;
|
|
3195
|
+
/**
|
|
3196
|
+
* Budget-based thinking (`thinking.type` `enabled` with `budget_tokens`) is
|
|
3197
|
+
* rejected with a 400. Only adaptive thinking is supported.
|
|
3198
|
+
*/
|
|
3199
|
+
rejectsBudgetThinking: boolean;
|
|
3184
3200
|
/**
|
|
3185
3201
|
* Forced tool use (`tool_choice` `any` or a named tool) is rejected with a 400.
|
|
3186
3202
|
*/
|
|
@@ -3201,6 +3217,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3201
3217
|
supportsXhighEffort: true,
|
|
3202
3218
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3203
3219
|
rejectsThinkingDisabled: true,
|
|
3220
|
+
rejectsBudgetThinking: true,
|
|
3204
3221
|
rejectsForcedToolUse: true,
|
|
3205
3222
|
supportsBetweenToolsThinking: true,
|
|
3206
3223
|
isKnownModel: true,
|
|
@@ -3214,10 +3231,26 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3214
3231
|
supportsXhighEffort: true,
|
|
3215
3232
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3216
3233
|
rejectsThinkingDisabled: true,
|
|
3234
|
+
rejectsBudgetThinking: true,
|
|
3217
3235
|
rejectsForcedToolUse: true,
|
|
3218
3236
|
supportsBetweenToolsThinking: false,
|
|
3219
3237
|
isKnownModel: true,
|
|
3220
3238
|
};
|
|
3239
|
+
} else if (modelId.includes('claude-haiku-5-5')) {
|
|
3240
|
+
// Thinking can be turned off, but only up to `high` effort.
|
|
3241
|
+
return {
|
|
3242
|
+
maxOutputTokens: 128000,
|
|
3243
|
+
supportsStructuredOutput: true,
|
|
3244
|
+
supportsAdaptiveThinking: true,
|
|
3245
|
+
rejectsSamplingParameters: true,
|
|
3246
|
+
supportsXhighEffort: true,
|
|
3247
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3248
|
+
rejectsThinkingDisabled: false,
|
|
3249
|
+
rejectsBudgetThinking: true,
|
|
3250
|
+
rejectsForcedToolUse: false,
|
|
3251
|
+
supportsBetweenToolsThinking: false,
|
|
3252
|
+
isKnownModel: true,
|
|
3253
|
+
};
|
|
3221
3254
|
} else if (modelId.includes('claude-opus-5')) {
|
|
3222
3255
|
return {
|
|
3223
3256
|
maxOutputTokens: 128000,
|
|
@@ -3227,6 +3260,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3227
3260
|
supportsXhighEffort: true,
|
|
3228
3261
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3229
3262
|
rejectsThinkingDisabled: false,
|
|
3263
|
+
rejectsBudgetThinking: false,
|
|
3230
3264
|
rejectsForcedToolUse: false,
|
|
3231
3265
|
supportsBetweenToolsThinking: false,
|
|
3232
3266
|
isKnownModel: true,
|
|
@@ -3240,6 +3274,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3240
3274
|
supportsXhighEffort: true,
|
|
3241
3275
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3242
3276
|
rejectsThinkingDisabled: true,
|
|
3277
|
+
rejectsBudgetThinking: true,
|
|
3243
3278
|
rejectsForcedToolUse: true,
|
|
3244
3279
|
supportsBetweenToolsThinking: false,
|
|
3245
3280
|
isKnownModel: true,
|
|
@@ -3253,6 +3288,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3253
3288
|
supportsXhighEffort: true,
|
|
3254
3289
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3255
3290
|
rejectsThinkingDisabled: true,
|
|
3291
|
+
rejectsBudgetThinking: true,
|
|
3256
3292
|
rejectsForcedToolUse: false,
|
|
3257
3293
|
supportsBetweenToolsThinking: false,
|
|
3258
3294
|
isKnownModel: true,
|
|
@@ -3270,6 +3306,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3270
3306
|
supportsXhighEffort: true,
|
|
3271
3307
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3272
3308
|
rejectsThinkingDisabled: false,
|
|
3309
|
+
rejectsBudgetThinking: false,
|
|
3273
3310
|
rejectsForcedToolUse: false,
|
|
3274
3311
|
supportsBetweenToolsThinking: false,
|
|
3275
3312
|
isKnownModel: true,
|
|
@@ -3286,6 +3323,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3286
3323
|
supportsXhighEffort: false,
|
|
3287
3324
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3288
3325
|
rejectsThinkingDisabled: false,
|
|
3326
|
+
rejectsBudgetThinking: false,
|
|
3289
3327
|
rejectsForcedToolUse: false,
|
|
3290
3328
|
supportsBetweenToolsThinking: false,
|
|
3291
3329
|
isKnownModel: true,
|
|
@@ -3303,6 +3341,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3303
3341
|
supportsXhighEffort: false,
|
|
3304
3342
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3305
3343
|
rejectsThinkingDisabled: false,
|
|
3344
|
+
rejectsBudgetThinking: false,
|
|
3306
3345
|
rejectsForcedToolUse: false,
|
|
3307
3346
|
supportsBetweenToolsThinking: false,
|
|
3308
3347
|
isKnownModel: true,
|
|
@@ -3316,6 +3355,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3316
3355
|
supportsXhighEffort: false,
|
|
3317
3356
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3318
3357
|
rejectsThinkingDisabled: false,
|
|
3358
|
+
rejectsBudgetThinking: false,
|
|
3319
3359
|
rejectsForcedToolUse: false,
|
|
3320
3360
|
supportsBetweenToolsThinking: false,
|
|
3321
3361
|
isKnownModel: true,
|
|
@@ -3329,6 +3369,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3329
3369
|
supportsXhighEffort: false,
|
|
3330
3370
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3331
3371
|
rejectsThinkingDisabled: false,
|
|
3372
|
+
rejectsBudgetThinking: false,
|
|
3332
3373
|
rejectsForcedToolUse: false,
|
|
3333
3374
|
supportsBetweenToolsThinking: false,
|
|
3334
3375
|
isKnownModel: true,
|
|
@@ -3342,6 +3383,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3342
3383
|
supportsXhighEffort: false,
|
|
3343
3384
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3344
3385
|
rejectsThinkingDisabled: false,
|
|
3386
|
+
rejectsBudgetThinking: false,
|
|
3345
3387
|
rejectsForcedToolUse: false,
|
|
3346
3388
|
supportsBetweenToolsThinking: false,
|
|
3347
3389
|
isKnownModel: true,
|
|
@@ -3355,6 +3397,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3355
3397
|
supportsXhighEffort: false,
|
|
3356
3398
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3357
3399
|
rejectsThinkingDisabled: false,
|
|
3400
|
+
rejectsBudgetThinking: false,
|
|
3358
3401
|
rejectsForcedToolUse: false,
|
|
3359
3402
|
supportsBetweenToolsThinking: false,
|
|
3360
3403
|
isKnownModel: true,
|
|
@@ -3370,6 +3413,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3370
3413
|
supportsXhighEffort: false,
|
|
3371
3414
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3372
3415
|
rejectsThinkingDisabled: false,
|
|
3416
|
+
rejectsBudgetThinking: false,
|
|
3373
3417
|
rejectsForcedToolUse: false,
|
|
3374
3418
|
supportsBetweenToolsThinking: false,
|
|
3375
3419
|
isKnownModel: false,
|
|
@@ -3386,6 +3430,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3386
3430
|
supportsXhighEffort: true,
|
|
3387
3431
|
rejectsThinkingDisabledAboveHighEffort: true,
|
|
3388
3432
|
rejectsThinkingDisabled: false,
|
|
3433
|
+
rejectsBudgetThinking: false,
|
|
3389
3434
|
rejectsForcedToolUse: false,
|
|
3390
3435
|
supportsBetweenToolsThinking: false,
|
|
3391
3436
|
isKnownModel: false,
|
|
@@ -3401,6 +3446,7 @@ export function getModelCapabilities(modelId: string): {
|
|
|
3401
3446
|
supportsXhighEffort: false,
|
|
3402
3447
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
3403
3448
|
rejectsThinkingDisabled: false,
|
|
3449
|
+
rejectsBudgetThinking: false,
|
|
3404
3450
|
rejectsForcedToolUse: false,
|
|
3405
3451
|
supportsBetweenToolsThinking: false,
|
|
3406
3452
|
isKnownModel: false,
|