@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.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +15 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.js +95 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -10
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +1 -1
- package/dist/internal/index.d.ts +1 -1
- package/dist/internal/index.js +94 -9
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +94 -9
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +97 -2
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +66 -1
- package/src/anthropic-messages-options.ts +33 -1
package/dist/index.mjs
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "@ai-sdk/provider-utils";
|
|
13
13
|
|
|
14
14
|
// src/version.ts
|
|
15
|
-
var VERSION = true ? "3.0.
|
|
15
|
+
var VERSION = true ? "3.0.70" : "0.0.0-test";
|
|
16
16
|
|
|
17
17
|
// src/anthropic-messages-language-model.ts
|
|
18
18
|
import {
|
|
@@ -840,7 +840,13 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
840
840
|
thinking: z3.discriminatedUnion("type", [
|
|
841
841
|
z3.object({
|
|
842
842
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
843
|
-
type: z3.literal("adaptive")
|
|
843
|
+
type: z3.literal("adaptive"),
|
|
844
|
+
/**
|
|
845
|
+
* Controls whether thinking content is included in the response.
|
|
846
|
+
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
847
|
+
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
848
|
+
*/
|
|
849
|
+
display: z3.enum(["omitted", "summarized"]).optional()
|
|
844
850
|
}),
|
|
845
851
|
z3.object({
|
|
846
852
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
@@ -920,12 +926,33 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
920
926
|
/**
|
|
921
927
|
* @default 'high'
|
|
922
928
|
*/
|
|
923
|
-
effort: z3.enum(["low", "medium", "high", "max"]).optional(),
|
|
929
|
+
effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
930
|
+
/**
|
|
931
|
+
* Task budget for agentic turns. Informs the model of the total token budget
|
|
932
|
+
* available for the current task, allowing it to prioritize work and wind down
|
|
933
|
+
* gracefully as the budget is consumed.
|
|
934
|
+
*
|
|
935
|
+
* Advisory only — does not enforce a hard token limit.
|
|
936
|
+
*/
|
|
937
|
+
taskBudget: z3.object({
|
|
938
|
+
type: z3.literal("tokens"),
|
|
939
|
+
total: z3.number().int().min(2e4),
|
|
940
|
+
remaining: z3.number().int().min(0).optional()
|
|
941
|
+
}).optional(),
|
|
924
942
|
/**
|
|
925
943
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
926
944
|
* Only supported with claude-opus-4-6.
|
|
927
945
|
*/
|
|
928
946
|
speed: z3.enum(["fast", "standard"]).optional(),
|
|
947
|
+
/**
|
|
948
|
+
* Controls where model inference runs for this request.
|
|
949
|
+
*
|
|
950
|
+
* - `"global"`: Inference may run in any available geography (default).
|
|
951
|
+
* - `"us"`: Inference runs only in US-based infrastructure.
|
|
952
|
+
*
|
|
953
|
+
* See https://platform.claude.com/docs/en/build-with-claude/data-residency
|
|
954
|
+
*/
|
|
955
|
+
inferenceGeo: z3.enum(["us", "global"]).optional(),
|
|
929
956
|
/**
|
|
930
957
|
* A set of beta features to enable.
|
|
931
958
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -2929,7 +2956,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2929
2956
|
providerOptions,
|
|
2930
2957
|
stream
|
|
2931
2958
|
}) {
|
|
2932
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2959
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2933
2960
|
const warnings = [];
|
|
2934
2961
|
if (frequencyPenalty != null) {
|
|
2935
2962
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2984,8 +3011,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2984
3011
|
const {
|
|
2985
3012
|
maxOutputTokens: maxOutputTokensForModel,
|
|
2986
3013
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3014
|
+
rejectsSamplingParameters,
|
|
2987
3015
|
isKnownModel
|
|
2988
3016
|
} = getModelCapabilities(this.modelId);
|
|
3017
|
+
if (rejectsSamplingParameters) {
|
|
3018
|
+
if (temperature != null) {
|
|
3019
|
+
warnings.push({
|
|
3020
|
+
type: "unsupported",
|
|
3021
|
+
feature: "temperature",
|
|
3022
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
3023
|
+
});
|
|
3024
|
+
temperature = void 0;
|
|
3025
|
+
}
|
|
3026
|
+
if (topK != null) {
|
|
3027
|
+
warnings.push({
|
|
3028
|
+
type: "unsupported",
|
|
3029
|
+
feature: "topK",
|
|
3030
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
3031
|
+
});
|
|
3032
|
+
topK = void 0;
|
|
3033
|
+
}
|
|
3034
|
+
if (topP != null) {
|
|
3035
|
+
warnings.push({
|
|
3036
|
+
type: "unsupported",
|
|
3037
|
+
feature: "topP",
|
|
3038
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
3039
|
+
});
|
|
3040
|
+
topP = void 0;
|
|
3041
|
+
}
|
|
3042
|
+
}
|
|
2989
3043
|
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
2990
3044
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
2991
3045
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
@@ -3032,6 +3086,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3032
3086
|
const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
|
|
3033
3087
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3034
3088
|
let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
|
|
3089
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
|
|
3035
3090
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3036
3091
|
const baseArgs = {
|
|
3037
3092
|
// model id:
|
|
@@ -3046,14 +3101,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3046
3101
|
...isThinking && {
|
|
3047
3102
|
thinking: {
|
|
3048
3103
|
type: thinkingType,
|
|
3049
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
3104
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
3105
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
3050
3106
|
}
|
|
3051
3107
|
},
|
|
3052
|
-
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3108
|
+
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3053
3109
|
output_config: {
|
|
3054
3110
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
3055
3111
|
effort: anthropicOptions.effort
|
|
3056
3112
|
},
|
|
3113
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
|
|
3114
|
+
task_budget: {
|
|
3115
|
+
type: anthropicOptions.taskBudget.type,
|
|
3116
|
+
total: anthropicOptions.taskBudget.total,
|
|
3117
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
3118
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
},
|
|
3057
3122
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3058
3123
|
format: {
|
|
3059
3124
|
type: "json_schema",
|
|
@@ -3065,10 +3130,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3065
3130
|
...(anthropicOptions == null ? void 0 : anthropicOptions.speed) && {
|
|
3066
3131
|
speed: anthropicOptions.speed
|
|
3067
3132
|
},
|
|
3133
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3134
|
+
inference_geo: anthropicOptions.inferenceGeo
|
|
3135
|
+
},
|
|
3068
3136
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3069
3137
|
cache_control: anthropicOptions.cacheControl
|
|
3070
3138
|
},
|
|
3071
|
-
...((
|
|
3139
|
+
...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
|
|
3072
3140
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3073
3141
|
},
|
|
3074
3142
|
// mcp servers:
|
|
@@ -3238,10 +3306,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3238
3306
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
3239
3307
|
betas.add("effort-2025-11-24");
|
|
3240
3308
|
}
|
|
3309
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
3310
|
+
betas.add("task-budgets-2026-03-13");
|
|
3311
|
+
}
|
|
3241
3312
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3242
3313
|
betas.add("fast-mode-2026-02-01");
|
|
3243
3314
|
}
|
|
3244
|
-
if (stream && ((
|
|
3315
|
+
if (stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true)) {
|
|
3245
3316
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
3246
3317
|
}
|
|
3247
3318
|
const {
|
|
@@ -3280,7 +3351,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3280
3351
|
...betas,
|
|
3281
3352
|
...toolsBetas,
|
|
3282
3353
|
...userSuppliedBetas,
|
|
3283
|
-
...(
|
|
3354
|
+
...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
3284
3355
|
]),
|
|
3285
3356
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3286
3357
|
toolNameMapping,
|
|
@@ -4539,46 +4610,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4539
4610
|
}
|
|
4540
4611
|
};
|
|
4541
4612
|
function getModelCapabilities(modelId) {
|
|
4542
|
-
if (modelId.includes("claude-
|
|
4613
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
4614
|
+
return {
|
|
4615
|
+
maxOutputTokens: 128e3,
|
|
4616
|
+
supportsStructuredOutput: true,
|
|
4617
|
+
rejectsSamplingParameters: true,
|
|
4618
|
+
isKnownModel: true
|
|
4619
|
+
};
|
|
4620
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
4543
4621
|
return {
|
|
4544
4622
|
maxOutputTokens: 128e3,
|
|
4545
4623
|
supportsStructuredOutput: true,
|
|
4624
|
+
rejectsSamplingParameters: false,
|
|
4546
4625
|
isKnownModel: true
|
|
4547
4626
|
};
|
|
4548
4627
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
4549
4628
|
return {
|
|
4550
4629
|
maxOutputTokens: 64e3,
|
|
4551
4630
|
supportsStructuredOutput: true,
|
|
4631
|
+
rejectsSamplingParameters: false,
|
|
4552
4632
|
isKnownModel: true
|
|
4553
4633
|
};
|
|
4554
4634
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
4555
4635
|
return {
|
|
4556
4636
|
maxOutputTokens: 32e3,
|
|
4557
4637
|
supportsStructuredOutput: true,
|
|
4638
|
+
rejectsSamplingParameters: false,
|
|
4558
4639
|
isKnownModel: true
|
|
4559
4640
|
};
|
|
4560
4641
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
4561
4642
|
return {
|
|
4562
4643
|
maxOutputTokens: 64e3,
|
|
4563
4644
|
supportsStructuredOutput: false,
|
|
4645
|
+
rejectsSamplingParameters: false,
|
|
4564
4646
|
isKnownModel: true
|
|
4565
4647
|
};
|
|
4566
4648
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
4567
4649
|
return {
|
|
4568
4650
|
maxOutputTokens: 32e3,
|
|
4569
4651
|
supportsStructuredOutput: false,
|
|
4652
|
+
rejectsSamplingParameters: false,
|
|
4570
4653
|
isKnownModel: true
|
|
4571
4654
|
};
|
|
4572
4655
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
4573
4656
|
return {
|
|
4574
4657
|
maxOutputTokens: 4096,
|
|
4575
4658
|
supportsStructuredOutput: false,
|
|
4659
|
+
rejectsSamplingParameters: false,
|
|
4576
4660
|
isKnownModel: true
|
|
4577
4661
|
};
|
|
4578
4662
|
} else {
|
|
4579
4663
|
return {
|
|
4580
4664
|
maxOutputTokens: 4096,
|
|
4581
4665
|
supportsStructuredOutput: false,
|
|
4666
|
+
rejectsSamplingParameters: false,
|
|
4582
4667
|
isKnownModel: false
|
|
4583
4668
|
};
|
|
4584
4669
|
}
|