@ai-sdk/anthropic 3.0.69 → 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 +6 -0
- package/dist/index.d.mts +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +83 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +83 -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 +82 -9
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +82 -9
- package/dist/internal/index.mjs.map +1 -1
- package/docs/05-anthropic.mdx +72 -2
- package/package.json +1 -1
- package/src/anthropic-messages-language-model.ts +63 -1
- package/src/anthropic-messages-options.ts +23 -1
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { 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;
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
|
|
|
2
2
|
import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
|
|
3
3
|
import { 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;
|
package/dist/internal/index.js
CHANGED
|
@@ -837,7 +837,13 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
837
837
|
thinking: import_v43.z.discriminatedUnion("type", [
|
|
838
838
|
import_v43.z.object({
|
|
839
839
|
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
840
|
-
type: import_v43.z.literal("adaptive")
|
|
840
|
+
type: import_v43.z.literal("adaptive"),
|
|
841
|
+
/**
|
|
842
|
+
* Controls whether thinking content is included in the response.
|
|
843
|
+
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
844
|
+
* - `"summarized"`: Thinking content is returned. Required to see reasoning output.
|
|
845
|
+
*/
|
|
846
|
+
display: import_v43.z.enum(["omitted", "summarized"]).optional()
|
|
841
847
|
}),
|
|
842
848
|
import_v43.z.object({
|
|
843
849
|
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
@@ -917,7 +923,19 @@ var anthropicLanguageModelOptions = import_v43.z.object({
|
|
|
917
923
|
/**
|
|
918
924
|
* @default 'high'
|
|
919
925
|
*/
|
|
920
|
-
effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional(),
|
|
926
|
+
effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
927
|
+
/**
|
|
928
|
+
* Task budget for agentic turns. Informs the model of the total token budget
|
|
929
|
+
* available for the current task, allowing it to prioritize work and wind down
|
|
930
|
+
* gracefully as the budget is consumed.
|
|
931
|
+
*
|
|
932
|
+
* Advisory only — does not enforce a hard token limit.
|
|
933
|
+
*/
|
|
934
|
+
taskBudget: import_v43.z.object({
|
|
935
|
+
type: import_v43.z.literal("tokens"),
|
|
936
|
+
total: import_v43.z.number().int().min(2e4),
|
|
937
|
+
remaining: import_v43.z.number().int().min(0).optional()
|
|
938
|
+
}).optional(),
|
|
921
939
|
/**
|
|
922
940
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
923
941
|
* Only supported with claude-opus-4-6.
|
|
@@ -2893,7 +2911,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2893
2911
|
providerOptions,
|
|
2894
2912
|
stream
|
|
2895
2913
|
}) {
|
|
2896
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2914
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2897
2915
|
const warnings = [];
|
|
2898
2916
|
if (frequencyPenalty != null) {
|
|
2899
2917
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2948,8 +2966,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2948
2966
|
const {
|
|
2949
2967
|
maxOutputTokens: maxOutputTokensForModel,
|
|
2950
2968
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
2969
|
+
rejectsSamplingParameters,
|
|
2951
2970
|
isKnownModel
|
|
2952
2971
|
} = getModelCapabilities(this.modelId);
|
|
2972
|
+
if (rejectsSamplingParameters) {
|
|
2973
|
+
if (temperature != null) {
|
|
2974
|
+
warnings.push({
|
|
2975
|
+
type: "unsupported",
|
|
2976
|
+
feature: "temperature",
|
|
2977
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
2978
|
+
});
|
|
2979
|
+
temperature = void 0;
|
|
2980
|
+
}
|
|
2981
|
+
if (topK != null) {
|
|
2982
|
+
warnings.push({
|
|
2983
|
+
type: "unsupported",
|
|
2984
|
+
feature: "topK",
|
|
2985
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
2986
|
+
});
|
|
2987
|
+
topK = void 0;
|
|
2988
|
+
}
|
|
2989
|
+
if (topP != null) {
|
|
2990
|
+
warnings.push({
|
|
2991
|
+
type: "unsupported",
|
|
2992
|
+
feature: "topP",
|
|
2993
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
2994
|
+
});
|
|
2995
|
+
topP = void 0;
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2953
2998
|
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
2954
2999
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
2955
3000
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
@@ -2996,6 +3041,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2996
3041
|
const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
|
|
2997
3042
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
2998
3043
|
let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
|
|
3044
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
|
|
2999
3045
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3000
3046
|
const baseArgs = {
|
|
3001
3047
|
// model id:
|
|
@@ -3010,14 +3056,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3010
3056
|
...isThinking && {
|
|
3011
3057
|
thinking: {
|
|
3012
3058
|
type: thinkingType,
|
|
3013
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
3059
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
3060
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
3014
3061
|
}
|
|
3015
3062
|
},
|
|
3016
|
-
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3063
|
+
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3017
3064
|
output_config: {
|
|
3018
3065
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
3019
3066
|
effort: anthropicOptions.effort
|
|
3020
3067
|
},
|
|
3068
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
|
|
3069
|
+
task_budget: {
|
|
3070
|
+
type: anthropicOptions.taskBudget.type,
|
|
3071
|
+
total: anthropicOptions.taskBudget.total,
|
|
3072
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
3073
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
3074
|
+
}
|
|
3075
|
+
}
|
|
3076
|
+
},
|
|
3021
3077
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3022
3078
|
format: {
|
|
3023
3079
|
type: "json_schema",
|
|
@@ -3035,7 +3091,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3035
3091
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3036
3092
|
cache_control: anthropicOptions.cacheControl
|
|
3037
3093
|
},
|
|
3038
|
-
...((
|
|
3094
|
+
...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
|
|
3039
3095
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3040
3096
|
},
|
|
3041
3097
|
// mcp servers:
|
|
@@ -3205,10 +3261,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3205
3261
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
3206
3262
|
betas.add("effort-2025-11-24");
|
|
3207
3263
|
}
|
|
3264
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
3265
|
+
betas.add("task-budgets-2026-03-13");
|
|
3266
|
+
}
|
|
3208
3267
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3209
3268
|
betas.add("fast-mode-2026-02-01");
|
|
3210
3269
|
}
|
|
3211
|
-
if (stream && ((
|
|
3270
|
+
if (stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true)) {
|
|
3212
3271
|
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
3213
3272
|
}
|
|
3214
3273
|
const {
|
|
@@ -3247,7 +3306,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3247
3306
|
...betas,
|
|
3248
3307
|
...toolsBetas,
|
|
3249
3308
|
...userSuppliedBetas,
|
|
3250
|
-
...(
|
|
3309
|
+
...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
3251
3310
|
]),
|
|
3252
3311
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3253
3312
|
toolNameMapping,
|
|
@@ -4506,46 +4565,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4506
4565
|
}
|
|
4507
4566
|
};
|
|
4508
4567
|
function getModelCapabilities(modelId) {
|
|
4509
|
-
if (modelId.includes("claude-
|
|
4568
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
4569
|
+
return {
|
|
4570
|
+
maxOutputTokens: 128e3,
|
|
4571
|
+
supportsStructuredOutput: true,
|
|
4572
|
+
rejectsSamplingParameters: true,
|
|
4573
|
+
isKnownModel: true
|
|
4574
|
+
};
|
|
4575
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
4510
4576
|
return {
|
|
4511
4577
|
maxOutputTokens: 128e3,
|
|
4512
4578
|
supportsStructuredOutput: true,
|
|
4579
|
+
rejectsSamplingParameters: false,
|
|
4513
4580
|
isKnownModel: true
|
|
4514
4581
|
};
|
|
4515
4582
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
4516
4583
|
return {
|
|
4517
4584
|
maxOutputTokens: 64e3,
|
|
4518
4585
|
supportsStructuredOutput: true,
|
|
4586
|
+
rejectsSamplingParameters: false,
|
|
4519
4587
|
isKnownModel: true
|
|
4520
4588
|
};
|
|
4521
4589
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
4522
4590
|
return {
|
|
4523
4591
|
maxOutputTokens: 32e3,
|
|
4524
4592
|
supportsStructuredOutput: true,
|
|
4593
|
+
rejectsSamplingParameters: false,
|
|
4525
4594
|
isKnownModel: true
|
|
4526
4595
|
};
|
|
4527
4596
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
4528
4597
|
return {
|
|
4529
4598
|
maxOutputTokens: 64e3,
|
|
4530
4599
|
supportsStructuredOutput: false,
|
|
4600
|
+
rejectsSamplingParameters: false,
|
|
4531
4601
|
isKnownModel: true
|
|
4532
4602
|
};
|
|
4533
4603
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
4534
4604
|
return {
|
|
4535
4605
|
maxOutputTokens: 32e3,
|
|
4536
4606
|
supportsStructuredOutput: false,
|
|
4607
|
+
rejectsSamplingParameters: false,
|
|
4537
4608
|
isKnownModel: true
|
|
4538
4609
|
};
|
|
4539
4610
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
4540
4611
|
return {
|
|
4541
4612
|
maxOutputTokens: 4096,
|
|
4542
4613
|
supportsStructuredOutput: false,
|
|
4614
|
+
rejectsSamplingParameters: false,
|
|
4543
4615
|
isKnownModel: true
|
|
4544
4616
|
};
|
|
4545
4617
|
} else {
|
|
4546
4618
|
return {
|
|
4547
4619
|
maxOutputTokens: 4096,
|
|
4548
4620
|
supportsStructuredOutput: false,
|
|
4621
|
+
rejectsSamplingParameters: false,
|
|
4549
4622
|
isKnownModel: false
|
|
4550
4623
|
};
|
|
4551
4624
|
}
|