@ai-sdk/anthropic 4.0.47 → 4.0.49
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 +14 -0
- package/dist/index.d.ts +19 -2
- package/dist/index.js +112 -33
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +10 -3
- package/dist/internal/index.js +111 -32
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +110 -1
- package/package.json +2 -2
- package/src/anthropic-api.ts +4 -0
- package/src/anthropic-language-model-options.ts +52 -17
- package/src/anthropic-language-model.ts +26 -5
- package/src/convert-to-anthropic-prompt.ts +70 -13
package/dist/internal/index.d.ts
CHANGED
|
@@ -26,6 +26,10 @@ type AnthropicCacheControl = {
|
|
|
26
26
|
interface AnthropicSystemMessage {
|
|
27
27
|
role: 'system';
|
|
28
28
|
content: Array<AnthropicTextContent | AnthropicToolChangeContent>;
|
|
29
|
+
clear_at?: 'next_user_message';
|
|
30
|
+
output_config?: {
|
|
31
|
+
effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
|
|
32
|
+
};
|
|
29
33
|
}
|
|
30
34
|
/**
|
|
31
35
|
* Mid-conversation tool change content block. Adds or removes a tool from the
|
|
@@ -753,7 +757,7 @@ type Citation = NonNullable<(InferSchema<typeof anthropicResponseSchema>['conten
|
|
|
753
757
|
type: 'text';
|
|
754
758
|
})['citations']>[number];
|
|
755
759
|
|
|
756
|
-
type AnthropicModelId = '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' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
760
|
+
type AnthropicModelId = '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' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
|
|
757
761
|
|
|
758
762
|
type AnthropicLanguageModelConfig = {
|
|
759
763
|
provider: string;
|
|
@@ -890,9 +894,12 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
|
|
|
890
894
|
effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
|
|
891
895
|
} | undefined;
|
|
892
896
|
thinking?: {
|
|
893
|
-
|
|
897
|
+
block_binding?: {
|
|
898
|
+
prefix_mismatch_behavior: "drop_block";
|
|
899
|
+
} | undefined;
|
|
900
|
+
display?: "omitted" | "summarized" | "updates" | undefined;
|
|
894
901
|
budget_tokens?: number | undefined;
|
|
895
|
-
type
|
|
902
|
+
type?: "enabled" | "adaptive" | "disabled" | undefined;
|
|
896
903
|
} | undefined;
|
|
897
904
|
model: AnthropicModelId;
|
|
898
905
|
max_tokens: number;
|
package/dist/internal/index.js
CHANGED
|
@@ -958,6 +958,20 @@ var anthropicFilePartProviderOptions = z4.object({
|
|
|
958
958
|
context: z4.string().optional()
|
|
959
959
|
});
|
|
960
960
|
var anthropicSystemMessageProviderOptions = z4.object({
|
|
961
|
+
/**
|
|
962
|
+
* Controls when an ephemeral mid-conversation system message is cleared.
|
|
963
|
+
*
|
|
964
|
+
* Only supported on system messages that appear mid-conversation.
|
|
965
|
+
* The required `mid-conversation-system-clear-at-2026-08-21` beta is
|
|
966
|
+
* added automatically.
|
|
967
|
+
*/
|
|
968
|
+
clearAt: z4.literal("next_user_message").optional(),
|
|
969
|
+
/**
|
|
970
|
+
* Sets the model effort for the turn that follows this mid-conversation
|
|
971
|
+
* system message. The required `mid-conversation-effort-2026-08-01` beta
|
|
972
|
+
* is added automatically.
|
|
973
|
+
*/
|
|
974
|
+
effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
|
|
961
975
|
/**
|
|
962
976
|
* Mid-conversation tool changes. Adds or removes tools from the
|
|
963
977
|
* conversation's tool set between turns without invalidating the prompt
|
|
@@ -1006,24 +1020,40 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1006
1020
|
* When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
|
|
1007
1021
|
* Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
|
|
1008
1022
|
*/
|
|
1009
|
-
thinking: z4.
|
|
1010
|
-
z4.
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1023
|
+
thinking: z4.union([
|
|
1024
|
+
z4.discriminatedUnion("type", [
|
|
1025
|
+
z4.object({
|
|
1026
|
+
/** for Sonnet 4.6, Opus 4.6, and newer models */
|
|
1027
|
+
type: z4.literal("adaptive"),
|
|
1028
|
+
/**
|
|
1029
|
+
* Controls whether thinking content is included in the response.
|
|
1030
|
+
* - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
|
|
1031
|
+
* - `"summarized"`: Thinking content is returned.
|
|
1032
|
+
* - `"updates"`: Thinking updates are returned between tool calls.
|
|
1033
|
+
*/
|
|
1034
|
+
display: z4.enum(["omitted", "summarized", "updates"]).optional(),
|
|
1035
|
+
/**
|
|
1036
|
+
* Controls how thinking blocks are bound to an existing thinking
|
|
1037
|
+
* prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
|
|
1038
|
+
*/
|
|
1039
|
+
blockBinding: z4.object({
|
|
1040
|
+
prefixMismatchBehavior: z4.literal("drop_block")
|
|
1041
|
+
}).optional()
|
|
1042
|
+
}),
|
|
1043
|
+
z4.object({
|
|
1044
|
+
/** for models before Opus 4.6, except Sonnet 4.6 still supports it */
|
|
1045
|
+
type: z4.literal("enabled"),
|
|
1046
|
+
budgetTokens: z4.number().optional()
|
|
1047
|
+
}),
|
|
1048
|
+
z4.object({
|
|
1049
|
+
type: z4.literal("disabled")
|
|
1050
|
+
})
|
|
1051
|
+
]),
|
|
1025
1052
|
z4.object({
|
|
1026
|
-
type: z4.
|
|
1053
|
+
type: z4.never().optional(),
|
|
1054
|
+
blockBinding: z4.object({
|
|
1055
|
+
prefixMismatchBehavior: z4.literal("drop_block")
|
|
1056
|
+
})
|
|
1027
1057
|
})
|
|
1028
1058
|
]).optional(),
|
|
1029
1059
|
/**
|
|
@@ -2440,8 +2470,7 @@ async function convertToAnthropicPrompt({
|
|
|
2440
2470
|
const type = block.type;
|
|
2441
2471
|
switch (type) {
|
|
2442
2472
|
case "system": {
|
|
2443
|
-
const
|
|
2444
|
-
let toolChangeCount = 0;
|
|
2473
|
+
const convertedMessages = [];
|
|
2445
2474
|
for (const { content: text, providerOptions } of block.messages) {
|
|
2446
2475
|
const systemMessageOptions = await parseProviderOptions({
|
|
2447
2476
|
provider: "anthropic",
|
|
@@ -2449,7 +2478,8 @@ async function convertToAnthropicPrompt({
|
|
|
2449
2478
|
schema: anthropicSystemMessageProviderOptions
|
|
2450
2479
|
});
|
|
2451
2480
|
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2452
|
-
|
|
2481
|
+
const content = [];
|
|
2482
|
+
if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
|
|
2453
2483
|
content.push({
|
|
2454
2484
|
type: "text",
|
|
2455
2485
|
text,
|
|
@@ -2460,7 +2490,6 @@ async function convertToAnthropicPrompt({
|
|
|
2460
2490
|
});
|
|
2461
2491
|
}
|
|
2462
2492
|
for (const toolChange of toolChanges) {
|
|
2463
|
-
toolChangeCount++;
|
|
2464
2493
|
content.push({
|
|
2465
2494
|
type: toolChange.type,
|
|
2466
2495
|
tool: {
|
|
@@ -2469,22 +2498,60 @@ async function convertToAnthropicPrompt({
|
|
|
2469
2498
|
}
|
|
2470
2499
|
});
|
|
2471
2500
|
}
|
|
2501
|
+
convertedMessages.push({
|
|
2502
|
+
content,
|
|
2503
|
+
clearAt: systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt,
|
|
2504
|
+
effort: systemMessageOptions == null ? void 0 : systemMessageOptions.effort,
|
|
2505
|
+
toolChangeCount: toolChanges.length
|
|
2506
|
+
});
|
|
2472
2507
|
}
|
|
2473
|
-
|
|
2508
|
+
const toolChangeCount = convertedMessages.reduce(
|
|
2509
|
+
(count, message) => count + message.toolChangeCount,
|
|
2510
|
+
0
|
|
2511
|
+
);
|
|
2512
|
+
const hasInlineSystemOptions = convertedMessages.some(
|
|
2513
|
+
(message) => message.clearAt != null || message.effort != null
|
|
2514
|
+
);
|
|
2515
|
+
if (i === 0 || system == null && toolChangeCount === 0 && !hasInlineSystemOptions) {
|
|
2474
2516
|
if (toolChangeCount > 0) {
|
|
2475
2517
|
warnings.push({
|
|
2476
2518
|
type: "other",
|
|
2477
2519
|
message: "tool changes on the initial system message are not supported by Anthropic. Configure the initial tool set via the tools option instead. The tool changes have been ignored."
|
|
2478
2520
|
});
|
|
2479
2521
|
}
|
|
2480
|
-
|
|
2481
|
-
(
|
|
2522
|
+
for (const message of convertedMessages) {
|
|
2523
|
+
if (message.clearAt != null || message.effort != null) {
|
|
2524
|
+
warnings.push({
|
|
2525
|
+
type: "other",
|
|
2526
|
+
message: "clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored."
|
|
2527
|
+
});
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
system = convertedMessages.flatMap(
|
|
2531
|
+
(message) => message.content.filter(
|
|
2532
|
+
(part) => part.type === "text"
|
|
2533
|
+
)
|
|
2482
2534
|
);
|
|
2483
2535
|
} else {
|
|
2484
|
-
messages.push({ role: "system", content });
|
|
2485
2536
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2486
|
-
|
|
2487
|
-
|
|
2537
|
+
for (const message of convertedMessages) {
|
|
2538
|
+
messages.push({
|
|
2539
|
+
role: "system",
|
|
2540
|
+
content: message.content,
|
|
2541
|
+
...message.clearAt != null && { clear_at: message.clearAt },
|
|
2542
|
+
...message.effort != null && {
|
|
2543
|
+
output_config: { effort: message.effort }
|
|
2544
|
+
}
|
|
2545
|
+
});
|
|
2546
|
+
if (message.toolChangeCount > 0) {
|
|
2547
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2548
|
+
}
|
|
2549
|
+
if (message.clearAt != null) {
|
|
2550
|
+
betas.add("mid-conversation-system-clear-at-2026-08-21");
|
|
2551
|
+
}
|
|
2552
|
+
if (message.effort != null) {
|
|
2553
|
+
betas.add("mid-conversation-effort-2026-08-01");
|
|
2554
|
+
}
|
|
2488
2555
|
}
|
|
2489
2556
|
}
|
|
2490
2557
|
break;
|
|
@@ -3905,7 +3972,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3905
3972
|
}
|
|
3906
3973
|
const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
|
|
3907
3974
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3908
|
-
const
|
|
3975
|
+
const thinkingBlockBinding = (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
|
|
3976
|
+
const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
|
|
3909
3977
|
let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
|
|
3910
3978
|
const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
|
|
3911
3979
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
@@ -3921,9 +3989,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3921
3989
|
// provider specific settings:
|
|
3922
3990
|
...sendThinking && {
|
|
3923
3991
|
thinking: {
|
|
3924
|
-
type: thinkingType,
|
|
3992
|
+
...thinkingType != null && { type: thinkingType },
|
|
3925
3993
|
...thinkingBudget != null && { budget_tokens: thinkingBudget },
|
|
3926
|
-
...thinkingDisplay != null && { display: thinkingDisplay }
|
|
3994
|
+
...thinkingDisplay != null && { display: thinkingDisplay },
|
|
3995
|
+
...thinkingBlockBinding != null && {
|
|
3996
|
+
block_binding: {
|
|
3997
|
+
prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
|
|
3998
|
+
}
|
|
3999
|
+
}
|
|
3927
4000
|
}
|
|
3928
4001
|
},
|
|
3929
4002
|
...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
|
|
@@ -4139,6 +4212,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
4139
4212
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
4140
4213
|
betas.add("fast-mode-2026-02-01");
|
|
4141
4214
|
}
|
|
4215
|
+
if (thinkingDisplay === "updates") {
|
|
4216
|
+
betas.add("thinking-display-updates-2026-08-18");
|
|
4217
|
+
}
|
|
4218
|
+
if (thinkingBlockBinding != null) {
|
|
4219
|
+
betas.add("thinking-binding-controls-2026-08-01");
|
|
4220
|
+
}
|
|
4142
4221
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
4143
4222
|
betas.add("server-side-fallback-2026-07-01");
|
|
4144
4223
|
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
@@ -5723,7 +5802,7 @@ function getModelCapabilities(modelId) {
|
|
|
5723
5802
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5724
5803
|
isKnownModel: true
|
|
5725
5804
|
};
|
|
5726
|
-
} else if (
|
|
5805
|
+
} else if (/claude-sonnet-4(?:-|@)/.test(modelId)) {
|
|
5727
5806
|
return {
|
|
5728
5807
|
maxOutputTokens: 64e3,
|
|
5729
5808
|
supportsStructuredOutput: false,
|
|
@@ -5733,7 +5812,7 @@ function getModelCapabilities(modelId) {
|
|
|
5733
5812
|
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5734
5813
|
isKnownModel: true
|
|
5735
5814
|
};
|
|
5736
|
-
} else if (
|
|
5815
|
+
} else if (/claude-opus-4(?:-|@)/.test(modelId)) {
|
|
5737
5816
|
return {
|
|
5738
5817
|
maxOutputTokens: 32e3,
|
|
5739
5818
|
supportsStructuredOutput: false,
|