@ai-sdk/anthropic 4.0.19 → 4.0.21
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 +17 -4
- package/dist/index.js +177 -70
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +2 -1
- package/dist/internal/index.js +176 -69
- package/dist/internal/index.js.map +1 -1
- package/docs/05-anthropic.mdx +79 -2
- package/package.json +1 -1
- package/src/anthropic-api.ts +24 -1
- package/src/anthropic-language-model-options.ts +64 -20
- package/src/anthropic-language-model.ts +56 -4
- package/src/convert-anthropic-usage.ts +8 -2
- package/src/convert-to-anthropic-prompt.ts +64 -12
- package/src/index.ts +1 -0
package/dist/internal/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ declare class AnthropicFiles implements FilesV4 {
|
|
|
16
16
|
uploadFile({ data, mediaType, filename, }: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult>;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
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-fable-5' | 'claude-sonnet-5' | (string & {});
|
|
19
|
+
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 & {});
|
|
20
20
|
|
|
21
21
|
type AnthropicLanguageModelConfig = {
|
|
22
22
|
provider: string;
|
|
@@ -80,6 +80,7 @@ declare function getModelCapabilities(modelId: string): {
|
|
|
80
80
|
supportsAdaptiveThinking: boolean;
|
|
81
81
|
rejectsSamplingParameters: boolean;
|
|
82
82
|
supportsXhighEffort: boolean;
|
|
83
|
+
rejectsThinkingDisabledAboveHighEffort: boolean;
|
|
83
84
|
isKnownModel: boolean;
|
|
84
85
|
};
|
|
85
86
|
|
package/dist/internal/index.js
CHANGED
|
@@ -433,6 +433,9 @@ var anthropicResponseSchema = lazySchema3(
|
|
|
433
433
|
usage: z3.looseObject({
|
|
434
434
|
input_tokens: z3.number(),
|
|
435
435
|
output_tokens: z3.number(),
|
|
436
|
+
output_tokens_details: z3.object({
|
|
437
|
+
thinking_tokens: z3.number().nullish()
|
|
438
|
+
}).nullish(),
|
|
436
439
|
cache_creation_input_tokens: z3.number().nullish(),
|
|
437
440
|
cache_read_input_tokens: z3.number().nullish(),
|
|
438
441
|
iterations: z3.array(
|
|
@@ -880,6 +883,9 @@ var anthropicChunkSchema = lazySchema3(
|
|
|
880
883
|
usage: z3.looseObject({
|
|
881
884
|
input_tokens: z3.number().nullish(),
|
|
882
885
|
output_tokens: z3.number(),
|
|
886
|
+
output_tokens_details: z3.object({
|
|
887
|
+
thinking_tokens: z3.number().nullish()
|
|
888
|
+
}).nullish(),
|
|
883
889
|
cache_creation_input_tokens: z3.number().nullish(),
|
|
884
890
|
cache_read_input_tokens: z3.number().nullish(),
|
|
885
891
|
iterations: z3.array(
|
|
@@ -966,6 +972,34 @@ var anthropicFilePartProviderOptions = z4.object({
|
|
|
966
972
|
*/
|
|
967
973
|
context: z4.string().optional()
|
|
968
974
|
});
|
|
975
|
+
var anthropicSystemMessageProviderOptions = z4.object({
|
|
976
|
+
/**
|
|
977
|
+
* Mid-conversation tool changes. Adds or removes tools from the
|
|
978
|
+
* conversation's tool set between turns without invalidating the prompt
|
|
979
|
+
* cache.
|
|
980
|
+
*
|
|
981
|
+
* Only supported on system messages that appear mid-conversation (not the
|
|
982
|
+
* initial system prompt). A system message carrying tool changes must come
|
|
983
|
+
* right before an assistant message or at the end of the messages.
|
|
984
|
+
*
|
|
985
|
+
* Tools referenced by a `tool_addition` must be declared in the `tools`
|
|
986
|
+
* option (typically with `deferLoading: true` so they are not loaded until
|
|
987
|
+
* the addition surfaces them). The required
|
|
988
|
+
* `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
|
|
989
|
+
*/
|
|
990
|
+
toolChanges: z4.array(
|
|
991
|
+
z4.discriminatedUnion("type", [
|
|
992
|
+
z4.object({
|
|
993
|
+
type: z4.literal("tool_addition"),
|
|
994
|
+
toolName: z4.string()
|
|
995
|
+
}),
|
|
996
|
+
z4.object({
|
|
997
|
+
type: z4.literal("tool_removal"),
|
|
998
|
+
toolName: z4.string()
|
|
999
|
+
})
|
|
1000
|
+
])
|
|
1001
|
+
).optional()
|
|
1002
|
+
});
|
|
969
1003
|
var anthropicLanguageModelOptions = z4.object({
|
|
970
1004
|
/**
|
|
971
1005
|
* Whether to send reasoning to the model.
|
|
@@ -1112,30 +1146,35 @@ var anthropicLanguageModelOptions = z4.object({
|
|
|
1112
1146
|
*/
|
|
1113
1147
|
inferenceGeo: z4.enum(["us", "global"]).optional(),
|
|
1114
1148
|
/**
|
|
1115
|
-
* Server-side fallback
|
|
1149
|
+
* Server-side fallback configuration.
|
|
1116
1150
|
*
|
|
1117
1151
|
* When the primary model's safety classifiers block a turn, the API
|
|
1118
|
-
* automatically retries it on
|
|
1119
|
-
* `content-filter` finish reason means the
|
|
1120
|
-
*
|
|
1121
|
-
* Each entry is merged into the request as a direct request to that entry's
|
|
1122
|
-
* model, so it must be formatted accordingly: `model` is required, and an
|
|
1123
|
-
* entry may additionally override `max_tokens`, `thinking`, `output_config`,
|
|
1124
|
-
* and `speed` for that attempt only (`speed` additionally requires the speed
|
|
1125
|
-
* beta). The value is passed through to the API as-is.
|
|
1152
|
+
* automatically retries it server-side on a fallback model. A
|
|
1153
|
+
* `content-filter` finish reason means the fallback(s) refused as well.
|
|
1126
1154
|
*
|
|
1127
|
-
*
|
|
1128
|
-
*
|
|
1155
|
+
* - `'default'` (recommended): the API routes the retry to Anthropic's
|
|
1156
|
+
* recommended fallback model based on the refusal category. Requires the
|
|
1157
|
+
* `server-side-fallback-2026-07-01` beta, which is added automatically.
|
|
1158
|
+
* - Array form: an explicit fallback chain. Each entry is merged into the
|
|
1159
|
+
* request as a direct request to that entry's model, so it must be
|
|
1160
|
+
* formatted accordingly: `model` is required, and an entry may
|
|
1161
|
+
* additionally override `max_tokens`, `thinking`, `output_config`, and
|
|
1162
|
+
* `speed` for that attempt only (`speed` additionally requires the speed
|
|
1163
|
+
* beta). The value is passed through to the API as-is, and the
|
|
1164
|
+
* `server-side-fallback-2026-06-01` beta is added automatically.
|
|
1129
1165
|
*/
|
|
1130
|
-
fallbacks: z4.
|
|
1131
|
-
z4.
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1166
|
+
fallbacks: z4.union([
|
|
1167
|
+
z4.literal("default"),
|
|
1168
|
+
z4.array(
|
|
1169
|
+
z4.object({
|
|
1170
|
+
model: z4.string(),
|
|
1171
|
+
max_tokens: z4.number().int().optional(),
|
|
1172
|
+
thinking: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1173
|
+
output_config: z4.record(z4.string(), z4.unknown()).optional(),
|
|
1174
|
+
speed: z4.enum(["fast", "standard"]).optional()
|
|
1175
|
+
})
|
|
1176
|
+
)
|
|
1177
|
+
]).optional(),
|
|
1139
1178
|
/**
|
|
1140
1179
|
* A set of beta features to enable.
|
|
1141
1180
|
* Allow a provider to receive the full `betas` set if it needs it.
|
|
@@ -1916,12 +1955,13 @@ function convertAnthropicUsage({
|
|
|
1916
1955
|
usage,
|
|
1917
1956
|
rawUsage
|
|
1918
1957
|
}) {
|
|
1919
|
-
var _a, _b, _c;
|
|
1958
|
+
var _a, _b, _c, _d, _e;
|
|
1920
1959
|
const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
|
|
1921
1960
|
const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
|
|
1961
|
+
const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
|
|
1922
1962
|
let inputTokens;
|
|
1923
1963
|
let outputTokens;
|
|
1924
|
-
const servedByFallback = (
|
|
1964
|
+
const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
|
|
1925
1965
|
(iter) => iter.type === "fallback_message"
|
|
1926
1966
|
);
|
|
1927
1967
|
if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
|
|
@@ -1955,8 +1995,8 @@ function convertAnthropicUsage({
|
|
|
1955
1995
|
},
|
|
1956
1996
|
outputTokens: {
|
|
1957
1997
|
total: outputTokens,
|
|
1958
|
-
text: void 0,
|
|
1959
|
-
reasoning:
|
|
1998
|
+
text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
|
|
1999
|
+
reasoning: reasoningTokens
|
|
1960
2000
|
},
|
|
1961
2001
|
raw: rawUsage != null ? rawUsage : usage
|
|
1962
2002
|
};
|
|
@@ -2328,7 +2368,7 @@ async function convertToAnthropicPrompt({
|
|
|
2328
2368
|
cacheControlValidator,
|
|
2329
2369
|
toolNameMapping
|
|
2330
2370
|
}) {
|
|
2331
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
2371
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
|
|
2332
2372
|
const betas = /* @__PURE__ */ new Set();
|
|
2333
2373
|
const blocks = groupIntoBlocks(prompt);
|
|
2334
2374
|
const validator = cacheControlValidator || new CacheControlValidator();
|
|
@@ -2369,19 +2409,52 @@ async function convertToAnthropicPrompt({
|
|
|
2369
2409
|
const type = block.type;
|
|
2370
2410
|
switch (type) {
|
|
2371
2411
|
case "system": {
|
|
2372
|
-
const content =
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2412
|
+
const content = [];
|
|
2413
|
+
let toolChangeCount = 0;
|
|
2414
|
+
for (const { content: text, providerOptions } of block.messages) {
|
|
2415
|
+
const systemMessageOptions = await parseProviderOptions({
|
|
2416
|
+
provider: "anthropic",
|
|
2417
|
+
providerOptions,
|
|
2418
|
+
schema: anthropicSystemMessageProviderOptions
|
|
2419
|
+
});
|
|
2420
|
+
const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
|
|
2421
|
+
if (text !== "" || toolChanges.length === 0) {
|
|
2422
|
+
content.push({
|
|
2423
|
+
type: "text",
|
|
2424
|
+
text,
|
|
2425
|
+
cache_control: validator.getCacheControl(providerOptions, {
|
|
2426
|
+
type: "system message",
|
|
2427
|
+
canCache: true
|
|
2428
|
+
})
|
|
2429
|
+
});
|
|
2430
|
+
}
|
|
2431
|
+
for (const toolChange of toolChanges) {
|
|
2432
|
+
toolChangeCount++;
|
|
2433
|
+
content.push({
|
|
2434
|
+
type: toolChange.type,
|
|
2435
|
+
tool: {
|
|
2436
|
+
type: "tool_reference",
|
|
2437
|
+
name: toolNameMapping.toProviderToolName(toolChange.toolName)
|
|
2438
|
+
}
|
|
2439
|
+
});
|
|
2440
|
+
}
|
|
2441
|
+
}
|
|
2442
|
+
if (i === 0 || system == null && toolChangeCount === 0) {
|
|
2443
|
+
if (toolChangeCount > 0) {
|
|
2444
|
+
warnings.push({
|
|
2445
|
+
type: "other",
|
|
2446
|
+
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."
|
|
2447
|
+
});
|
|
2448
|
+
}
|
|
2449
|
+
system = content.filter(
|
|
2450
|
+
(part) => part.type === "text"
|
|
2451
|
+
);
|
|
2382
2452
|
} else {
|
|
2383
2453
|
messages.push({ role: "system", content });
|
|
2384
2454
|
betas.add("mid-conversation-system-2026-04-07");
|
|
2455
|
+
if (toolChangeCount > 0) {
|
|
2456
|
+
betas.add("mid-conversation-tool-changes-2026-07-01");
|
|
2457
|
+
}
|
|
2385
2458
|
}
|
|
2386
2459
|
break;
|
|
2387
2460
|
}
|
|
@@ -2394,10 +2467,10 @@ async function convertToAnthropicPrompt({
|
|
|
2394
2467
|
for (let j = 0; j < content.length; j++) {
|
|
2395
2468
|
const part = content[j];
|
|
2396
2469
|
const isLastPart = j === content.length - 1;
|
|
2397
|
-
const cacheControl = (
|
|
2470
|
+
const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
|
|
2398
2471
|
type: "user message part",
|
|
2399
2472
|
canCache: true
|
|
2400
|
-
})) != null ?
|
|
2473
|
+
})) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2401
2474
|
type: "user message",
|
|
2402
2475
|
canCache: true
|
|
2403
2476
|
}) : void 0;
|
|
@@ -2452,7 +2525,7 @@ async function convertToAnthropicPrompt({
|
|
|
2452
2525
|
media_type: "text/plain",
|
|
2453
2526
|
data: part.data.text
|
|
2454
2527
|
},
|
|
2455
|
-
title: (
|
|
2528
|
+
title: (_c = metadata.title) != null ? _c : part.filename,
|
|
2456
2529
|
...metadata.context && {
|
|
2457
2530
|
context: metadata.context
|
|
2458
2531
|
},
|
|
@@ -2497,7 +2570,7 @@ async function convertToAnthropicPrompt({
|
|
|
2497
2570
|
media_type: "application/pdf",
|
|
2498
2571
|
data: convertToBase64(part.data.data)
|
|
2499
2572
|
},
|
|
2500
|
-
title: (
|
|
2573
|
+
title: (_d = metadata.title) != null ? _d : part.filename,
|
|
2501
2574
|
...metadata.context && {
|
|
2502
2575
|
context: metadata.context
|
|
2503
2576
|
},
|
|
@@ -2525,7 +2598,7 @@ async function convertToAnthropicPrompt({
|
|
|
2525
2598
|
part.data.data
|
|
2526
2599
|
)
|
|
2527
2600
|
},
|
|
2528
|
-
title: (
|
|
2601
|
+
title: (_e = metadata.title) != null ? _e : part.filename,
|
|
2529
2602
|
...metadata.context && {
|
|
2530
2603
|
context: metadata.context
|
|
2531
2604
|
},
|
|
@@ -2555,17 +2628,17 @@ async function convertToAnthropicPrompt({
|
|
|
2555
2628
|
continue;
|
|
2556
2629
|
}
|
|
2557
2630
|
const output = part.output;
|
|
2558
|
-
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (
|
|
2631
|
+
const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_f = output.value.find(
|
|
2559
2632
|
(contentPart) => contentPart.providerOptions != null
|
|
2560
|
-
)) == null ? void 0 :
|
|
2633
|
+
)) == null ? void 0 : _f.providerOptions : void 0;
|
|
2561
2634
|
const isLastPart = i2 === content.length - 1;
|
|
2562
|
-
const cacheControl = (
|
|
2635
|
+
const cacheControl = (_h = (_g = validator.getCacheControl(part.providerOptions, {
|
|
2563
2636
|
type: "tool result part",
|
|
2564
2637
|
canCache: true
|
|
2565
|
-
})) != null ?
|
|
2638
|
+
})) != null ? _g : validator.getCacheControl(outputProviderOptions, {
|
|
2566
2639
|
type: "tool result output",
|
|
2567
2640
|
canCache: true
|
|
2568
|
-
})) != null ?
|
|
2641
|
+
})) != null ? _h : isLastPart ? validator.getCacheControl(message.providerOptions, {
|
|
2569
2642
|
type: "tool result message",
|
|
2570
2643
|
canCache: true
|
|
2571
2644
|
}) : void 0;
|
|
@@ -2671,7 +2744,7 @@ async function convertToAnthropicPrompt({
|
|
|
2671
2744
|
contentValue = output.value;
|
|
2672
2745
|
break;
|
|
2673
2746
|
case "execution-denied":
|
|
2674
|
-
contentValue = (
|
|
2747
|
+
contentValue = (_i = output.reason) != null ? _i : "Tool call execution denied.";
|
|
2675
2748
|
break;
|
|
2676
2749
|
case "json":
|
|
2677
2750
|
case "error-json":
|
|
@@ -2708,16 +2781,16 @@ async function convertToAnthropicPrompt({
|
|
|
2708
2781
|
for (let k = 0; k < content.length; k++) {
|
|
2709
2782
|
const part = content[k];
|
|
2710
2783
|
const isLastContentPart = k === content.length - 1;
|
|
2711
|
-
const cacheControl = (
|
|
2784
|
+
const cacheControl = (_j = validator.getCacheControl(part.providerOptions, {
|
|
2712
2785
|
type: "assistant message part",
|
|
2713
2786
|
canCache: true
|
|
2714
|
-
})) != null ?
|
|
2787
|
+
})) != null ? _j : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
|
|
2715
2788
|
type: "assistant message",
|
|
2716
2789
|
canCache: true
|
|
2717
2790
|
}) : void 0;
|
|
2718
2791
|
switch (part.type) {
|
|
2719
2792
|
case "text": {
|
|
2720
|
-
const textMetadata = (
|
|
2793
|
+
const textMetadata = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
|
|
2721
2794
|
if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
|
|
2722
2795
|
anthropicContent.push({
|
|
2723
2796
|
type: "compaction",
|
|
@@ -2793,10 +2866,10 @@ async function convertToAnthropicPrompt({
|
|
|
2793
2866
|
const providerToolName = toolNameMapping.toProviderToolName(
|
|
2794
2867
|
part.toolName
|
|
2795
2868
|
);
|
|
2796
|
-
const isMcpToolUse = ((
|
|
2869
|
+
const isMcpToolUse = ((_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.type) === "mcp-tool-use";
|
|
2797
2870
|
if (isMcpToolUse) {
|
|
2798
2871
|
mcpToolUseIds.add(part.toolCallId);
|
|
2799
|
-
const serverName = (
|
|
2872
|
+
const serverName = (_o = (_n = part.providerOptions) == null ? void 0 : _n.anthropic) == null ? void 0 : _o.serverName;
|
|
2800
2873
|
if (serverName == null || typeof serverName !== "string") {
|
|
2801
2874
|
warnings.push({
|
|
2802
2875
|
type: "other",
|
|
@@ -2872,7 +2945,7 @@ async function convertToAnthropicPrompt({
|
|
|
2872
2945
|
}
|
|
2873
2946
|
break;
|
|
2874
2947
|
}
|
|
2875
|
-
const callerOptions = (
|
|
2948
|
+
const callerOptions = (_p = part.providerOptions) == null ? void 0 : _p.anthropic;
|
|
2876
2949
|
const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
|
|
2877
2950
|
type: callerOptions.caller.type,
|
|
2878
2951
|
tool_id: callerOptions.caller.toolId
|
|
@@ -2925,7 +2998,7 @@ async function convertToAnthropicPrompt({
|
|
|
2925
2998
|
tool_use_id: part.toolCallId,
|
|
2926
2999
|
content: {
|
|
2927
3000
|
type: "code_execution_tool_result_error",
|
|
2928
|
-
error_code: (
|
|
3001
|
+
error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
|
|
2929
3002
|
},
|
|
2930
3003
|
cache_control: cacheControl
|
|
2931
3004
|
});
|
|
@@ -2936,7 +3009,7 @@ async function convertToAnthropicPrompt({
|
|
|
2936
3009
|
cache_control: cacheControl,
|
|
2937
3010
|
content: {
|
|
2938
3011
|
type: "bash_code_execution_tool_result_error",
|
|
2939
|
-
error_code: (
|
|
3012
|
+
error_code: (_r = errorInfo.errorCode) != null ? _r : "unknown"
|
|
2940
3013
|
}
|
|
2941
3014
|
});
|
|
2942
3015
|
}
|
|
@@ -2969,7 +3042,7 @@ async function convertToAnthropicPrompt({
|
|
|
2969
3042
|
stdout: codeExecutionOutput.stdout,
|
|
2970
3043
|
stderr: codeExecutionOutput.stderr,
|
|
2971
3044
|
return_code: codeExecutionOutput.return_code,
|
|
2972
|
-
content: (
|
|
3045
|
+
content: (_s = codeExecutionOutput.content) != null ? _s : []
|
|
2973
3046
|
},
|
|
2974
3047
|
cache_control: cacheControl
|
|
2975
3048
|
});
|
|
@@ -2987,7 +3060,7 @@ async function convertToAnthropicPrompt({
|
|
|
2987
3060
|
encrypted_stdout: codeExecutionOutput.encrypted_stdout,
|
|
2988
3061
|
stderr: codeExecutionOutput.stderr,
|
|
2989
3062
|
return_code: codeExecutionOutput.return_code,
|
|
2990
|
-
content: (
|
|
3063
|
+
content: (_t = codeExecutionOutput.content) != null ? _t : []
|
|
2991
3064
|
},
|
|
2992
3065
|
cache_control: cacheControl
|
|
2993
3066
|
});
|
|
@@ -3006,7 +3079,7 @@ async function convertToAnthropicPrompt({
|
|
|
3006
3079
|
stdout: codeExecutionOutput.stdout,
|
|
3007
3080
|
stderr: codeExecutionOutput.stderr,
|
|
3008
3081
|
return_code: codeExecutionOutput.return_code,
|
|
3009
|
-
content: (
|
|
3082
|
+
content: (_u = codeExecutionOutput.content) != null ? _u : []
|
|
3010
3083
|
},
|
|
3011
3084
|
cache_control: cacheControl
|
|
3012
3085
|
});
|
|
@@ -3036,7 +3109,7 @@ async function convertToAnthropicPrompt({
|
|
|
3036
3109
|
tool_use_id: part.toolCallId,
|
|
3037
3110
|
content: {
|
|
3038
3111
|
type: "web_fetch_tool_result_error",
|
|
3039
|
-
error_code: (
|
|
3112
|
+
error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
|
|
3040
3113
|
},
|
|
3041
3114
|
cache_control: cacheControl
|
|
3042
3115
|
});
|
|
@@ -3083,7 +3156,7 @@ async function convertToAnthropicPrompt({
|
|
|
3083
3156
|
tool_use_id: part.toolCallId,
|
|
3084
3157
|
content: {
|
|
3085
3158
|
type: "web_search_tool_result_error",
|
|
3086
|
-
error_code: (
|
|
3159
|
+
error_code: (_w = extractErrorValue(output.value).errorCode) != null ? _w : "unavailable"
|
|
3087
3160
|
},
|
|
3088
3161
|
cache_control: cacheControl
|
|
3089
3162
|
});
|
|
@@ -3554,7 +3627,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3554
3627
|
providerOptions,
|
|
3555
3628
|
stream
|
|
3556
3629
|
}) {
|
|
3557
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
3630
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3558
3631
|
const warnings = [];
|
|
3559
3632
|
if (frequencyPenalty != null) {
|
|
3560
3633
|
warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
|
|
@@ -3612,6 +3685,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3612
3685
|
supportsAdaptiveThinking,
|
|
3613
3686
|
rejectsSamplingParameters,
|
|
3614
3687
|
supportsXhighEffort,
|
|
3688
|
+
rejectsThinkingDisabledAboveHighEffort,
|
|
3615
3689
|
isKnownModel
|
|
3616
3690
|
} = getModelCapabilities(this.modelId);
|
|
3617
3691
|
if (!isKnownModel && maxOutputTokens == null) {
|
|
@@ -3715,11 +3789,19 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3715
3789
|
}
|
|
3716
3790
|
}
|
|
3717
3791
|
}
|
|
3718
|
-
|
|
3792
|
+
if (rejectsThinkingDisabledAboveHighEffort && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
|
|
3793
|
+
warnings.push({
|
|
3794
|
+
type: "unsupported",
|
|
3795
|
+
feature: "providerOptions.anthropic.effort",
|
|
3796
|
+
details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
|
|
3797
|
+
});
|
|
3798
|
+
anthropicOptions.effort = "high";
|
|
3799
|
+
}
|
|
3800
|
+
const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
|
|
3719
3801
|
const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
|
|
3720
3802
|
const sendThinking = isThinking || thinkingType === "disabled";
|
|
3721
|
-
let thinkingBudget = thinkingType === "enabled" ? (
|
|
3722
|
-
const thinkingDisplay = thinkingType === "adaptive" ? (
|
|
3803
|
+
let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
|
|
3804
|
+
const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
|
|
3723
3805
|
const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
|
|
3724
3806
|
const baseArgs = {
|
|
3725
3807
|
// model id:
|
|
@@ -3766,13 +3848,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3766
3848
|
...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
|
|
3767
3849
|
inference_geo: anthropicOptions.inferenceGeo
|
|
3768
3850
|
},
|
|
3769
|
-
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
|
|
3851
|
+
...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
|
|
3770
3852
|
fallbacks: anthropicOptions.fallbacks
|
|
3771
3853
|
},
|
|
3772
3854
|
...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
|
|
3773
3855
|
cache_control: anthropicOptions.cacheControl
|
|
3774
3856
|
},
|
|
3775
|
-
...((
|
|
3857
|
+
...((_j = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _j.userId) != null && {
|
|
3776
3858
|
metadata: { user_id: anthropicOptions.metadata.userId }
|
|
3777
3859
|
},
|
|
3778
3860
|
// mcp servers:
|
|
@@ -3948,10 +4030,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3948
4030
|
if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
|
|
3949
4031
|
betas.add("fast-mode-2026-02-01");
|
|
3950
4032
|
}
|
|
3951
|
-
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks)
|
|
4033
|
+
if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
|
|
4034
|
+
betas.add("server-side-fallback-2026-07-01");
|
|
4035
|
+
} else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
|
|
3952
4036
|
betas.add("server-side-fallback-2026-06-01");
|
|
3953
4037
|
}
|
|
3954
|
-
const defaultEagerInputStreaming = stream && ((
|
|
4038
|
+
const defaultEagerInputStreaming = stream && ((_k = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _k : true);
|
|
3955
4039
|
const {
|
|
3956
4040
|
tools: anthropicTools2,
|
|
3957
4041
|
toolChoice: anthropicToolChoice,
|
|
@@ -3990,7 +4074,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
3990
4074
|
...betas,
|
|
3991
4075
|
...toolsBetas,
|
|
3992
4076
|
...userSuppliedBetas,
|
|
3993
|
-
...(
|
|
4077
|
+
...(_l = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _l : []
|
|
3994
4078
|
]),
|
|
3995
4079
|
usesJsonResponseTool: jsonResponseTool != null,
|
|
3996
4080
|
toolNameMapping,
|
|
@@ -5311,6 +5395,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5311
5395
|
usage.input_tokens = value.usage.input_tokens;
|
|
5312
5396
|
}
|
|
5313
5397
|
usage.output_tokens = value.usage.output_tokens;
|
|
5398
|
+
if (value.usage.output_tokens_details != null) {
|
|
5399
|
+
usage.output_tokens_details = value.usage.output_tokens_details;
|
|
5400
|
+
}
|
|
5314
5401
|
if (value.usage.cache_read_input_tokens != null) {
|
|
5315
5402
|
usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
|
|
5316
5403
|
}
|
|
@@ -5430,13 +5517,24 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
|
|
|
5430
5517
|
}
|
|
5431
5518
|
};
|
|
5432
5519
|
function getModelCapabilities(modelId) {
|
|
5433
|
-
if (modelId.includes("claude-opus-
|
|
5520
|
+
if (modelId.includes("claude-opus-5")) {
|
|
5521
|
+
return {
|
|
5522
|
+
maxOutputTokens: 128e3,
|
|
5523
|
+
supportsStructuredOutput: true,
|
|
5524
|
+
supportsAdaptiveThinking: true,
|
|
5525
|
+
rejectsSamplingParameters: true,
|
|
5526
|
+
supportsXhighEffort: true,
|
|
5527
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5528
|
+
isKnownModel: true
|
|
5529
|
+
};
|
|
5530
|
+
} else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
|
|
5434
5531
|
return {
|
|
5435
5532
|
maxOutputTokens: 128e3,
|
|
5436
5533
|
supportsStructuredOutput: true,
|
|
5437
5534
|
supportsAdaptiveThinking: true,
|
|
5438
5535
|
rejectsSamplingParameters: true,
|
|
5439
5536
|
supportsXhighEffort: true,
|
|
5537
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5440
5538
|
isKnownModel: true
|
|
5441
5539
|
};
|
|
5442
5540
|
} else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
|
|
@@ -5446,6 +5544,7 @@ function getModelCapabilities(modelId) {
|
|
|
5446
5544
|
supportsAdaptiveThinking: true,
|
|
5447
5545
|
rejectsSamplingParameters: false,
|
|
5448
5546
|
supportsXhighEffort: false,
|
|
5547
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5449
5548
|
isKnownModel: true
|
|
5450
5549
|
};
|
|
5451
5550
|
} else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
|
|
@@ -5455,6 +5554,7 @@ function getModelCapabilities(modelId) {
|
|
|
5455
5554
|
supportsAdaptiveThinking: false,
|
|
5456
5555
|
rejectsSamplingParameters: false,
|
|
5457
5556
|
supportsXhighEffort: false,
|
|
5557
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5458
5558
|
isKnownModel: true
|
|
5459
5559
|
};
|
|
5460
5560
|
} else if (modelId.includes("claude-opus-4-1")) {
|
|
@@ -5464,6 +5564,7 @@ function getModelCapabilities(modelId) {
|
|
|
5464
5564
|
supportsAdaptiveThinking: false,
|
|
5465
5565
|
rejectsSamplingParameters: false,
|
|
5466
5566
|
supportsXhighEffort: false,
|
|
5567
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5467
5568
|
isKnownModel: true
|
|
5468
5569
|
};
|
|
5469
5570
|
} else if (modelId.includes("claude-sonnet-4-")) {
|
|
@@ -5473,6 +5574,7 @@ function getModelCapabilities(modelId) {
|
|
|
5473
5574
|
supportsAdaptiveThinking: false,
|
|
5474
5575
|
rejectsSamplingParameters: false,
|
|
5475
5576
|
supportsXhighEffort: false,
|
|
5577
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5476
5578
|
isKnownModel: true
|
|
5477
5579
|
};
|
|
5478
5580
|
} else if (modelId.includes("claude-opus-4-")) {
|
|
@@ -5482,6 +5584,7 @@ function getModelCapabilities(modelId) {
|
|
|
5482
5584
|
supportsAdaptiveThinking: false,
|
|
5483
5585
|
rejectsSamplingParameters: false,
|
|
5484
5586
|
supportsXhighEffort: false,
|
|
5587
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5485
5588
|
isKnownModel: true
|
|
5486
5589
|
};
|
|
5487
5590
|
} else if (modelId.includes("claude-3-haiku")) {
|
|
@@ -5491,6 +5594,7 @@ function getModelCapabilities(modelId) {
|
|
|
5491
5594
|
supportsAdaptiveThinking: false,
|
|
5492
5595
|
rejectsSamplingParameters: false,
|
|
5493
5596
|
supportsXhighEffort: false,
|
|
5597
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5494
5598
|
isKnownModel: true
|
|
5495
5599
|
};
|
|
5496
5600
|
} else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
|
|
@@ -5500,6 +5604,7 @@ function getModelCapabilities(modelId) {
|
|
|
5500
5604
|
supportsAdaptiveThinking: false,
|
|
5501
5605
|
rejectsSamplingParameters: false,
|
|
5502
5606
|
supportsXhighEffort: false,
|
|
5607
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5503
5608
|
isKnownModel: false
|
|
5504
5609
|
};
|
|
5505
5610
|
} else if (modelId.includes("claude-")) {
|
|
@@ -5509,6 +5614,7 @@ function getModelCapabilities(modelId) {
|
|
|
5509
5614
|
supportsAdaptiveThinking: true,
|
|
5510
5615
|
rejectsSamplingParameters: true,
|
|
5511
5616
|
supportsXhighEffort: true,
|
|
5617
|
+
rejectsThinkingDisabledAboveHighEffort: true,
|
|
5512
5618
|
isKnownModel: false
|
|
5513
5619
|
};
|
|
5514
5620
|
} else {
|
|
@@ -5518,6 +5624,7 @@ function getModelCapabilities(modelId) {
|
|
|
5518
5624
|
supportsAdaptiveThinking: false,
|
|
5519
5625
|
rejectsSamplingParameters: false,
|
|
5520
5626
|
supportsXhighEffort: false,
|
|
5627
|
+
rejectsThinkingDisabledAboveHighEffort: false,
|
|
5521
5628
|
isKnownModel: false
|
|
5522
5629
|
};
|
|
5523
5630
|
}
|