@ai-sdk/anthropic 3.0.101 → 3.0.103

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/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.101" : "0.0.0-test";
15
+ var VERSION = true ? "3.0.103" : "0.0.0-test";
16
16
 
17
17
  // src/anthropic-messages-language-model.ts
18
18
  import {
@@ -365,6 +365,9 @@ var anthropicMessagesResponseSchema = lazySchema2(
365
365
  usage: z2.looseObject({
366
366
  input_tokens: z2.number(),
367
367
  output_tokens: z2.number(),
368
+ output_tokens_details: z2.object({
369
+ thinking_tokens: z2.number().nullish()
370
+ }).nullish(),
368
371
  cache_creation_input_tokens: z2.number().nullish(),
369
372
  cache_read_input_tokens: z2.number().nullish(),
370
373
  iterations: z2.array(
@@ -812,6 +815,9 @@ var anthropicMessagesChunkSchema = lazySchema2(
812
815
  usage: z2.looseObject({
813
816
  input_tokens: z2.number().nullish(),
814
817
  output_tokens: z2.number(),
818
+ output_tokens_details: z2.object({
819
+ thinking_tokens: z2.number().nullish()
820
+ }).nullish(),
815
821
  cache_creation_input_tokens: z2.number().nullish(),
816
822
  cache_read_input_tokens: z2.number().nullish(),
817
823
  iterations: z2.array(
@@ -893,6 +899,34 @@ var anthropicFilePartProviderOptions = z3.object({
893
899
  */
894
900
  context: z3.string().optional()
895
901
  });
902
+ var anthropicSystemMessageProviderOptions = z3.object({
903
+ /**
904
+ * Mid-conversation tool changes. Adds or removes tools from the
905
+ * conversation's tool set between turns without invalidating the prompt
906
+ * cache.
907
+ *
908
+ * Only supported on system messages that appear mid-conversation (not the
909
+ * initial system prompt). A system message carrying tool changes must come
910
+ * right before an assistant message or at the end of the messages.
911
+ *
912
+ * Tools referenced by a `tool_addition` must be declared in the `tools`
913
+ * option (typically with `deferLoading: true` so they are not loaded until
914
+ * the addition surfaces them). The required
915
+ * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
916
+ */
917
+ toolChanges: z3.array(
918
+ z3.discriminatedUnion("type", [
919
+ z3.object({
920
+ type: z3.literal("tool_addition"),
921
+ toolName: z3.string()
922
+ }),
923
+ z3.object({
924
+ type: z3.literal("tool_removal"),
925
+ toolName: z3.string()
926
+ })
927
+ ])
928
+ ).optional()
929
+ });
896
930
  var anthropicLanguageModelOptions = z3.object({
897
931
  /**
898
932
  * Whether to send reasoning to the model.
@@ -1032,30 +1066,35 @@ var anthropicLanguageModelOptions = z3.object({
1032
1066
  */
1033
1067
  inferenceGeo: z3.enum(["us", "global"]).optional(),
1034
1068
  /**
1035
- * Server-side fallback chain.
1069
+ * Server-side fallback configuration.
1036
1070
  *
1037
1071
  * When the primary model's safety classifiers block a turn, the API
1038
- * automatically retries it on the next model in the chain, server-side. A
1039
- * `content-filter` finish reason means the entire chain refused.
1040
- *
1041
- * Each entry is merged into the request as a direct request to that entry's
1042
- * model, so it must be formatted accordingly: `model` is required, and an
1043
- * entry may additionally override `max_tokens`, `thinking`, `output_config`,
1044
- * and `speed` for that attempt only (`speed` additionally requires the speed
1045
- * beta). The value is passed through to the API as-is.
1072
+ * automatically retries it server-side on a fallback model. A
1073
+ * `content-filter` finish reason means the fallback(s) refused as well.
1046
1074
  *
1047
- * The required `server-side-fallback-2026-06-01` beta is added automatically
1048
- * when this option is set.
1075
+ * - `'default'` (recommended): the API routes the retry to Anthropic's
1076
+ * recommended fallback model based on the refusal category. Requires the
1077
+ * `server-side-fallback-2026-07-01` beta, which is added automatically.
1078
+ * - Array form: an explicit fallback chain. Each entry is merged into the
1079
+ * request as a direct request to that entry's model, so it must be
1080
+ * formatted accordingly: `model` is required, and an entry may
1081
+ * additionally override `max_tokens`, `thinking`, `output_config`, and
1082
+ * `speed` for that attempt only (`speed` additionally requires the speed
1083
+ * beta). The value is passed through to the API as-is, and the
1084
+ * `server-side-fallback-2026-06-01` beta is added automatically.
1049
1085
  */
1050
- fallbacks: z3.array(
1051
- z3.object({
1052
- model: z3.string(),
1053
- max_tokens: z3.number().int().optional(),
1054
- thinking: z3.record(z3.string(), z3.unknown()).optional(),
1055
- output_config: z3.record(z3.string(), z3.unknown()).optional(),
1056
- speed: z3.enum(["fast", "standard"]).optional()
1057
- })
1058
- ).optional(),
1086
+ fallbacks: z3.union([
1087
+ z3.literal("default"),
1088
+ z3.array(
1089
+ z3.object({
1090
+ model: z3.string(),
1091
+ max_tokens: z3.number().int().optional(),
1092
+ thinking: z3.record(z3.string(), z3.unknown()).optional(),
1093
+ output_config: z3.record(z3.string(), z3.unknown()).optional(),
1094
+ speed: z3.enum(["fast", "standard"]).optional()
1095
+ })
1096
+ )
1097
+ ]).optional(),
1059
1098
  /**
1060
1099
  * A set of beta features to enable.
1061
1100
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -1836,12 +1875,13 @@ function convertAnthropicMessagesUsage({
1836
1875
  usage,
1837
1876
  rawUsage
1838
1877
  }) {
1839
- var _a, _b, _c;
1878
+ var _a, _b, _c, _d, _e;
1840
1879
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1841
1880
  const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1881
+ const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
1842
1882
  let inputTokens;
1843
1883
  let outputTokens;
1844
- const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some(
1884
+ const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
1845
1885
  (iter) => iter.type === "fallback_message"
1846
1886
  );
1847
1887
  if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
@@ -1875,8 +1915,8 @@ function convertAnthropicMessagesUsage({
1875
1915
  },
1876
1916
  outputTokens: {
1877
1917
  total: outputTokens,
1878
- text: void 0,
1879
- reasoning: void 0
1918
+ text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
1919
+ reasoning: reasoningTokens
1880
1920
  },
1881
1921
  raw: rawUsage != null ? rawUsage : usage
1882
1922
  };
@@ -2265,7 +2305,7 @@ async function convertToAnthropicMessagesPrompt({
2265
2305
  cacheControlValidator,
2266
2306
  toolNameMapping
2267
2307
  }) {
2268
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2308
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2269
2309
  const betas = /* @__PURE__ */ new Set();
2270
2310
  const blocks = groupIntoBlocks(prompt);
2271
2311
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2297,19 +2337,52 @@ async function convertToAnthropicMessagesPrompt({
2297
2337
  const type = block.type;
2298
2338
  switch (type) {
2299
2339
  case "system": {
2300
- const content = block.messages.map(({ content: content2, providerOptions }) => ({
2301
- type: "text",
2302
- text: content2,
2303
- cache_control: validator.getCacheControl(providerOptions, {
2304
- type: "system message",
2305
- canCache: true
2306
- })
2307
- }));
2308
- if (system == null) {
2309
- system = content;
2340
+ const content = [];
2341
+ let toolChangeCount = 0;
2342
+ for (const { content: text, providerOptions } of block.messages) {
2343
+ const systemMessageOptions = await parseProviderOptions({
2344
+ provider: "anthropic",
2345
+ providerOptions,
2346
+ schema: anthropicSystemMessageProviderOptions
2347
+ });
2348
+ const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2349
+ if (text !== "" || toolChanges.length === 0) {
2350
+ content.push({
2351
+ type: "text",
2352
+ text,
2353
+ cache_control: validator.getCacheControl(providerOptions, {
2354
+ type: "system message",
2355
+ canCache: true
2356
+ })
2357
+ });
2358
+ }
2359
+ for (const toolChange of toolChanges) {
2360
+ toolChangeCount++;
2361
+ content.push({
2362
+ type: toolChange.type,
2363
+ tool: {
2364
+ type: "tool_reference",
2365
+ name: toolNameMapping.toProviderToolName(toolChange.toolName)
2366
+ }
2367
+ });
2368
+ }
2369
+ }
2370
+ if (i === 0 || system == null && toolChangeCount === 0) {
2371
+ if (toolChangeCount > 0) {
2372
+ warnings.push({
2373
+ type: "other",
2374
+ 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."
2375
+ });
2376
+ }
2377
+ system = content.filter(
2378
+ (part) => part.type === "text"
2379
+ );
2310
2380
  } else {
2311
2381
  messages.push({ role: "system", content });
2312
2382
  betas.add("mid-conversation-system-2026-04-07");
2383
+ if (toolChangeCount > 0) {
2384
+ betas.add("mid-conversation-tool-changes-2026-07-01");
2385
+ }
2313
2386
  }
2314
2387
  break;
2315
2388
  }
@@ -2322,10 +2395,10 @@ async function convertToAnthropicMessagesPrompt({
2322
2395
  for (let j = 0; j < content.length; j++) {
2323
2396
  const part = content[j];
2324
2397
  const isLastPart = j === content.length - 1;
2325
- const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
2398
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
2326
2399
  type: "user message part",
2327
2400
  canCache: true
2328
- })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
2401
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
2329
2402
  type: "user message",
2330
2403
  canCache: true
2331
2404
  }) : void 0;
@@ -2370,7 +2443,7 @@ async function convertToAnthropicMessagesPrompt({
2370
2443
  media_type: "application/pdf",
2371
2444
  data: convertToBase64(part.data)
2372
2445
  },
2373
- title: (_b = metadata.title) != null ? _b : part.filename,
2446
+ title: (_c = metadata.title) != null ? _c : part.filename,
2374
2447
  ...metadata.context && { context: metadata.context },
2375
2448
  ...enableCitations && {
2376
2449
  citations: { enabled: true }
@@ -2394,7 +2467,7 @@ async function convertToAnthropicMessagesPrompt({
2394
2467
  media_type: "text/plain",
2395
2468
  data: convertToString(part.data)
2396
2469
  },
2397
- title: (_c = metadata.title) != null ? _c : part.filename,
2470
+ title: (_d = metadata.title) != null ? _d : part.filename,
2398
2471
  ...metadata.context && { context: metadata.context },
2399
2472
  ...enableCitations && {
2400
2473
  citations: { enabled: true }
@@ -2419,17 +2492,17 @@ async function convertToAnthropicMessagesPrompt({
2419
2492
  continue;
2420
2493
  }
2421
2494
  const output = part.output;
2422
- const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find(
2495
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
2423
2496
  (contentPart) => contentPart.providerOptions != null
2424
- )) == null ? void 0 : _d.providerOptions : void 0;
2497
+ )) == null ? void 0 : _e.providerOptions : void 0;
2425
2498
  const isLastPart = i2 === content.length - 1;
2426
- const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
2499
+ const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
2427
2500
  type: "tool result part",
2428
2501
  canCache: true
2429
- })) != null ? _e : validator.getCacheControl(outputProviderOptions, {
2502
+ })) != null ? _f : validator.getCacheControl(outputProviderOptions, {
2430
2503
  type: "tool result output",
2431
2504
  canCache: true
2432
- })) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
2505
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
2433
2506
  type: "tool result message",
2434
2507
  canCache: true
2435
2508
  }) : void 0;
@@ -2519,7 +2592,7 @@ async function convertToAnthropicMessagesPrompt({
2519
2592
  contentValue = output.value;
2520
2593
  break;
2521
2594
  case "execution-denied":
2522
- contentValue = (_g = output.reason) != null ? _g : "Tool call execution denied.";
2595
+ contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
2523
2596
  break;
2524
2597
  case "json":
2525
2598
  case "error-json":
@@ -2556,16 +2629,16 @@ async function convertToAnthropicMessagesPrompt({
2556
2629
  for (let k = 0; k < content.length; k++) {
2557
2630
  const part = content[k];
2558
2631
  const isLastContentPart = k === content.length - 1;
2559
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
2632
+ const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
2560
2633
  type: "assistant message part",
2561
2634
  canCache: true
2562
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2635
+ })) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2563
2636
  type: "assistant message",
2564
2637
  canCache: true
2565
2638
  }) : void 0;
2566
2639
  switch (part.type) {
2567
2640
  case "text": {
2568
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
2641
+ const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
2569
2642
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
2570
2643
  anthropicContent.push({
2571
2644
  type: "compaction",
@@ -2641,10 +2714,10 @@ async function convertToAnthropicMessagesPrompt({
2641
2714
  const providerToolName = toolNameMapping.toProviderToolName(
2642
2715
  part.toolName
2643
2716
  );
2644
- const isMcpToolUse = ((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use";
2717
+ const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
2645
2718
  if (isMcpToolUse) {
2646
2719
  mcpToolUseIds.add(part.toolCallId);
2647
- const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
2720
+ const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
2648
2721
  if (serverName == null || typeof serverName !== "string") {
2649
2722
  warnings.push({
2650
2723
  type: "other",
@@ -2720,7 +2793,7 @@ async function convertToAnthropicMessagesPrompt({
2720
2793
  }
2721
2794
  break;
2722
2795
  }
2723
- const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
2796
+ const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
2724
2797
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2725
2798
  type: callerOptions.caller.type,
2726
2799
  tool_id: callerOptions.caller.toolId
@@ -2773,7 +2846,7 @@ async function convertToAnthropicMessagesPrompt({
2773
2846
  tool_use_id: part.toolCallId,
2774
2847
  content: {
2775
2848
  type: "code_execution_tool_result_error",
2776
- error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
2849
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2777
2850
  },
2778
2851
  cache_control: cacheControl
2779
2852
  });
@@ -2784,7 +2857,7 @@ async function convertToAnthropicMessagesPrompt({
2784
2857
  cache_control: cacheControl,
2785
2858
  content: {
2786
2859
  type: "bash_code_execution_tool_result_error",
2787
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2860
+ error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
2788
2861
  }
2789
2862
  });
2790
2863
  }
@@ -2817,7 +2890,7 @@ async function convertToAnthropicMessagesPrompt({
2817
2890
  stdout: codeExecutionOutput.stdout,
2818
2891
  stderr: codeExecutionOutput.stderr,
2819
2892
  return_code: codeExecutionOutput.return_code,
2820
- content: (_q = codeExecutionOutput.content) != null ? _q : []
2893
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
2821
2894
  },
2822
2895
  cache_control: cacheControl
2823
2896
  });
@@ -2835,7 +2908,7 @@ async function convertToAnthropicMessagesPrompt({
2835
2908
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
2836
2909
  stderr: codeExecutionOutput.stderr,
2837
2910
  return_code: codeExecutionOutput.return_code,
2838
- content: (_r = codeExecutionOutput.content) != null ? _r : []
2911
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2839
2912
  },
2840
2913
  cache_control: cacheControl
2841
2914
  });
@@ -2854,7 +2927,7 @@ async function convertToAnthropicMessagesPrompt({
2854
2927
  stdout: codeExecutionOutput.stdout,
2855
2928
  stderr: codeExecutionOutput.stderr,
2856
2929
  return_code: codeExecutionOutput.return_code,
2857
- content: (_s = codeExecutionOutput.content) != null ? _s : []
2930
+ content: (_t = codeExecutionOutput.content) != null ? _t : []
2858
2931
  },
2859
2932
  cache_control: cacheControl
2860
2933
  });
@@ -2884,7 +2957,7 @@ async function convertToAnthropicMessagesPrompt({
2884
2957
  tool_use_id: part.toolCallId,
2885
2958
  content: {
2886
2959
  type: "web_fetch_tool_result_error",
2887
- error_code: (_t = (await extractErrorValue(output.value)).errorCode) != null ? _t : "unavailable"
2960
+ error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2888
2961
  },
2889
2962
  cache_control: cacheControl
2890
2963
  });
@@ -2931,7 +3004,7 @@ async function convertToAnthropicMessagesPrompt({
2931
3004
  tool_use_id: part.toolCallId,
2932
3005
  content: {
2933
3006
  type: "web_search_tool_result_error",
2934
- error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
3007
+ error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
2935
3008
  },
2936
3009
  cache_control: cacheControl
2937
3010
  });
@@ -3389,7 +3462,7 @@ var AnthropicMessagesLanguageModel = class {
3389
3462
  providerOptions,
3390
3463
  stream
3391
3464
  }) {
3392
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3465
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3393
3466
  const warnings = [];
3394
3467
  if (frequencyPenalty != null) {
3395
3468
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3445,6 +3518,7 @@ var AnthropicMessagesLanguageModel = class {
3445
3518
  maxOutputTokens: maxOutputTokensForModel,
3446
3519
  supportsStructuredOutput: modelSupportsStructuredOutput,
3447
3520
  rejectsSamplingParameters,
3521
+ rejectsThinkingDisabledAboveHighEffort,
3448
3522
  isKnownModel
3449
3523
  } = getModelCapabilities(this.modelId);
3450
3524
  if (!isKnownModel && maxOutputTokens == null) {
@@ -3531,11 +3605,19 @@ var AnthropicMessagesLanguageModel = class {
3531
3605
  cacheControlValidator,
3532
3606
  toolNameMapping
3533
3607
  });
3534
- const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3608
+ if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3609
+ warnings.push({
3610
+ type: "unsupported",
3611
+ feature: "providerOptions.anthropic.effort",
3612
+ details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
3613
+ });
3614
+ anthropicOptions.effort = "high";
3615
+ }
3616
+ const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3535
3617
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3536
3618
  const sendThinking = isThinking || thinkingType === "disabled";
3537
- let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3538
- const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3619
+ let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3620
+ const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3539
3621
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3540
3622
  const baseArgs = {
3541
3623
  // model id:
@@ -3582,13 +3664,13 @@ var AnthropicMessagesLanguageModel = class {
3582
3664
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3583
3665
  inference_geo: anthropicOptions.inferenceGeo
3584
3666
  },
3585
- ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
3667
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
3586
3668
  fallbacks: anthropicOptions.fallbacks
3587
3669
  },
3588
3670
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3589
3671
  cache_control: anthropicOptions.cacheControl
3590
3672
  },
3591
- ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3673
+ ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3592
3674
  metadata: { user_id: anthropicOptions.metadata.userId }
3593
3675
  },
3594
3676
  // mcp servers:
@@ -3761,10 +3843,12 @@ var AnthropicMessagesLanguageModel = class {
3761
3843
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3762
3844
  betas.add("fast-mode-2026-02-01");
3763
3845
  }
3764
- if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3846
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
3847
+ betas.add("server-side-fallback-2026-07-01");
3848
+ } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3765
3849
  betas.add("server-side-fallback-2026-06-01");
3766
3850
  }
3767
- const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3851
+ const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
3768
3852
  const {
3769
3853
  tools: anthropicTools2,
3770
3854
  toolChoice: anthropicToolChoice,
@@ -3803,7 +3887,7 @@ var AnthropicMessagesLanguageModel = class {
3803
3887
  ...betas,
3804
3888
  ...toolsBetas,
3805
3889
  ...userSuppliedBetas,
3806
- ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3890
+ ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
3807
3891
  ]),
3808
3892
  usesJsonResponseTool: jsonResponseTool != null,
3809
3893
  toolNameMapping,
@@ -5128,6 +5212,9 @@ var AnthropicMessagesLanguageModel = class {
5128
5212
  usage.input_tokens = value.usage.input_tokens;
5129
5213
  }
5130
5214
  usage.output_tokens = value.usage.output_tokens;
5215
+ if (value.usage.output_tokens_details != null) {
5216
+ usage.output_tokens_details = value.usage.output_tokens_details;
5217
+ }
5131
5218
  if (value.usage.cache_read_input_tokens != null) {
5132
5219
  usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
5133
5220
  }
@@ -5249,11 +5336,20 @@ var AnthropicMessagesLanguageModel = class {
5249
5336
  }
5250
5337
  };
5251
5338
  function getModelCapabilities(modelId) {
5252
- if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5339
+ if (modelId.includes("claude-opus-5")) {
5340
+ return {
5341
+ maxOutputTokens: 128e3,
5342
+ supportsStructuredOutput: true,
5343
+ rejectsSamplingParameters: true,
5344
+ rejectsThinkingDisabledAboveHighEffort: true,
5345
+ isKnownModel: true
5346
+ };
5347
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5253
5348
  return {
5254
5349
  maxOutputTokens: 128e3,
5255
5350
  supportsStructuredOutput: true,
5256
5351
  rejectsSamplingParameters: true,
5352
+ rejectsThinkingDisabledAboveHighEffort: false,
5257
5353
  isKnownModel: true
5258
5354
  };
5259
5355
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -5261,6 +5357,7 @@ function getModelCapabilities(modelId) {
5261
5357
  maxOutputTokens: 128e3,
5262
5358
  supportsStructuredOutput: true,
5263
5359
  rejectsSamplingParameters: false,
5360
+ rejectsThinkingDisabledAboveHighEffort: false,
5264
5361
  isKnownModel: true
5265
5362
  };
5266
5363
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -5268,6 +5365,7 @@ function getModelCapabilities(modelId) {
5268
5365
  maxOutputTokens: 64e3,
5269
5366
  supportsStructuredOutput: true,
5270
5367
  rejectsSamplingParameters: false,
5368
+ rejectsThinkingDisabledAboveHighEffort: false,
5271
5369
  isKnownModel: true
5272
5370
  };
5273
5371
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -5275,6 +5373,7 @@ function getModelCapabilities(modelId) {
5275
5373
  maxOutputTokens: 32e3,
5276
5374
  supportsStructuredOutput: true,
5277
5375
  rejectsSamplingParameters: false,
5376
+ rejectsThinkingDisabledAboveHighEffort: false,
5278
5377
  isKnownModel: true
5279
5378
  };
5280
5379
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -5282,6 +5381,7 @@ function getModelCapabilities(modelId) {
5282
5381
  maxOutputTokens: 64e3,
5283
5382
  supportsStructuredOutput: false,
5284
5383
  rejectsSamplingParameters: false,
5384
+ rejectsThinkingDisabledAboveHighEffort: false,
5285
5385
  isKnownModel: true
5286
5386
  };
5287
5387
  } else if (modelId.includes("claude-opus-4-")) {
@@ -5289,6 +5389,7 @@ function getModelCapabilities(modelId) {
5289
5389
  maxOutputTokens: 32e3,
5290
5390
  supportsStructuredOutput: false,
5291
5391
  rejectsSamplingParameters: false,
5392
+ rejectsThinkingDisabledAboveHighEffort: false,
5292
5393
  isKnownModel: true
5293
5394
  };
5294
5395
  } else if (modelId.includes("claude-3-haiku")) {
@@ -5296,6 +5397,7 @@ function getModelCapabilities(modelId) {
5296
5397
  maxOutputTokens: 4096,
5297
5398
  supportsStructuredOutput: false,
5298
5399
  rejectsSamplingParameters: false,
5400
+ rejectsThinkingDisabledAboveHighEffort: false,
5299
5401
  isKnownModel: true
5300
5402
  };
5301
5403
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -5303,6 +5405,7 @@ function getModelCapabilities(modelId) {
5303
5405
  maxOutputTokens: 4096,
5304
5406
  supportsStructuredOutput: false,
5305
5407
  rejectsSamplingParameters: false,
5408
+ rejectsThinkingDisabledAboveHighEffort: false,
5306
5409
  isKnownModel: false
5307
5410
  };
5308
5411
  } else if (modelId.includes("claude-")) {
@@ -5310,6 +5413,7 @@ function getModelCapabilities(modelId) {
5310
5413
  maxOutputTokens: 128e3,
5311
5414
  supportsStructuredOutput: true,
5312
5415
  rejectsSamplingParameters: true,
5416
+ rejectsThinkingDisabledAboveHighEffort: true,
5313
5417
  isKnownModel: false
5314
5418
  };
5315
5419
  } else {
@@ -5317,6 +5421,7 @@ function getModelCapabilities(modelId) {
5317
5421
  maxOutputTokens: 4096,
5318
5422
  supportsStructuredOutput: false,
5319
5423
  rejectsSamplingParameters: false,
5424
+ rejectsThinkingDisabledAboveHighEffort: false,
5320
5425
  isKnownModel: false
5321
5426
  };
5322
5427
  }