@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.
@@ -349,6 +349,9 @@ var anthropicMessagesResponseSchema = lazySchema2(
349
349
  usage: z2.looseObject({
350
350
  input_tokens: z2.number(),
351
351
  output_tokens: z2.number(),
352
+ output_tokens_details: z2.object({
353
+ thinking_tokens: z2.number().nullish()
354
+ }).nullish(),
352
355
  cache_creation_input_tokens: z2.number().nullish(),
353
356
  cache_read_input_tokens: z2.number().nullish(),
354
357
  iterations: z2.array(
@@ -796,6 +799,9 @@ var anthropicMessagesChunkSchema = lazySchema2(
796
799
  usage: z2.looseObject({
797
800
  input_tokens: z2.number().nullish(),
798
801
  output_tokens: z2.number(),
802
+ output_tokens_details: z2.object({
803
+ thinking_tokens: z2.number().nullish()
804
+ }).nullish(),
799
805
  cache_creation_input_tokens: z2.number().nullish(),
800
806
  cache_read_input_tokens: z2.number().nullish(),
801
807
  iterations: z2.array(
@@ -877,6 +883,34 @@ var anthropicFilePartProviderOptions = z3.object({
877
883
  */
878
884
  context: z3.string().optional()
879
885
  });
886
+ var anthropicSystemMessageProviderOptions = z3.object({
887
+ /**
888
+ * Mid-conversation tool changes. Adds or removes tools from the
889
+ * conversation's tool set between turns without invalidating the prompt
890
+ * cache.
891
+ *
892
+ * Only supported on system messages that appear mid-conversation (not the
893
+ * initial system prompt). A system message carrying tool changes must come
894
+ * right before an assistant message or at the end of the messages.
895
+ *
896
+ * Tools referenced by a `tool_addition` must be declared in the `tools`
897
+ * option (typically with `deferLoading: true` so they are not loaded until
898
+ * the addition surfaces them). The required
899
+ * `mid-conversation-tool-changes-2026-07-01` beta is added automatically.
900
+ */
901
+ toolChanges: z3.array(
902
+ z3.discriminatedUnion("type", [
903
+ z3.object({
904
+ type: z3.literal("tool_addition"),
905
+ toolName: z3.string()
906
+ }),
907
+ z3.object({
908
+ type: z3.literal("tool_removal"),
909
+ toolName: z3.string()
910
+ })
911
+ ])
912
+ ).optional()
913
+ });
880
914
  var anthropicLanguageModelOptions = z3.object({
881
915
  /**
882
916
  * Whether to send reasoning to the model.
@@ -1016,30 +1050,35 @@ var anthropicLanguageModelOptions = z3.object({
1016
1050
  */
1017
1051
  inferenceGeo: z3.enum(["us", "global"]).optional(),
1018
1052
  /**
1019
- * Server-side fallback chain.
1053
+ * Server-side fallback configuration.
1020
1054
  *
1021
1055
  * When the primary model's safety classifiers block a turn, the API
1022
- * automatically retries it on the next model in the chain, server-side. A
1023
- * `content-filter` finish reason means the entire chain refused.
1056
+ * automatically retries it server-side on a fallback model. A
1057
+ * `content-filter` finish reason means the fallback(s) refused as well.
1024
1058
  *
1025
- * Each entry is merged into the request as a direct request to that entry's
1026
- * model, so it must be formatted accordingly: `model` is required, and an
1027
- * entry may additionally override `max_tokens`, `thinking`, `output_config`,
1028
- * and `speed` for that attempt only (`speed` additionally requires the speed
1029
- * beta). The value is passed through to the API as-is.
1030
- *
1031
- * The required `server-side-fallback-2026-06-01` beta is added automatically
1032
- * when this option is set.
1059
+ * - `'default'` (recommended): the API routes the retry to Anthropic's
1060
+ * recommended fallback model based on the refusal category. Requires the
1061
+ * `server-side-fallback-2026-07-01` beta, which is added automatically.
1062
+ * - Array form: an explicit fallback chain. Each entry is merged into the
1063
+ * request as a direct request to that entry's model, so it must be
1064
+ * formatted accordingly: `model` is required, and an entry may
1065
+ * additionally override `max_tokens`, `thinking`, `output_config`, and
1066
+ * `speed` for that attempt only (`speed` additionally requires the speed
1067
+ * beta). The value is passed through to the API as-is, and the
1068
+ * `server-side-fallback-2026-06-01` beta is added automatically.
1033
1069
  */
1034
- fallbacks: z3.array(
1035
- z3.object({
1036
- model: z3.string(),
1037
- max_tokens: z3.number().int().optional(),
1038
- thinking: z3.record(z3.string(), z3.unknown()).optional(),
1039
- output_config: z3.record(z3.string(), z3.unknown()).optional(),
1040
- speed: z3.enum(["fast", "standard"]).optional()
1041
- })
1042
- ).optional(),
1070
+ fallbacks: z3.union([
1071
+ z3.literal("default"),
1072
+ z3.array(
1073
+ z3.object({
1074
+ model: z3.string(),
1075
+ max_tokens: z3.number().int().optional(),
1076
+ thinking: z3.record(z3.string(), z3.unknown()).optional(),
1077
+ output_config: z3.record(z3.string(), z3.unknown()).optional(),
1078
+ speed: z3.enum(["fast", "standard"]).optional()
1079
+ })
1080
+ )
1081
+ ]).optional(),
1043
1082
  /**
1044
1083
  * A set of beta features to enable.
1045
1084
  * Allow a provider to receive the full `betas` set if it needs it.
@@ -1820,12 +1859,13 @@ function convertAnthropicMessagesUsage({
1820
1859
  usage,
1821
1860
  rawUsage
1822
1861
  }) {
1823
- var _a, _b, _c;
1862
+ var _a, _b, _c, _d, _e;
1824
1863
  const cacheCreationTokens = (_a = usage.cache_creation_input_tokens) != null ? _a : 0;
1825
1864
  const cacheReadTokens = (_b = usage.cache_read_input_tokens) != null ? _b : 0;
1865
+ const reasoningTokens = (_d = (_c = usage.output_tokens_details) == null ? void 0 : _c.thinking_tokens) != null ? _d : void 0;
1826
1866
  let inputTokens;
1827
1867
  let outputTokens;
1828
- const servedByFallback = (_c = usage.iterations) == null ? void 0 : _c.some(
1868
+ const servedByFallback = (_e = usage.iterations) == null ? void 0 : _e.some(
1829
1869
  (iter) => iter.type === "fallback_message"
1830
1870
  );
1831
1871
  if (usage.iterations && usage.iterations.length > 0 && !servedByFallback) {
@@ -1859,8 +1899,8 @@ function convertAnthropicMessagesUsage({
1859
1899
  },
1860
1900
  outputTokens: {
1861
1901
  total: outputTokens,
1862
- text: void 0,
1863
- reasoning: void 0
1902
+ text: reasoningTokens == null ? void 0 : outputTokens - reasoningTokens,
1903
+ reasoning: reasoningTokens
1864
1904
  },
1865
1905
  raw: rawUsage != null ? rawUsage : usage
1866
1906
  };
@@ -2249,7 +2289,7 @@ async function convertToAnthropicMessagesPrompt({
2249
2289
  cacheControlValidator,
2250
2290
  toolNameMapping
2251
2291
  }) {
2252
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
2292
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
2253
2293
  const betas = /* @__PURE__ */ new Set();
2254
2294
  const blocks = groupIntoBlocks(prompt);
2255
2295
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -2281,19 +2321,52 @@ async function convertToAnthropicMessagesPrompt({
2281
2321
  const type = block.type;
2282
2322
  switch (type) {
2283
2323
  case "system": {
2284
- const content = block.messages.map(({ content: content2, providerOptions }) => ({
2285
- type: "text",
2286
- text: content2,
2287
- cache_control: validator.getCacheControl(providerOptions, {
2288
- type: "system message",
2289
- canCache: true
2290
- })
2291
- }));
2292
- if (system == null) {
2293
- system = content;
2324
+ const content = [];
2325
+ let toolChangeCount = 0;
2326
+ for (const { content: text, providerOptions } of block.messages) {
2327
+ const systemMessageOptions = await parseProviderOptions({
2328
+ provider: "anthropic",
2329
+ providerOptions,
2330
+ schema: anthropicSystemMessageProviderOptions
2331
+ });
2332
+ const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2333
+ if (text !== "" || toolChanges.length === 0) {
2334
+ content.push({
2335
+ type: "text",
2336
+ text,
2337
+ cache_control: validator.getCacheControl(providerOptions, {
2338
+ type: "system message",
2339
+ canCache: true
2340
+ })
2341
+ });
2342
+ }
2343
+ for (const toolChange of toolChanges) {
2344
+ toolChangeCount++;
2345
+ content.push({
2346
+ type: toolChange.type,
2347
+ tool: {
2348
+ type: "tool_reference",
2349
+ name: toolNameMapping.toProviderToolName(toolChange.toolName)
2350
+ }
2351
+ });
2352
+ }
2353
+ }
2354
+ if (i === 0 || system == null && toolChangeCount === 0) {
2355
+ if (toolChangeCount > 0) {
2356
+ warnings.push({
2357
+ type: "other",
2358
+ 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."
2359
+ });
2360
+ }
2361
+ system = content.filter(
2362
+ (part) => part.type === "text"
2363
+ );
2294
2364
  } else {
2295
2365
  messages.push({ role: "system", content });
2296
2366
  betas.add("mid-conversation-system-2026-04-07");
2367
+ if (toolChangeCount > 0) {
2368
+ betas.add("mid-conversation-tool-changes-2026-07-01");
2369
+ }
2297
2370
  }
2298
2371
  break;
2299
2372
  }
@@ -2306,10 +2379,10 @@ async function convertToAnthropicMessagesPrompt({
2306
2379
  for (let j = 0; j < content.length; j++) {
2307
2380
  const part = content[j];
2308
2381
  const isLastPart = j === content.length - 1;
2309
- const cacheControl = (_a = validator.getCacheControl(part.providerOptions, {
2382
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
2310
2383
  type: "user message part",
2311
2384
  canCache: true
2312
- })) != null ? _a : isLastPart ? validator.getCacheControl(message.providerOptions, {
2385
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
2313
2386
  type: "user message",
2314
2387
  canCache: true
2315
2388
  }) : void 0;
@@ -2354,7 +2427,7 @@ async function convertToAnthropicMessagesPrompt({
2354
2427
  media_type: "application/pdf",
2355
2428
  data: convertToBase64(part.data)
2356
2429
  },
2357
- title: (_b = metadata.title) != null ? _b : part.filename,
2430
+ title: (_c = metadata.title) != null ? _c : part.filename,
2358
2431
  ...metadata.context && { context: metadata.context },
2359
2432
  ...enableCitations && {
2360
2433
  citations: { enabled: true }
@@ -2378,7 +2451,7 @@ async function convertToAnthropicMessagesPrompt({
2378
2451
  media_type: "text/plain",
2379
2452
  data: convertToString(part.data)
2380
2453
  },
2381
- title: (_c = metadata.title) != null ? _c : part.filename,
2454
+ title: (_d = metadata.title) != null ? _d : part.filename,
2382
2455
  ...metadata.context && { context: metadata.context },
2383
2456
  ...enableCitations && {
2384
2457
  citations: { enabled: true }
@@ -2403,17 +2476,17 @@ async function convertToAnthropicMessagesPrompt({
2403
2476
  continue;
2404
2477
  }
2405
2478
  const output = part.output;
2406
- const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_d = output.value.find(
2479
+ const outputProviderOptions = "providerOptions" in output ? output.providerOptions : output.type === "content" ? (_e = output.value.find(
2407
2480
  (contentPart) => contentPart.providerOptions != null
2408
- )) == null ? void 0 : _d.providerOptions : void 0;
2481
+ )) == null ? void 0 : _e.providerOptions : void 0;
2409
2482
  const isLastPart = i2 === content.length - 1;
2410
- const cacheControl = (_f = (_e = validator.getCacheControl(part.providerOptions, {
2483
+ const cacheControl = (_g = (_f = validator.getCacheControl(part.providerOptions, {
2411
2484
  type: "tool result part",
2412
2485
  canCache: true
2413
- })) != null ? _e : validator.getCacheControl(outputProviderOptions, {
2486
+ })) != null ? _f : validator.getCacheControl(outputProviderOptions, {
2414
2487
  type: "tool result output",
2415
2488
  canCache: true
2416
- })) != null ? _f : isLastPart ? validator.getCacheControl(message.providerOptions, {
2489
+ })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
2417
2490
  type: "tool result message",
2418
2491
  canCache: true
2419
2492
  }) : void 0;
@@ -2503,7 +2576,7 @@ async function convertToAnthropicMessagesPrompt({
2503
2576
  contentValue = output.value;
2504
2577
  break;
2505
2578
  case "execution-denied":
2506
- contentValue = (_g = output.reason) != null ? _g : "Tool call execution denied.";
2579
+ contentValue = (_h = output.reason) != null ? _h : "Tool call execution denied.";
2507
2580
  break;
2508
2581
  case "json":
2509
2582
  case "error-json":
@@ -2540,16 +2613,16 @@ async function convertToAnthropicMessagesPrompt({
2540
2613
  for (let k = 0; k < content.length; k++) {
2541
2614
  const part = content[k];
2542
2615
  const isLastContentPart = k === content.length - 1;
2543
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
2616
+ const cacheControl = (_i = validator.getCacheControl(part.providerOptions, {
2544
2617
  type: "assistant message part",
2545
2618
  canCache: true
2546
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2619
+ })) != null ? _i : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
2547
2620
  type: "assistant message",
2548
2621
  canCache: true
2549
2622
  }) : void 0;
2550
2623
  switch (part.type) {
2551
2624
  case "text": {
2552
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
2625
+ const textMetadata = (_j = part.providerOptions) == null ? void 0 : _j.anthropic;
2553
2626
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
2554
2627
  anthropicContent.push({
2555
2628
  type: "compaction",
@@ -2625,10 +2698,10 @@ async function convertToAnthropicMessagesPrompt({
2625
2698
  const providerToolName = toolNameMapping.toProviderToolName(
2626
2699
  part.toolName
2627
2700
  );
2628
- const isMcpToolUse = ((_k = (_j = part.providerOptions) == null ? void 0 : _j.anthropic) == null ? void 0 : _k.type) === "mcp-tool-use";
2701
+ const isMcpToolUse = ((_l = (_k = part.providerOptions) == null ? void 0 : _k.anthropic) == null ? void 0 : _l.type) === "mcp-tool-use";
2629
2702
  if (isMcpToolUse) {
2630
2703
  mcpToolUseIds.add(part.toolCallId);
2631
- const serverName = (_m = (_l = part.providerOptions) == null ? void 0 : _l.anthropic) == null ? void 0 : _m.serverName;
2704
+ const serverName = (_n = (_m = part.providerOptions) == null ? void 0 : _m.anthropic) == null ? void 0 : _n.serverName;
2632
2705
  if (serverName == null || typeof serverName !== "string") {
2633
2706
  warnings.push({
2634
2707
  type: "other",
@@ -2704,7 +2777,7 @@ async function convertToAnthropicMessagesPrompt({
2704
2777
  }
2705
2778
  break;
2706
2779
  }
2707
- const callerOptions = (_n = part.providerOptions) == null ? void 0 : _n.anthropic;
2780
+ const callerOptions = (_o = part.providerOptions) == null ? void 0 : _o.anthropic;
2708
2781
  const caller = (callerOptions == null ? void 0 : callerOptions.caller) ? (callerOptions.caller.type === "code_execution_20250825" || callerOptions.caller.type === "code_execution_20260120") && callerOptions.caller.toolId ? {
2709
2782
  type: callerOptions.caller.type,
2710
2783
  tool_id: callerOptions.caller.toolId
@@ -2757,7 +2830,7 @@ async function convertToAnthropicMessagesPrompt({
2757
2830
  tool_use_id: part.toolCallId,
2758
2831
  content: {
2759
2832
  type: "code_execution_tool_result_error",
2760
- error_code: (_o = errorInfo.errorCode) != null ? _o : "unknown"
2833
+ error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2761
2834
  },
2762
2835
  cache_control: cacheControl
2763
2836
  });
@@ -2768,7 +2841,7 @@ async function convertToAnthropicMessagesPrompt({
2768
2841
  cache_control: cacheControl,
2769
2842
  content: {
2770
2843
  type: "bash_code_execution_tool_result_error",
2771
- error_code: (_p = errorInfo.errorCode) != null ? _p : "unknown"
2844
+ error_code: (_q = errorInfo.errorCode) != null ? _q : "unknown"
2772
2845
  }
2773
2846
  });
2774
2847
  }
@@ -2801,7 +2874,7 @@ async function convertToAnthropicMessagesPrompt({
2801
2874
  stdout: codeExecutionOutput.stdout,
2802
2875
  stderr: codeExecutionOutput.stderr,
2803
2876
  return_code: codeExecutionOutput.return_code,
2804
- content: (_q = codeExecutionOutput.content) != null ? _q : []
2877
+ content: (_r = codeExecutionOutput.content) != null ? _r : []
2805
2878
  },
2806
2879
  cache_control: cacheControl
2807
2880
  });
@@ -2819,7 +2892,7 @@ async function convertToAnthropicMessagesPrompt({
2819
2892
  encrypted_stdout: codeExecutionOutput.encrypted_stdout,
2820
2893
  stderr: codeExecutionOutput.stderr,
2821
2894
  return_code: codeExecutionOutput.return_code,
2822
- content: (_r = codeExecutionOutput.content) != null ? _r : []
2895
+ content: (_s = codeExecutionOutput.content) != null ? _s : []
2823
2896
  },
2824
2897
  cache_control: cacheControl
2825
2898
  });
@@ -2838,7 +2911,7 @@ async function convertToAnthropicMessagesPrompt({
2838
2911
  stdout: codeExecutionOutput.stdout,
2839
2912
  stderr: codeExecutionOutput.stderr,
2840
2913
  return_code: codeExecutionOutput.return_code,
2841
- content: (_s = codeExecutionOutput.content) != null ? _s : []
2914
+ content: (_t = codeExecutionOutput.content) != null ? _t : []
2842
2915
  },
2843
2916
  cache_control: cacheControl
2844
2917
  });
@@ -2868,7 +2941,7 @@ async function convertToAnthropicMessagesPrompt({
2868
2941
  tool_use_id: part.toolCallId,
2869
2942
  content: {
2870
2943
  type: "web_fetch_tool_result_error",
2871
- error_code: (_t = (await extractErrorValue(output.value)).errorCode) != null ? _t : "unavailable"
2944
+ error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2872
2945
  },
2873
2946
  cache_control: cacheControl
2874
2947
  });
@@ -2915,7 +2988,7 @@ async function convertToAnthropicMessagesPrompt({
2915
2988
  tool_use_id: part.toolCallId,
2916
2989
  content: {
2917
2990
  type: "web_search_tool_result_error",
2918
- error_code: (_u = (await extractErrorValue(output.value)).errorCode) != null ? _u : "unavailable"
2991
+ error_code: (_v = (await extractErrorValue(output.value)).errorCode) != null ? _v : "unavailable"
2919
2992
  },
2920
2993
  cache_control: cacheControl
2921
2994
  });
@@ -3373,7 +3446,7 @@ var AnthropicMessagesLanguageModel = class {
3373
3446
  providerOptions,
3374
3447
  stream
3375
3448
  }) {
3376
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3449
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3377
3450
  const warnings = [];
3378
3451
  if (frequencyPenalty != null) {
3379
3452
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3429,6 +3502,7 @@ var AnthropicMessagesLanguageModel = class {
3429
3502
  maxOutputTokens: maxOutputTokensForModel,
3430
3503
  supportsStructuredOutput: modelSupportsStructuredOutput,
3431
3504
  rejectsSamplingParameters,
3505
+ rejectsThinkingDisabledAboveHighEffort,
3432
3506
  isKnownModel
3433
3507
  } = getModelCapabilities(this.modelId);
3434
3508
  if (!isKnownModel && maxOutputTokens == null) {
@@ -3515,11 +3589,19 @@ var AnthropicMessagesLanguageModel = class {
3515
3589
  cacheControlValidator,
3516
3590
  toolNameMapping
3517
3591
  });
3518
- const thinkingType = (_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type;
3592
+ if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3593
+ warnings.push({
3594
+ type: "unsupported",
3595
+ feature: "providerOptions.anthropic.effort",
3596
+ details: `effort '${anthropicOptions.effort}' is not supported by ${this.modelId} when thinking is disabled. The effort has been lowered to 'high'.`
3597
+ });
3598
+ anthropicOptions.effort = "high";
3599
+ }
3600
+ const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3519
3601
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3520
3602
  const sendThinking = isThinking || thinkingType === "disabled";
3521
- let thinkingBudget = thinkingType === "enabled" ? (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.budgetTokens : void 0;
3522
- const thinkingDisplay = thinkingType === "adaptive" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.display : void 0;
3603
+ let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3604
+ const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3523
3605
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3524
3606
  const baseArgs = {
3525
3607
  // model id:
@@ -3566,13 +3648,13 @@ var AnthropicMessagesLanguageModel = class {
3566
3648
  ...(anthropicOptions == null ? void 0 : anthropicOptions.inferenceGeo) && {
3567
3649
  inference_geo: anthropicOptions.inferenceGeo
3568
3650
  },
3569
- ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0 && {
3651
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) != null && (anthropicOptions.fallbacks === "default" || anthropicOptions.fallbacks.length > 0) && {
3570
3652
  fallbacks: anthropicOptions.fallbacks
3571
3653
  },
3572
3654
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3573
3655
  cache_control: anthropicOptions.cacheControl
3574
3656
  },
3575
- ...((_h = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _h.userId) != null && {
3657
+ ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3576
3658
  metadata: { user_id: anthropicOptions.metadata.userId }
3577
3659
  },
3578
3660
  // mcp servers:
@@ -3745,10 +3827,12 @@ var AnthropicMessagesLanguageModel = class {
3745
3827
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3746
3828
  betas.add("fast-mode-2026-02-01");
3747
3829
  }
3748
- if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3830
+ if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
3831
+ betas.add("server-side-fallback-2026-07-01");
3832
+ } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3749
3833
  betas.add("server-side-fallback-2026-06-01");
3750
3834
  }
3751
- const defaultEagerInputStreaming = stream && ((_i = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _i : true);
3835
+ const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
3752
3836
  const {
3753
3837
  tools: anthropicTools2,
3754
3838
  toolChoice: anthropicToolChoice,
@@ -3787,7 +3871,7 @@ var AnthropicMessagesLanguageModel = class {
3787
3871
  ...betas,
3788
3872
  ...toolsBetas,
3789
3873
  ...userSuppliedBetas,
3790
- ...(_j = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _j : []
3874
+ ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
3791
3875
  ]),
3792
3876
  usesJsonResponseTool: jsonResponseTool != null,
3793
3877
  toolNameMapping,
@@ -5112,6 +5196,9 @@ var AnthropicMessagesLanguageModel = class {
5112
5196
  usage.input_tokens = value.usage.input_tokens;
5113
5197
  }
5114
5198
  usage.output_tokens = value.usage.output_tokens;
5199
+ if (value.usage.output_tokens_details != null) {
5200
+ usage.output_tokens_details = value.usage.output_tokens_details;
5201
+ }
5115
5202
  if (value.usage.cache_read_input_tokens != null) {
5116
5203
  usage.cache_read_input_tokens = value.usage.cache_read_input_tokens;
5117
5204
  }
@@ -5233,11 +5320,20 @@ var AnthropicMessagesLanguageModel = class {
5233
5320
  }
5234
5321
  };
5235
5322
  function getModelCapabilities(modelId) {
5236
- if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5323
+ if (modelId.includes("claude-opus-5")) {
5324
+ return {
5325
+ maxOutputTokens: 128e3,
5326
+ supportsStructuredOutput: true,
5327
+ rejectsSamplingParameters: true,
5328
+ rejectsThinkingDisabledAboveHighEffort: true,
5329
+ isKnownModel: true
5330
+ };
5331
+ } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-fable-5") || modelId.includes("claude-sonnet-5")) {
5237
5332
  return {
5238
5333
  maxOutputTokens: 128e3,
5239
5334
  supportsStructuredOutput: true,
5240
5335
  rejectsSamplingParameters: true,
5336
+ rejectsThinkingDisabledAboveHighEffort: false,
5241
5337
  isKnownModel: true
5242
5338
  };
5243
5339
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -5245,6 +5341,7 @@ function getModelCapabilities(modelId) {
5245
5341
  maxOutputTokens: 128e3,
5246
5342
  supportsStructuredOutput: true,
5247
5343
  rejectsSamplingParameters: false,
5344
+ rejectsThinkingDisabledAboveHighEffort: false,
5248
5345
  isKnownModel: true
5249
5346
  };
5250
5347
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -5252,6 +5349,7 @@ function getModelCapabilities(modelId) {
5252
5349
  maxOutputTokens: 64e3,
5253
5350
  supportsStructuredOutput: true,
5254
5351
  rejectsSamplingParameters: false,
5352
+ rejectsThinkingDisabledAboveHighEffort: false,
5255
5353
  isKnownModel: true
5256
5354
  };
5257
5355
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -5259,6 +5357,7 @@ function getModelCapabilities(modelId) {
5259
5357
  maxOutputTokens: 32e3,
5260
5358
  supportsStructuredOutput: true,
5261
5359
  rejectsSamplingParameters: false,
5360
+ rejectsThinkingDisabledAboveHighEffort: false,
5262
5361
  isKnownModel: true
5263
5362
  };
5264
5363
  } else if (modelId.includes("claude-sonnet-4-")) {
@@ -5266,6 +5365,7 @@ function getModelCapabilities(modelId) {
5266
5365
  maxOutputTokens: 64e3,
5267
5366
  supportsStructuredOutput: false,
5268
5367
  rejectsSamplingParameters: false,
5368
+ rejectsThinkingDisabledAboveHighEffort: false,
5269
5369
  isKnownModel: true
5270
5370
  };
5271
5371
  } else if (modelId.includes("claude-opus-4-")) {
@@ -5273,6 +5373,7 @@ function getModelCapabilities(modelId) {
5273
5373
  maxOutputTokens: 32e3,
5274
5374
  supportsStructuredOutput: false,
5275
5375
  rejectsSamplingParameters: false,
5376
+ rejectsThinkingDisabledAboveHighEffort: false,
5276
5377
  isKnownModel: true
5277
5378
  };
5278
5379
  } else if (modelId.includes("claude-3-haiku")) {
@@ -5280,6 +5381,7 @@ function getModelCapabilities(modelId) {
5280
5381
  maxOutputTokens: 4096,
5281
5382
  supportsStructuredOutput: false,
5282
5383
  rejectsSamplingParameters: false,
5384
+ rejectsThinkingDisabledAboveHighEffort: false,
5283
5385
  isKnownModel: true
5284
5386
  };
5285
5387
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -5287,6 +5389,7 @@ function getModelCapabilities(modelId) {
5287
5389
  maxOutputTokens: 4096,
5288
5390
  supportsStructuredOutput: false,
5289
5391
  rejectsSamplingParameters: false,
5392
+ rejectsThinkingDisabledAboveHighEffort: false,
5290
5393
  isKnownModel: false
5291
5394
  };
5292
5395
  } else if (modelId.includes("claude-")) {
@@ -5294,6 +5397,7 @@ function getModelCapabilities(modelId) {
5294
5397
  maxOutputTokens: 128e3,
5295
5398
  supportsStructuredOutput: true,
5296
5399
  rejectsSamplingParameters: true,
5400
+ rejectsThinkingDisabledAboveHighEffort: true,
5297
5401
  isKnownModel: false
5298
5402
  };
5299
5403
  } else {
@@ -5301,6 +5405,7 @@ function getModelCapabilities(modelId) {
5301
5405
  maxOutputTokens: 4096,
5302
5406
  supportsStructuredOutput: false,
5303
5407
  rejectsSamplingParameters: false,
5408
+ rejectsThinkingDisabledAboveHighEffort: false,
5304
5409
  isKnownModel: false
5305
5410
  };
5306
5411
  }