@ai-sdk/anthropic 3.0.69 → 3.0.71
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 +11 -1
- package/dist/index.d.ts +11 -1
- package/dist/index.js +96 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -21
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +7 -2
- package/dist/internal/index.d.ts +7 -2
- package/dist/internal/index.js +95 -20
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +95 -20
- 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 +67 -5
- package/src/anthropic-messages-options.ts +28 -5
- package/src/anthropic-prepare-tools.ts +11 -2
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.71" : "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 */
|
|
@@ -909,10 +915,11 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
909
915
|
).optional()
|
|
910
916
|
}).optional(),
|
|
911
917
|
/**
|
|
912
|
-
* Whether to enable
|
|
913
|
-
*
|
|
914
|
-
*
|
|
915
|
-
*
|
|
918
|
+
* Whether to enable fine-grained (eager) streaming of tool call inputs
|
|
919
|
+
* and structured outputs for every function tool in the request. When
|
|
920
|
+
* true (the default), each function tool receives a default of
|
|
921
|
+
* `eager_input_streaming: true` unless it explicitly sets
|
|
922
|
+
* `providerOptions.anthropic.eagerInputStreaming`.
|
|
916
923
|
*
|
|
917
924
|
* @default true
|
|
918
925
|
*/
|
|
@@ -920,7 +927,19 @@ var anthropicLanguageModelOptions = z3.object({
|
|
|
920
927
|
/**
|
|
921
928
|
* @default 'high'
|
|
922
929
|
*/
|
|
923
|
-
effort: z3.enum(["low", "medium", "high", "max"]).optional(),
|
|
930
|
+
effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
931
|
+
/**
|
|
932
|
+
* Task budget for agentic turns. Informs the model of the total token budget
|
|
933
|
+
* available for the current task, allowing it to prioritize work and wind down
|
|
934
|
+
* gracefully as the budget is consumed.
|
|
935
|
+
*
|
|
936
|
+
* Advisory only — does not enforce a hard token limit.
|
|
937
|
+
*/
|
|
938
|
+
taskBudget: z3.object({
|
|
939
|
+
type: z3.literal("tokens"),
|
|
940
|
+
total: z3.number().int().min(2e4),
|
|
941
|
+
remaining: z3.number().int().min(0).optional()
|
|
942
|
+
}).optional(),
|
|
924
943
|
/**
|
|
925
944
|
* Enable fast mode for faster inference (2.5x faster output token speeds).
|
|
926
945
|
* Only supported with claude-opus-4-6.
|
|
@@ -1306,9 +1325,10 @@ async function prepareTools({
|
|
|
1306
1325
|
disableParallelToolUse,
|
|
1307
1326
|
cacheControlValidator,
|
|
1308
1327
|
supportsStructuredOutput,
|
|
1309
|
-
supportsStrictTools
|
|
1328
|
+
supportsStrictTools,
|
|
1329
|
+
defaultEagerInputStreaming = false
|
|
1310
1330
|
}) {
|
|
1311
|
-
var _a;
|
|
1331
|
+
var _a, _b;
|
|
1312
1332
|
tools = (tools == null ? void 0 : tools.length) ? tools : void 0;
|
|
1313
1333
|
const toolWarnings = [];
|
|
1314
1334
|
const betas = /* @__PURE__ */ new Set();
|
|
@@ -1325,7 +1345,7 @@ async function prepareTools({
|
|
|
1325
1345
|
canCache: true
|
|
1326
1346
|
});
|
|
1327
1347
|
const anthropicOptions = (_a = tool.providerOptions) == null ? void 0 : _a.anthropic;
|
|
1328
|
-
const eagerInputStreaming = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming;
|
|
1348
|
+
const eagerInputStreaming = (_b = anthropicOptions == null ? void 0 : anthropicOptions.eagerInputStreaming) != null ? _b : defaultEagerInputStreaming;
|
|
1329
1349
|
const deferLoading = anthropicOptions == null ? void 0 : anthropicOptions.deferLoading;
|
|
1330
1350
|
const allowedCallers = anthropicOptions == null ? void 0 : anthropicOptions.allowedCallers;
|
|
1331
1351
|
if (!supportsStrictTools && tool.strict != null) {
|
|
@@ -2938,7 +2958,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2938
2958
|
providerOptions,
|
|
2939
2959
|
stream
|
|
2940
2960
|
}) {
|
|
2941
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
2961
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2942
2962
|
const warnings = [];
|
|
2943
2963
|
if (frequencyPenalty != null) {
|
|
2944
2964
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -2993,8 +3013,35 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
2993
3013
|
const {
|
|
2994
3014
|
maxOutputTokens: maxOutputTokensForModel,
|
|
2995
3015
|
supportsStructuredOutput: modelSupportsStructuredOutput,
|
|
3016
|
+
rejectsSamplingParameters,
|
|
2996
3017
|
isKnownModel
|
|
2997
3018
|
} = getModelCapabilities(this.modelId);
|
|
3019
|
+
if (rejectsSamplingParameters) {
|
|
3020
|
+
if (temperature != null) {
|
|
3021
|
+
warnings.push({
|
|
3022
|
+
type: "unsupported",
|
|
3023
|
+
feature: "temperature",
|
|
3024
|
+
details: `temperature is not supported by ${this.modelId} and will be ignored`
|
|
3025
|
+
});
|
|
3026
|
+
temperature = void 0;
|
|
3027
|
+
}
|
|
3028
|
+
if (topK != null) {
|
|
3029
|
+
warnings.push({
|
|
3030
|
+
type: "unsupported",
|
|
3031
|
+
feature: "topK",
|
|
3032
|
+
details: `topK is not supported by ${this.modelId} and will be ignored`
|
|
3033
|
+
});
|
|
3034
|
+
topK = void 0;
|
|
3035
|
+
}
|
|
3036
|
+
if (topP != null) {
|
|
3037
|
+
warnings.push({
|
|
3038
|
+
type: "unsupported",
|
|
3039
|
+
feature: "topP",
|
|
3040
|
+
details: `topP is not supported by ${this.modelId} and will be ignored`
|
|
3041
|
+
});
|
|
3042
|
+
topP = void 0;
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
2998
3045
|
const isAnthropicModel = isKnownModel || this.modelId.startsWith("claude-");
|
|
2999
3046
|
const supportsStructuredOutput = ((_a = this.config.supportsNativeStructuredOutput) != null ? _a : true) && modelSupportsStructuredOutput;
|
|
3000
3047
|
const supportsStrictTools = ((_b = this.config.supportsStrictTools) != null ? _b : true) && modelSupportsStructuredOutput;
|
|
@@ -3041,6 +3088,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3041
3088
|
const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
|
|
3042
3089
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3043
3090
|
let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
|
|
3091
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
|
|
3044
3092
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3045
3093
|
const baseArgs = {
|
|
3046
3094
|
// model id:
|
|
@@ -3055,14 +3103,24 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3055
3103
|
...isThinking && {
|
|
3056
3104
|
thinking: {
|
|
3057
3105
|
type: thinkingType,
|
|
3058
|
-
...thinkingBudget != null && { budget_tokens: thinkingBudget }
|
|
3106
|
+
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
3107
|
+
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
3059
3108
|
}
|
|
3060
3109
|
},
|
|
3061
|
-
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3110
|
+
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
3062
3111
|
output_config: {
|
|
3063
3112
|
...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
|
|
3064
3113
|
effort: anthropicOptions.effort
|
|
3065
3114
|
},
|
|
3115
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) && {
|
|
3116
|
+
task_budget: {
|
|
3117
|
+
type: anthropicOptions.taskBudget.type,
|
|
3118
|
+
total: anthropicOptions.taskBudget.total,
|
|
3119
|
+
...anthropicOptions.taskBudget.remaining != null && {
|
|
3120
|
+
remaining: anthropicOptions.taskBudget.remaining
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
},
|
|
3066
3124
|
...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
|
|
3067
3125
|
format: {
|
|
3068
3126
|
type: "json_schema",
|
|
@@ -3080,7 +3138,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3080
3138
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3081
3139
|
cache_control: anthropicOptions.cacheControl
|
|
3082
3140
|
},
|
|
3083
|
-
...((
|
|
3141
|
+
...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
|
|
3084
3142
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3085
3143
|
},
|
|
3086
3144
|
// mcp servers:
|
|
@@ -3250,12 +3308,13 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3250
3308
|
if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
|
|
3251
3309
|
betas.add("effort-2025-11-24");
|
|
3252
3310
|
}
|
|
3311
|
+
if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
|
|
3312
|
+
betas.add("task-budgets-2026-03-13");
|
|
3313
|
+
}
|
|
3253
3314
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3254
3315
|
betas.add("fast-mode-2026-02-01");
|
|
3255
3316
|
}
|
|
3256
|
-
|
|
3257
|
-
betas.add("fine-grained-tool-streaming-2025-05-14");
|
|
3258
|
-
}
|
|
3317
|
+
const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
|
|
3259
3318
|
const {
|
|
3260
3319
|
tools: anthropicTools2,
|
|
3261
3320
|
toolChoice: anthropicToolChoice,
|
|
@@ -3268,14 +3327,16 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3268
3327
|
disableParallelToolUse: true,
|
|
3269
3328
|
cacheControlValidator,
|
|
3270
3329
|
supportsStructuredOutput: false,
|
|
3271
|
-
supportsStrictTools
|
|
3330
|
+
supportsStrictTools,
|
|
3331
|
+
defaultEagerInputStreaming
|
|
3272
3332
|
} : {
|
|
3273
3333
|
tools: tools != null ? tools : [],
|
|
3274
3334
|
toolChoice,
|
|
3275
3335
|
disableParallelToolUse: anthropicOptions == null ? void 0 : anthropicOptions.disableParallelToolUse,
|
|
3276
3336
|
cacheControlValidator,
|
|
3277
3337
|
supportsStructuredOutput,
|
|
3278
|
-
supportsStrictTools
|
|
3338
|
+
supportsStrictTools,
|
|
3339
|
+
defaultEagerInputStreaming
|
|
3279
3340
|
}
|
|
3280
3341
|
);
|
|
3281
3342
|
const cacheWarnings = cacheControlValidator.getWarnings();
|
|
@@ -3292,7 +3353,7 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
3292
3353
|
...betas,
|
|
3293
3354
|
...toolsBetas,
|
|
3294
3355
|
...userSuppliedBetas,
|
|
3295
|
-
...(
|
|
3356
|
+
...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
|
|
3296
3357
|
]),
|
|
3297
3358
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3298
3359
|
toolNameMapping,
|
|
@@ -4551,46 +4612,60 @@ var AnthropicMessagesLanguageModel = class {
|
|
|
4551
4612
|
}
|
|
4552
4613
|
};
|
|
4553
4614
|
function getModelCapabilities(modelId) {
|
|
4554
|
-
if (modelId.includes("claude-
|
|
4615
|
+
if (modelId.includes("claude-opus-4-7")) {
|
|
4616
|
+
return {
|
|
4617
|
+
maxOutputTokens: 128e3,
|
|
4618
|
+
supportsStructuredOutput: true,
|
|
4619
|
+
rejectsSamplingParameters: true,
|
|
4620
|
+
isKnownModel: true
|
|
4621
|
+
};
|
|
4622
|
+
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
4555
4623
|
return {
|
|
4556
4624
|
maxOutputTokens: 128e3,
|
|
4557
4625
|
supportsStructuredOutput: true,
|
|
4626
|
+
rejectsSamplingParameters: false,
|
|
4558
4627
|
isKnownModel: true
|
|
4559
4628
|
};
|
|
4560
4629
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
4561
4630
|
return {
|
|
4562
4631
|
maxOutputTokens: 64e3,
|
|
4563
4632
|
supportsStructuredOutput: true,
|
|
4633
|
+
rejectsSamplingParameters: false,
|
|
4564
4634
|
isKnownModel: true
|
|
4565
4635
|
};
|
|
4566
4636
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
4567
4637
|
return {
|
|
4568
4638
|
maxOutputTokens: 32e3,
|
|
4569
4639
|
supportsStructuredOutput: true,
|
|
4640
|
+
rejectsSamplingParameters: false,
|
|
4570
4641
|
isKnownModel: true
|
|
4571
4642
|
};
|
|
4572
4643
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
4573
4644
|
return {
|
|
4574
4645
|
maxOutputTokens: 64e3,
|
|
4575
4646
|
supportsStructuredOutput: false,
|
|
4647
|
+
rejectsSamplingParameters: false,
|
|
4576
4648
|
isKnownModel: true
|
|
4577
4649
|
};
|
|
4578
4650
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
4579
4651
|
return {
|
|
4580
4652
|
maxOutputTokens: 32e3,
|
|
4581
4653
|
supportsStructuredOutput: false,
|
|
4654
|
+
rejectsSamplingParameters: false,
|
|
4582
4655
|
isKnownModel: true
|
|
4583
4656
|
};
|
|
4584
4657
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
4585
4658
|
return {
|
|
4586
4659
|
maxOutputTokens: 4096,
|
|
4587
4660
|
supportsStructuredOutput: false,
|
|
4661
|
+
rejectsSamplingParameters: false,
|
|
4588
4662
|
isKnownModel: true
|
|
4589
4663
|
};
|
|
4590
4664
|
} else {
|
|
4591
4665
|
return {
|
|
4592
4666
|
maxOutputTokens: 4096,
|
|
4593
4667
|
supportsStructuredOutput: false,
|
|
4668
|
+
rejectsSamplingParameters: false,
|
|
4594
4669
|
isKnownModel: false
|
|
4595
4670
|
};
|
|
4596
4671
|
}
|