@ai-sdk/anthropic 4.0.0-beta.29 → 4.0.0-beta.31
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 +13 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +103 -16
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +3 -1
- package/dist/internal/index.js +102 -15
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +72 -2
- package/package.json +3 -3
- package/src/anthropic-messages-language-model.ts +86 -9
- package/src/anthropic-messages-options.ts +23 -1
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV4, JSONObject, LanguageModelV4CallOptions, LanguageModelV
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE, Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
|
4
4
|
|
|
5
|
-
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | (string & {});
|
|
5
|
+
type AnthropicMessagesModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-5' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-0' | 'claude-sonnet-4-20250514' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-5' | 'claude-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | (string & {});
|
|
6
6
|
|
|
7
7
|
type AnthropicMessagesConfig = {
|
|
8
8
|
provider: string;
|
|
@@ -64,6 +64,8 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
64
64
|
maxOutputTokens: number;
|
|
65
65
|
supportsStructuredOutput: boolean;
|
|
66
66
|
supportsAdaptiveThinking: boolean;
|
|
67
|
+
rejectsSamplingParameters: boolean;
|
|
68
|
+
supportsXhighEffort: boolean;
|
|
67
69
|
isKnownModel: boolean;
|
|
68
70
|
};
|
|
69
71
|
|
package/dist/internal/index.js
CHANGED
|
@@ -831,7 +831,13 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
831
831
|
thinking: z3.discriminatedUnion("type", [
|
|
832
832
|
z3.object({
|
|
833
833
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
834
|
-
type: z3.literal("adaptive")
|
|
834
|
+
type: z3.literal("adaptive"),
|
|
835
|
+
/**
|
|
836
|
+
* Controls whether thinking content is included in the response.
|
|
837
|
+
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
838
|
+
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
839
|
+
*/
|
|
840
|
+
display: z3.enum(["omitted", "summarized"]).optional()
|
|
835
841
|
}),
|
|
836
842
|
z3.object({
|
|
837
843
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
@@ -918,7 +924,19 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
918
924
|
/**
|
|
919
925
|
* @default 'high'
|
|
920
926
|
*/
|
|
921
|
-
effort: z3.enum(["low", "medium", "high", "max"]).optional(),
|
|
927
|
+
effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
928
|
+
/**
|
|
929
|
+
* Task budget for agentic turns. Informs the model of the total token budget
|
|
930
|
+
* available for the current task, allowing it to prioritize work and wind down
|
|
931
|
+
* gracefully as the budget is consumed.
|
|
932
|
+
*
|
|
933
|
+
* Advisory only — does not enforce a hard token limit.
|
|
934
|
+
*/
|
|
935
|
+
taskBudget: z3.object({
|
|
936
|
+
type: z3.literal("tokens"),
|
|
937
|
+
total: z3.number().int().min(2e4),
|
|
938
|
+
remaining: z3.number().int().min(0).optional()
|
|
939
|
+
}).optional(),
|
|
922
940
|
/**
|
|
923
941
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
924
942
|
* Only supported with claude-opus-4-6.
|
|
@@ -2967,7 +2985,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
2967
2985
|
providerOptions,
|
|
2968
2986
|
stream
|
|
2969
2987
|
}) {
|
|
2970
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2988
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
2971
2989
|
const warnings = [];
|
|
2972
2990
|
if (frequencyPenalty != null) {
|
|
2973
2991
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3023,8 +3041,36 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3023
3041
|
maxOutputTokens: maxOutputTokensForModel,
|
|
3024
3042
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3025
3043
|
supportsAdaptiveThinking,
|
|
3044
|
+
rejectsSamplingParameters,
|
|
3045
|
+
supportsXhighEffort,
|
|
3026
3046
|
isKnownModel
|
|
3027
3047
|
} = getModelCapabilities(this.modelId);
|
|
3048
|
+
if (rejectsSamplingParameters) {
|
|
3049
|
+
if (temperature != null) {
|
|
3050
|
+
warnings.push({
|
|
3051
|
+
type: "unsupported",
|
|
3052
|
+
feature: "temperature",
|
|
3053
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
3054
|
+
});
|
|
3055
|
+
temperature = void 0;
|
|
3056
|
+
}
|
|
3057
|
+
if (topK != null) {
|
|
3058
|
+
warnings.push({
|
|
3059
|
+
type: "unsupported",
|
|
3060
|
+
feature: "topK",
|
|
3061
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
3062
|
+
});
|
|
3063
|
+
topK = void 0;
|
|
3064
|
+
}
|
|
3065
|
+
if (topP != null) {
|
|
3066
|
+
warnings.push({
|
|
3067
|
+
type: "unsupported",
|
|
3068
|
+
feature: "topP",
|
|
3069
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
3070
|
+
});
|
|
3071
|
+
topP = void 0;
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3028
3074
|
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
3029
3075
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
3030
3076
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
@@ -3068,23 +3114,27 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3068
3114
|
cacheControlValidator,
|
|
3069
3115
|
toolNameMapping
|
|
3070
3116
|
});
|
|
3071
|
-
if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.
|
|
3117
|
+
if (isCustomReasoning(reasoning) && (anthropicOptions == null ? void 0 : anthropicOptions.effort) == null) {
|
|
3072
3118
|
const reasoningConfig = resolveAnthropicReasoningConfig({
|
|
3073
3119
|
reasoning,
|
|
3074
3120
|
supportsAdaptiveThinking,
|
|
3121
|
+
supportsXhighEffort,
|
|
3075
3122
|
maxOutputTokensForModel,
|
|
3076
3123
|
warnings
|
|
3077
3124
|
});
|
|
3078
3125
|
if (reasoningConfig != null) {
|
|
3079
|
-
anthropicOptions.thinking
|
|
3080
|
-
|
|
3126
|
+
if (anthropicOptions.thinking == null) {
|
|
3127
|
+
anthropicOptions.thinking = reasoningConfig.thinking;
|
|
3128
|
+
}
|
|
3129
|
+
if (reasoningConfig.effort != null && ((_e = anthropicOptions.thinking) == null ? void 0 : _e.type) !== "disabled") {
|
|
3081
3130
|
anthropicOptions.effort = reasoningConfig.effort;
|
|
3082
3131
|
}
|
|
3083
3132
|
}
|
|
3084
3133
|
}
|
|
3085
|
-
const thinkingType = (
|
|
3134
|
+
const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
|
|
3086
3135
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3087
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3136
|
+
let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
|
|
3137
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
|
|
3088
3138
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3089
3139
|
const baseArgs = {
|
|
3090
3140
|
// model id:
|
|
@@ -3099,14 +3149,24 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3099
3149
|
...isThinking && {
|
|
3100
3150
|
thinking: {
|
|
3101
3151
|
type: thinkingType,
|
|
3102
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
3152
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
3153
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
3103
3154
|
}
|
|
3104
3155
|
},
|
|
3105
|
-
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3156
|
+
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3106
3157
|
output_config: {
|
|
3107
3158
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
3108
3159
|
effort: anthropicOptions.effort
|
|
3109
3160
|
},
|
|
3161
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
|
|
3162
|
+
task_budget: {
|
|
3163
|
+
type: anthropicOptions.taskBudget.type,
|
|
3164
|
+
total: anthropicOptions.taskBudget.total,
|
|
3165
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
3166
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
3167
|
+
}
|
|
3168
|
+
}
|
|
3169
|
+
},
|
|
3110
3170
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3111
3171
|
format: {
|
|
3112
3172
|
type: "json_schema",
|
|
@@ -3124,7 +3184,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3124
3184
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3125
3185
|
cache_control: anthropicOptions.cacheControl
|
|
3126
3186
|
},
|
|
3127
|
-
...((
|
|
3187
|
+
...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
|
|
3128
3188
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3129
3189
|
},
|
|
3130
3190
|
// mcp servers:
|
|
@@ -3297,10 +3357,13 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3297
3357
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
3298
3358
|
betas.add("effort-2025-11-24");
|
|
3299
3359
|
}
|
|
3360
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
3361
|
+
betas.add("task-budgets-2026-03-13");
|
|
3362
|
+
}
|
|
3300
3363
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3301
3364
|
betas.add("fast-mode-2026-02-01");
|
|
3302
3365
|
}
|
|
3303
|
-
if (stream && ((
|
|
3366
|
+
if (stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true)) {
|
|
3304
3367
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
3305
3368
|
}
|
|
3306
3369
|
const {
|
|
@@ -3339,7 +3402,7 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
3339
3402
|
...betas,
|
|
3340
3403
|
...toolsBetas,
|
|
3341
3404
|
...userSuppliedBetas,
|
|
3342
|
-
...(
|
|
3405
|
+
...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
|
|
3343
3406
|
]),
|
|
3344
3407
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3345
3408
|
toolNameMapping,
|
|
@@ -4599,11 +4662,22 @@ var AnthropicMessagesLanguageModel = class _AnthropicMessagesLanguageModel {
|
|
|
4599
4662
|
}
|
|
4600
4663
|
};
|
|
4601
4664
|
function getModelCapabilities(modelId) {
|
|
4602
|
-
if (modelId.includes("claude-
|
|
4665
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
4666
|
+
return {
|
|
4667
|
+
maxOutputTokens: 128e3,
|
|
4668
|
+
supportsStructuredOutput: true,
|
|
4669
|
+
supportsAdaptiveThinking: true,
|
|
4670
|
+
rejectsSamplingParameters: true,
|
|
4671
|
+
supportsXhighEffort: true,
|
|
4672
|
+
isKnownModel: true
|
|
4673
|
+
};
|
|
4674
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
4603
4675
|
return {
|
|
4604
4676
|
maxOutputTokens: 128e3,
|
|
4605
4677
|
supportsStructuredOutput: true,
|
|
4606
4678
|
supportsAdaptiveThinking: true,
|
|
4679
|
+
rejectsSamplingParameters: false,
|
|
4680
|
+
supportsXhighEffort: false,
|
|
4607
4681
|
isKnownModel: true
|
|
4608
4682
|
};
|
|
4609
4683
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -4611,6 +4685,8 @@ function getModelCapabilities(modelId) {
|
|
|
4611
4685
|
maxOutputTokens: 64e3,
|
|
4612
4686
|
supportsStructuredOutput: true,
|
|
4613
4687
|
supportsAdaptiveThinking: false,
|
|
4688
|
+
rejectsSamplingParameters: false,
|
|
4689
|
+
supportsXhighEffort: false,
|
|
4614
4690
|
isKnownModel: true
|
|
4615
4691
|
};
|
|
4616
4692
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -4618,6 +4694,8 @@ function getModelCapabilities(modelId) {
|
|
|
4618
4694
|
maxOutputTokens: 32e3,
|
|
4619
4695
|
supportsStructuredOutput: true,
|
|
4620
4696
|
supportsAdaptiveThinking: false,
|
|
4697
|
+
rejectsSamplingParameters: false,
|
|
4698
|
+
supportsXhighEffort: false,
|
|
4621
4699
|
isKnownModel: true
|
|
4622
4700
|
};
|
|
4623
4701
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -4625,6 +4703,8 @@ function getModelCapabilities(modelId) {
|
|
|
4625
4703
|
maxOutputTokens: 64e3,
|
|
4626
4704
|
supportsStructuredOutput: false,
|
|
4627
4705
|
supportsAdaptiveThinking: false,
|
|
4706
|
+
rejectsSamplingParameters: false,
|
|
4707
|
+
supportsXhighEffort: false,
|
|
4628
4708
|
isKnownModel: true
|
|
4629
4709
|
};
|
|
4630
4710
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -4632,6 +4712,8 @@ function getModelCapabilities(modelId) {
|
|
|
4632
4712
|
maxOutputTokens: 32e3,
|
|
4633
4713
|
supportsStructuredOutput: false,
|
|
4634
4714
|
supportsAdaptiveThinking: false,
|
|
4715
|
+
rejectsSamplingParameters: false,
|
|
4716
|
+
supportsXhighEffort: false,
|
|
4635
4717
|
isKnownModel: true
|
|
4636
4718
|
};
|
|
4637
4719
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -4639,6 +4721,8 @@ function getModelCapabilities(modelId) {
|
|
|
4639
4721
|
maxOutputTokens: 4096,
|
|
4640
4722
|
supportsStructuredOutput: false,
|
|
4641
4723
|
supportsAdaptiveThinking: false,
|
|
4724
|
+
rejectsSamplingParameters: false,
|
|
4725
|
+
supportsXhighEffort: false,
|
|
4642
4726
|
isKnownModel: true
|
|
4643
4727
|
};
|
|
4644
4728
|
} else {
|
|
@@ -4646,6 +4730,8 @@ function getModelCapabilities(modelId) {
|
|
|
4646
4730
|
maxOutputTokens: 4096,
|
|
4647
4731
|
supportsStructuredOutput: false,
|
|
4648
4732
|
supportsAdaptiveThinking: false,
|
|
4733
|
+
rejectsSamplingParameters: false,
|
|
4734
|
+
supportsXhighEffort: false,
|
|
4649
4735
|
isKnownModel: false
|
|
4650
4736
|
};
|
|
4651
4737
|
}
|
|
@@ -4671,6 +4757,7 @@ function hasWebTool20260209WithoutCodeExecution(tools) {
|
|
|
4671
4757
|
function resolveAnthropicReasoningConfig({
|
|
4672
4758
|
reasoning,
|
|
4673
4759
|
supportsAdaptiveThinking,
|
|
4760
|
+
supportsXhighEffort,
|
|
4674
4761
|
maxOutputTokensForModel,
|
|
4675
4762
|
warnings
|
|
4676
4763
|
}) {
|
|
@@ -4688,7 +4775,7 @@ function resolveAnthropicReasoningConfig({
|
|
|
4688
4775
|
low: "low",
|
|
4689
4776
|
medium: "medium",
|
|
4690
4777
|
high: "high",
|
|
4691
|
-
xhigh: "max"
|
|
4778
|
+
xhigh: supportsXhighEffort ? "xhigh" : "max"
|
|
4692
4779
|
},
|
|
4693
4780
|
warnings
|
|
4694
4781
|
});
|