@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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.21
4
+
5
+ ### Patch Changes
6
+
7
+ - e29788d: fix(anthropic): report thinking tokens as reasoning token usage
8
+
9
+ ## 4.0.20
10
+
11
+ ### Patch Changes
12
+
13
+ - cbdc990: feat (provider/anthropic): support fallbacks 'default' mode, which routes safety classifier refusals to Anthropic's recommended fallback model (adds the server-side-fallback-2026-07-01 beta automatically)
14
+ - cbdc990: feat (provider/anthropic): support mid-conversation tool changes via the toolChanges system message provider option, emitting tool_addition/tool_removal content blocks and the mid-conversation-tool-changes-2026-07-01 beta
15
+ - cbdc990: feat (provider/anthropic): add claude-opus-5 model id with frontier-tier capabilities (128k output tokens, structured output, adaptive thinking, xhigh effort, sampling parameter rejection, thinking-disabled only at effort high or below)
16
+
3
17
  ## 4.0.19
4
18
 
5
19
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -183,7 +183,20 @@ interface AnthropicMessageMetadata {
183
183
  } | null;
184
184
  }
185
185
 
186
- 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 & {});
186
+ 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 & {});
187
+ /**
188
+ * Anthropic provider options for system messages.
189
+ */
190
+ declare const anthropicSystemMessageProviderOptions: z.ZodObject<{
191
+ toolChanges: z.ZodOptional<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
192
+ type: z.ZodLiteral<"tool_addition">;
193
+ toolName: z.ZodString;
194
+ }, z.core.$strip>, z.ZodObject<{
195
+ type: z.ZodLiteral<"tool_removal">;
196
+ toolName: z.ZodString;
197
+ }, z.core.$strip>]>>>;
198
+ }, z.core.$strip>;
199
+ type AnthropicSystemMessageProviderOptions = z.infer<typeof anthropicSystemMessageProviderOptions>;
187
200
  declare const anthropicLanguageModelOptions: z.ZodObject<{
188
201
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
189
202
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -254,7 +267,7 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
254
267
  us: "us";
255
268
  global: "global";
256
269
  }>>;
257
- fallbacks: z.ZodOptional<z.ZodArray<z.ZodObject<{
270
+ fallbacks: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<"default">, z.ZodArray<z.ZodObject<{
258
271
  model: z.ZodString;
259
272
  max_tokens: z.ZodOptional<z.ZodNumber>;
260
273
  thinking: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
@@ -263,7 +276,7 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
263
276
  fast: "fast";
264
277
  standard: "standard";
265
278
  }>>;
266
- }, z.core.$strip>>>;
279
+ }, z.core.$strip>>]>>;
267
280
  anthropicBeta: z.ZodOptional<z.ZodArray<z.ZodString>>;
268
281
  contextManagement: z.ZodOptional<z.ZodObject<{
269
282
  edits: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -1284,4 +1297,4 @@ declare function forwardAnthropicContainerIdFromLastStep({ steps, }: {
1284
1297
 
1285
1298
  declare const VERSION: string;
1286
1299
 
1287
- export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
1300
+ export { type AnthropicLanguageModelOptions, type AnthropicMessageMetadata, type AnthropicProvider, type AnthropicLanguageModelOptions as AnthropicProviderOptions, type AnthropicProviderSettings, type AnthropicSystemMessageProviderOptions, type AnthropicToolOptions, type AnthropicUsageIteration, VERSION, anthropic, createAnthropic, forwardAnthropicContainerIdFromLastStep };
package/dist/index.js CHANGED
@@ -447,6 +447,9 @@ var anthropicResponseSchema = lazySchema3(
447
447
  usage: z3.looseObject({
448
448
  input_tokens: z3.number(),
449
449
  output_tokens: z3.number(),
450
+ output_tokens_details: z3.object({
451
+ thinking_tokens: z3.number().nullish()
452
+ }).nullish(),
450
453
  cache_creation_input_tokens: z3.number().nullish(),
451
454
  cache_read_input_tokens: z3.number().nullish(),
452
455
  iterations: z3.array(
@@ -894,6 +897,9 @@ var anthropicChunkSchema = lazySchema3(
894
897
  usage: z3.looseObject({
895
898
  input_tokens: z3.number().nullish(),
896
899
  output_tokens: z3.number(),
900
+ output_tokens_details: z3.object({
901
+ thinking_tokens: z3.number().nullish()
902
+ }).nullish(),
897
903
  cache_creation_input_tokens: z3.number().nullish(),
898
904
  cache_read_input_tokens: z3.number().nullish(),
899
905
  iterations: z3.array(
@@ -980,6 +986,34 @@ var anthropicFilePartProviderOptions = z4.object({
980
986
  */
981
987
  context: z4.string().optional()
982
988
  });
989
+ var anthropicSystemMessageProviderOptions = z4.object({
990
+ /**
991
+ * Mid-conversation tool changes. Adds or removes tools from the
992
+ * conversation's tool set between turns without invalidating the prompt
993
+ * cache.
994
+ *
995
+ * Only supported on system messages that appear mid-conversation (not the
996
+ * initial system prompt). A system message carrying tool changes must come
997
+ * right before an assistant message or at the end of the messages.
998
+ *
999
+ * Tools referenced by a `tool_addition` must be declared in the `tools`
1000
+ * option (typically with `deferLoading: true` so they are not loaded until
1001
+ * the addition surfaces them). The required
1002
+ * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
1003
+ */
1004
+ toolChanges: z4.array(
1005
+ z4.discriminatedUnion("type", [
1006
+ z4.object({
1007
+ type: z4.literal("tool_addition"),
1008
+ toolName: z4.string()
1009
+ }),
1010
+ z4.object({
1011
+ type: z4.literal("tool_removal"),
1012
+ toolName: z4.string()
1013
+ })
1014
+ ])
1015
+ ).optional()
1016
+ });
983
1017
  var anthropicLanguageModelOptions = z4.object({
984
1018
  /**
985
1019
  * Whether to send reasoning to the model.
@@ -1126,30 +1160,35 @@ var anthropicLanguageModelOptions = z4.object({
1126
1160
  */
1127
1161
  inferenceGeo: z4.enum(["us", "global"]).optional(),
1128
1162
  /**
1129
- * Server-side fallback chain.
1163
+ * Server-side fallback configuration.
1130
1164
  *
1131
1165
  * When the primary model's safety classifiers block a turn, the API
1132
- * automatically retries it on the next model in the chain, server-side. A
1133
- * `content-filter` finish reason means the entire chain refused.
1134
- *
1135
- * Each entry is merged into the request as a direct request to that entry's
1136
- * model, so it must be formatted accordingly: `model` is required, and an
1137
- * entry may additionally override `max_tokens`, `thinking`, `output_config`,
1138
- * and `speed` for that attempt only (`speed` additionally requires the speed
1139
- * beta). The value is passed through to the API as-is.
1166
+ * automatically retries it server-side on a fallback model. A
1167
+ * `content-filter` finish reason means the fallback(s) refused as well.
1140
1168
  *
1141
- * The required `server-side-fallback-2026-06-01` beta is added automatically
1142
- * when this option is set.
1169
+ * - `'default'` (recommended): the API routes the retry to Anthropic's
1170
+ * recommended fallback model based on the refusal category. Requires the
1171
+ * `server-side-fallback-2026-07-01` beta, which is added automatically.
1172
+ * - Array form: an explicit fallback chain. Each entry is merged into the
1173
+ * request as a direct request to that entry's model, so it must be
1174
+ * formatted accordingly: `model` is required, and an entry may
1175
+ * additionally override `max_tokens`, `thinking`, `output_config`, and
1176
+ * `speed` for that attempt only (`speed` additionally requires the speed
1177
+ * beta). The value is passed through to the API as-is, and the
1178
+ * `server-side-fallback-2026-06-01` beta is added automatically.
1143
1179
  */
1144
- fallbacks: z4.array(
1145
- z4.object({
1146
- model: z4.string(),
1147
- max_tokens: z4.number().int().optional(),
1148
- thinking: z4.record(z4.string(), z4.unknown()).optional(),
1149
- output_config: z4.record(z4.string(), z4.unknown()).optional(),
1150
- speed: z4.enum(["fast", "standard"]).optional()
1151
- })
1152
- ).optional(),
1180
+ fallbacks: z4.union([
1181
+ z4.literal("default"),
1182
+ z4.array(
1183
+ z4.object({
1184
+ model: z4.string(),
1185
+ max_tokens: z4.number().int().optional(),
1186
+ thinking: z4.record(z4.string(), z4.unknown()).optional(),
1187
+ output_config: z4.record(z4.string(), z4.unknown()).optional(),
1188
+ speed: z4.enum(["fast", "standard"]).optional()
1189
+ })
1190
+ )
1191
+ ]).optional(),
1153
1192
  /**
1154
1193
  * A set of beta features to enable.
1155
1194
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -1930,12 +1969,13 @@ function convertAnthropicUsage({
1930
1969
  usage,
1931
1970
  rawUsage
1932
1971
  }) {
1933
- var _a, _b, _c;
1972
+ var _a, _b, _c, _d, _e;
1934
1973
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1935
1974
  const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1975
+ const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
1936
1976
  let inputTokens;
1937
1977
  let outputTokens;
1938
- const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some(
1978
+ const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
1939
1979
  (iter) => iter.type === "fallback_message"
1940
1980
  );
1941
1981
  if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
@@ -1969,8 +2009,8 @@ function convertAnthropicUsage({
1969
2009
  },
1970
2010
  outputTokens: {
1971
2011
  total: outputTokens,
1972
- text: void 0,
1973
- reasoning: void 0
2012
+ text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
2013
+ reasoning: reasoningTokens
1974
2014
  },
1975
2015
  raw: rawUsage != null ? rawUsage : usage
1976
2016
  };
@@ -2342,7 +2382,7 @@ async function convertToAnthropicPrompt({
2342
2382
  cacheControlValidator,
2343
2383
  toolNameMapping
2344
2384
  }) {
2345
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2385
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
2346
2386
  const betas = /* @__PURE__ */ new Set();
2347
2387
  const blocks = groupIntoBlocks(prompt);
2348
2388
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2383,19 +2423,52 @@ async function convertToAnthropicPrompt({
2383
2423
  const type = block.type;
2384
2424
  switch (type) {
2385
2425
  case "system": {
2386
- const content = block.messages.map(({ content: content2, providerOptions }) => ({
2387
- type: "text",
2388
- text: content2,
2389
- cache_control: validator.getCacheControl(providerOptions, {
2390
- type: "system message",
2391
- canCache: true
2392
- })
2393
- }));
2394
- if (system == null) {
2395
- system = content;
2426
+ const content = [];
2427
+ let toolChangeCount = 0;
2428
+ for (const { content: text, providerOptions } of block.messages) {
2429
+ const systemMessageOptions = await parseProviderOptions({
2430
+ provider: "anthropic",
2431
+ providerOptions,
2432
+ schema: anthropicSystemMessageProviderOptions
2433
+ });
2434
+ const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2435
+ if (text !== "" || toolChanges.length === 0) {
2436
+ content.push({
2437
+ type: "text",
2438
+ text,
2439
+ cache_control: validator.getCacheControl(providerOptions, {
2440
+ type: "system message",
2441
+ canCache: true
2442
+ })
2443
+ });
2444
+ }
2445
+ for (const toolChange of toolChanges) {
2446
+ toolChangeCount++;
2447
+ content.push({
2448
+ type: toolChange.type,
2449
+ tool: {
2450
+ type: "tool_reference",
2451
+ name: toolNameMapping.toProviderToolName(toolChange.toolName)
2452
+ }
2453
+ });
2454
+ }
2455
+ }
2456
+ if (i === 0 || system == null && toolChangeCount === 0) {
2457
+ if (toolChangeCount > 0) {
2458
+ warnings.push({
2459
+ type: "other",
2460
+ 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."
2461
+ });
2462
+ }
2463
+ system = content.filter(
2464
+ (part) => part.type === "text"
2465
+ );
2396
2466
  } else {
2397
2467
  messages.push({ role: "system", content });
2398
2468
  betas.add("mid-conversation-system-2026-04-07");
2469
+ if (toolChangeCount > 0) {
2470
+ betas.add("mid-conversation-tool-changes-2026-07-01");
2471
+ }
2399
2472
  }
2400
2473
  break;
2401
2474
  }
@@ -2408,10 +2481,10 @@ async function convertToAnthropicPrompt({
2408
2481
  for (let j = 0; j < content.length; j++) {
2409
2482
  const part = content[j];
2410
2483
  const isLastPart = j === content.length - 1;
2411
- const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
2484
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
2412
2485
  type: "user message part",
2413
2486
  canCache: true
2414
- })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
2487
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
2415
2488
  type: "user message",
2416
2489
  canCache: true
2417
2490
  }) : void 0;
@@ -2466,7 +2539,7 @@ async function convertToAnthropicPrompt({
2466
2539
  media_type: "text/plain",
2467
2540
  data: part.data.text
2468
2541
  },
2469
- title: (_b = metadata.title) != null ? _b : part.filename,
2542
+ title: (_c = metadata.title) != null ? _c : part.filename,
2470
2543
  ...metadata.context && {
2471
2544
  context: metadata.context
2472
2545
  },
@@ -2511,7 +2584,7 @@ async function convertToAnthropicPrompt({
2511
2584
  media_type: "application/pdf",
2512
2585
  data: convertToBase64(part.data.data)
2513
2586
  },
2514
- title: (_c = metadata.title) != null ? _c : part.filename,
2587
+ title: (_d = metadata.title) != null ? _d : part.filename,
2515
2588
  ...metadata.context && {
2516
2589
  context: metadata.context
2517
2590
  },
@@ -2539,7 +2612,7 @@ async function convertToAnthropicPrompt({
2539
2612
  part.data.data
2540
2613
  )
2541
2614
  },
2542
- title: (_d = metadata.title) != null ? _d : part.filename,
2615
+ title: (_e = metadata.title) != null ? _e : part.filename,
2543
2616
  ...metadata.context && {
2544
2617
  context: metadata.context
2545
2618
  },
@@ -2569,17 +2642,17 @@ async function convertToAnthropicPrompt({
2569
2642
  continue;
2570
2643
  }
2571
2644
  const output = part.output;
2572
- const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
2645
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_f = output.value.find(
2573
2646
  (contentPart) => contentPart.providerOptions != null
2574
- )) == null ? void 0 : _e.providerOptions : void 0;
2647
+ )) == null ? void 0 : _f.providerOptions : void 0;
2575
2648
  const isLastPart = i2 === content.length - 1;
2576
- const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
2649
+ const cacheControl = (_h = (_g = validator.getCacheControl(part.providerOptions, {
2577
2650
  type: "tool result part",
2578
2651
  canCache: true
2579
- })) != null ? _f : validator.getCacheControl(outputProviderOptions, {
2652
+ })) != null ? _g : validator.getCacheControl(outputProviderOptions, {
2580
2653
  type: "tool result output",
2581
2654
  canCache: true
2582
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
2655
+ })) != null ? _h : isLastPart ? validator.getCacheControl(message.providerOptions, {
2583
2656
  type: "tool result message",
2584
2657
  canCache: true
2585
2658
  }) : void 0;
@@ -2685,7 +2758,7 @@ async function convertToAnthropicPrompt({
2685
2758
  contentValue = output.value;
2686
2759
  break;
2687
2760
  case "execution-denied":
2688
- contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
2761
+ contentValue = (_i = output.reason) != null ? _i : "Tool call execution denied.";
2689
2762
  break;
2690
2763
  case "json":
2691
2764
  case "error-json":
@@ -2722,16 +2795,16 @@ async function convertToAnthropicPrompt({
2722
2795
  for (let k = 0; k < content.length; k++) {
2723
2796
  const part = content[k];
2724
2797
  const isLastContentPart = k === content.length - 1;
2725
- const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
2798
+ const cacheControl = (_j = validator.getCacheControl(part.providerOptions, {
2726
2799
  type: "assistant message part",
2727
2800
  canCache: true
2728
- })) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2801
+ })) != null ? _j : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2729
2802
  type: "assistant message",
2730
2803
  canCache: true
2731
2804
  }) : void 0;
2732
2805
  switch (part.type) {
2733
2806
  case "text": {
2734
- const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
2807
+ const textMetadata = (_k = part.providerOptions) == null ? void 0 : _k.anthropic;
2735
2808
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
2736
2809
  anthropicContent.push({
2737
2810
  type: "compaction",
@@ -2807,10 +2880,10 @@ async function convertToAnthropicPrompt({
2807
2880
  const providerToolName = toolNameMapping.toProviderToolName(
2808
2881
  part.toolName
2809
2882
  );
2810
- const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
2883
+ const isMcpToolUse = ((_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.type) === "mcp-tool-use";
2811
2884
  if (isMcpToolUse) {
2812
2885
  mcpToolUseIds.add(part.toolCallId);
2813
- const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
2886
+ const serverName = (_o = (_n = part.providerOptions) == null ? void 0 : _n.anthropic) == null ? void 0 : _o.serverName;
2814
2887
  if (serverName == null || typeof serverName !== "string") {
2815
2888
  warnings.push({
2816
2889
  type: "other",
@@ -2886,7 +2959,7 @@ async function convertToAnthropicPrompt({
2886
2959
  }
2887
2960
  break;
2888
2961
  }
2889
- const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
2962
+ const callerOptions = (_p = part.providerOptions) == null ? void 0 : _p.anthropic;
2890
2963
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2891
2964
  type: callerOptions.caller.type,
2892
2965
  tool_id: callerOptions.caller.toolId
@@ -2939,7 +3012,7 @@ async function convertToAnthropicPrompt({
2939
3012
  tool_use_id: part.toolCallId,
2940
3013
  content: {
2941
3014
  type: "code_execution_tool_result_error",
2942
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
3015
+ error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
2943
3016
  },
2944
3017
  cache_control: cacheControl
2945
3018
  });
@@ -2950,7 +3023,7 @@ async function convertToAnthropicPrompt({
2950
3023
  cache_control: cacheControl,
2951
3024
  content: {
2952
3025
  type: "bash_code_execution_tool_result_error",
2953
- error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
3026
+ error_code: (_r = errorInfo.errorCode) != null ? _r : "unknown"
2954
3027
  }
2955
3028
  });
2956
3029
  }
@@ -2983,7 +3056,7 @@ async function convertToAnthropicPrompt({
2983
3056
  stdout: codeExecutionOutput.stdout,
2984
3057
  stderr: codeExecutionOutput.stderr,
2985
3058
  return_code: codeExecutionOutput.return_code,
2986
- content: (_r = codeExecutionOutput.content) != null ? _r : []
3059
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2987
3060
  },
2988
3061
  cache_control: cacheControl
2989
3062
  });
@@ -3001,7 +3074,7 @@ async function convertToAnthropicPrompt({
3001
3074
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
3002
3075
  stderr: codeExecutionOutput.stderr,
3003
3076
  return_code: codeExecutionOutput.return_code,
3004
- content: (_s = codeExecutionOutput.content) != null ? _s : []
3077
+ content: (_t = codeExecutionOutput.content) != null ? _t : []
3005
3078
  },
3006
3079
  cache_control: cacheControl
3007
3080
  });
@@ -3020,7 +3093,7 @@ async function convertToAnthropicPrompt({
3020
3093
  stdout: codeExecutionOutput.stdout,
3021
3094
  stderr: codeExecutionOutput.stderr,
3022
3095
  return_code: codeExecutionOutput.return_code,
3023
- content: (_t = codeExecutionOutput.content) != null ? _t : []
3096
+ content: (_u = codeExecutionOutput.content) != null ? _u : []
3024
3097
  },
3025
3098
  cache_control: cacheControl
3026
3099
  });
@@ -3050,7 +3123,7 @@ async function convertToAnthropicPrompt({
3050
3123
  tool_use_id: part.toolCallId,
3051
3124
  content: {
3052
3125
  type: "web_fetch_tool_result_error",
3053
- error_code: (_u = extractErrorValue(output.value).errorCode) != null ? _u : "unavailable"
3126
+ error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3054
3127
  },
3055
3128
  cache_control: cacheControl
3056
3129
  });
@@ -3097,7 +3170,7 @@ async function convertToAnthropicPrompt({
3097
3170
  tool_use_id: part.toolCallId,
3098
3171
  content: {
3099
3172
  type: "web_search_tool_result_error",
3100
- error_code: (_v = extractErrorValue(output.value).errorCode) != null ? _v : "unavailable"
3173
+ error_code: (_w = extractErrorValue(output.value).errorCode) != null ? _w : "unavailable"
3101
3174
  },
3102
3175
  cache_control: cacheControl
3103
3176
  });
@@ -3568,7 +3641,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3568
3641
  providerOptions,
3569
3642
  stream
3570
3643
  }) {
3571
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3644
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
3572
3645
  const warnings = [];
3573
3646
  if (frequencyPenalty != null) {
3574
3647
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3626,6 +3699,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3626
3699
  supportsAdaptiveThinking,
3627
3700
  rejectsSamplingParameters,
3628
3701
  supportsXhighEffort,
3702
+ rejectsThinkingDisabledAboveHighEffort,
3629
3703
  isKnownModel
3630
3704
  } = getModelCapabilities(this.modelId);
3631
3705
  if (!isKnownModel && maxOutputTokens == null) {
@@ -3729,11 +3803,19 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3729
3803
  }
3730
3804
  }
3731
3805
  }
3732
- const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3806
+ if (rejectsThinkingDisabledAboveHighEffort && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3807
+ warnings.push({
3808
+ type: "unsupported",
3809
+ feature: "providerOptions.anthropic.effort",
3810
+ details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
3811
+ });
3812
+ anthropicOptions.effort = "high";
3813
+ }
3814
+ const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
3733
3815
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3734
3816
  const sendThinking = isThinking || thinkingType === "disabled";
3735
- let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3736
- const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3817
+ let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
3818
+ const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
3737
3819
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3738
3820
  const baseArgs = {
3739
3821
  // model id:
@@ -3780,13 +3862,13 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3780
3862
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3781
3863
  inference_geo: anthropicOptions.inferenceGeo
3782
3864
  },
3783
- ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
3865
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
3784
3866
  fallbacks: anthropicOptions.fallbacks
3785
3867
  },
3786
3868
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3787
3869
  cache_control: anthropicOptions.cacheControl
3788
3870
  },
3789
- ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3871
+ ...((_j = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _j.userId) != null && {
3790
3872
  metadata: { user_id: anthropicOptions.metadata.userId }
3791
3873
  },
3792
3874
  // mcp servers:
@@ -3962,10 +4044,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3962
4044
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3963
4045
  betas.add("fast-mode-2026-02-01");
3964
4046
  }
3965
- if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
4047
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4048
+ betas.add("server-side-fallback-2026-07-01");
4049
+ } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3966
4050
  betas.add("server-side-fallback-2026-06-01");
3967
4051
  }
3968
- const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
4052
+ const defaultEagerInputStreaming = stream && ((_k = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _k : true);
3969
4053
  const {
3970
4054
  tools: anthropicTools2,
3971
4055
  toolChoice: anthropicToolChoice,
@@ -4004,7 +4088,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4004
4088
  ...betas,
4005
4089
  ...toolsBetas,
4006
4090
  ...userSuppliedBetas,
4007
- ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
4091
+ ...(_l = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _l : []
4008
4092
  ]),
4009
4093
  usesJsonResponseTool: jsonResponseTool != null,
4010
4094
  toolNameMapping,
@@ -5325,6 +5409,9 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5325
5409
  usage.input_tokens = value.usage.input_tokens;
5326
5410
  }
5327
5411
  usage.output_tokens = value.usage.output_tokens;
5412
+ if (value.usage.output_tokens_details != null) {
5413
+ usage.output_tokens_details = value.usage.output_tokens_details;
5414
+ }
5328
5415
  if (value.usage.cache_read_input_tokens != null) {
5329
5416
  usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
5330
5417
  }
@@ -5444,13 +5531,24 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
5444
5531
  }
5445
5532
  };
5446
5533
  function getModelCapabilities(modelId) {
5447
- if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5534
+ if (modelId.includes("claude-opus-5")) {
5535
+ return {
5536
+ maxOutputTokens: 128e3,
5537
+ supportsStructuredOutput: true,
5538
+ supportsAdaptiveThinking: true,
5539
+ rejectsSamplingParameters: true,
5540
+ supportsXhighEffort: true,
5541
+ rejectsThinkingDisabledAboveHighEffort: true,
5542
+ isKnownModel: true
5543
+ };
5544
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5448
5545
  return {
5449
5546
  maxOutputTokens: 128e3,
5450
5547
  supportsStructuredOutput: true,
5451
5548
  supportsAdaptiveThinking: true,
5452
5549
  rejectsSamplingParameters: true,
5453
5550
  supportsXhighEffort: true,
5551
+ rejectsThinkingDisabledAboveHighEffort: false,
5454
5552
  isKnownModel: true
5455
5553
  };
5456
5554
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -5460,6 +5558,7 @@ function getModelCapabilities(modelId) {
5460
5558
  supportsAdaptiveThinking: true,
5461
5559
  rejectsSamplingParameters: false,
5462
5560
  supportsXhighEffort: false,
5561
+ rejectsThinkingDisabledAboveHighEffort: false,
5463
5562
  isKnownModel: true
5464
5563
  };
5465
5564
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -5469,6 +5568,7 @@ function getModelCapabilities(modelId) {
5469
5568
  supportsAdaptiveThinking: false,
5470
5569
  rejectsSamplingParameters: false,
5471
5570
  supportsXhighEffort: false,
5571
+ rejectsThinkingDisabledAboveHighEffort: false,
5472
5572
  isKnownModel: true
5473
5573
  };
5474
5574
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -5478,6 +5578,7 @@ function getModelCapabilities(modelId) {
5478
5578
  supportsAdaptiveThinking: false,
5479
5579
  rejectsSamplingParameters: false,
5480
5580
  supportsXhighEffort: false,
5581
+ rejectsThinkingDisabledAboveHighEffort: false,
5481
5582
  isKnownModel: true
5482
5583
  };
5483
5584
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -5487,6 +5588,7 @@ function getModelCapabilities(modelId) {
5487
5588
  supportsAdaptiveThinking: false,
5488
5589
  rejectsSamplingParameters: false,
5489
5590
  supportsXhighEffort: false,
5591
+ rejectsThinkingDisabledAboveHighEffort: false,
5490
5592
  isKnownModel: true
5491
5593
  };
5492
5594
  } else if (modelId.includes("claude-opus-4-")) {
@@ -5496,6 +5598,7 @@ function getModelCapabilities(modelId) {
5496
5598
  supportsAdaptiveThinking: false,
5497
5599
  rejectsSamplingParameters: false,
5498
5600
  supportsXhighEffort: false,
5601
+ rejectsThinkingDisabledAboveHighEffort: false,
5499
5602
  isKnownModel: true
5500
5603
  };
5501
5604
  } else if (modelId.includes("claude-3-haiku")) {
@@ -5505,6 +5608,7 @@ function getModelCapabilities(modelId) {
5505
5608
  supportsAdaptiveThinking: false,
5506
5609
  rejectsSamplingParameters: false,
5507
5610
  supportsXhighEffort: false,
5611
+ rejectsThinkingDisabledAboveHighEffort: false,
5508
5612
  isKnownModel: true
5509
5613
  };
5510
5614
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -5514,6 +5618,7 @@ function getModelCapabilities(modelId) {
5514
5618
  supportsAdaptiveThinking: false,
5515
5619
  rejectsSamplingParameters: false,
5516
5620
  supportsXhighEffort: false,
5621
+ rejectsThinkingDisabledAboveHighEffort: false,
5517
5622
  isKnownModel: false
5518
5623
  };
5519
5624
  } else if (modelId.includes("claude-")) {
@@ -5523,6 +5628,7 @@ function getModelCapabilities(modelId) {
5523
5628
  supportsAdaptiveThinking: true,
5524
5629
  rejectsSamplingParameters: true,
5525
5630
  supportsXhighEffort: true,
5631
+ rejectsThinkingDisabledAboveHighEffort: true,
5526
5632
  isKnownModel: false
5527
5633
  };
5528
5634
  } else {
@@ -5532,6 +5638,7 @@ function getModelCapabilities(modelId) {
5532
5638
  supportsAdaptiveThinking: false,
5533
5639
  rejectsSamplingParameters: false,
5534
5640
  supportsXhighEffort: false,
5641
+ rejectsThinkingDisabledAboveHighEffort: false,
5535
5642
  isKnownModel: false
5536
5643
  };
5537
5644
  }
@@ -6365,7 +6472,7 @@ var AnthropicSkills = class {
6365
6472
  };
6366
6473
 
6367
6474
  // src/version.ts
6368
- var VERSION = true ? "4.0.19" : "0.0.0-test";
6475
+ var VERSION = true ? "4.0.21" : "0.0.0-test";
6369
6476
 
6370
6477
  // src/anthropic-provider.ts
6371
6478
  var ANTHROPIC_API_URL = "https://api.anthropic.com";