@ai-sdk/anthropic 2.0.57 → 2.0.59

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.
@@ -497,8 +497,10 @@ var anthropicMessagesChunkSchema = lazySchema2(
497
497
  }).nullish()
498
498
  }),
499
499
  usage: z2.looseObject({
500
+ input_tokens: z2.number().nullish(),
500
501
  output_tokens: z2.number(),
501
- cache_creation_input_tokens: z2.number().nullish()
502
+ cache_creation_input_tokens: z2.number().nullish(),
503
+ cache_read_input_tokens: z2.number().nullish()
502
504
  })
503
505
  }),
504
506
  z2.object({
@@ -560,10 +562,20 @@ var anthropicProviderOptions = z3.object({
560
562
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
561
563
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
562
564
  */
563
- thinking: z3.object({
564
- type: z3.union([z3.literal("enabled"), z3.literal("disabled")]),
565
- budgetTokens: z3.number().optional()
566
- }).optional(),
565
+ thinking: z3.discriminatedUnion("type", [
566
+ z3.object({
567
+ /** for Opus 4.6 and newer models */
568
+ type: z3.literal("adaptive")
569
+ }),
570
+ z3.object({
571
+ /** for models before Opus 4.6 */
572
+ type: z3.literal("enabled"),
573
+ budgetTokens: z3.number().optional()
574
+ }),
575
+ z3.object({
576
+ type: z3.literal("disabled")
577
+ })
578
+ ]).optional(),
567
579
  /**
568
580
  * Whether to disable parallel function calling during tool use. Default is false.
569
581
  * When set to true, Claude will use at most one tool per response.
@@ -595,7 +607,7 @@ var anthropicProviderOptions = z3.object({
595
607
  /**
596
608
  * @default 'high'
597
609
  */
598
- effort: z3.enum(["low", "medium", "high"]).optional()
610
+ effort: z3.enum(["low", "medium", "high", "max"]).optional()
599
611
  });
600
612
 
601
613
  // src/anthropic-prepare-tools.ts
@@ -1877,8 +1889,9 @@ var AnthropicMessagesLanguageModel = class {
1877
1889
  warnings,
1878
1890
  cacheControlValidator
1879
1891
  });
1880
- const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1881
- const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
1892
+ const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
1893
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
1894
+ let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
1882
1895
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1883
1896
  const baseArgs = {
1884
1897
  // model id:
@@ -1891,7 +1904,10 @@ var AnthropicMessagesLanguageModel = class {
1891
1904
  stop_sequences: stopSequences,
1892
1905
  // provider specific settings:
1893
1906
  ...isThinking && {
1894
- thinking: { type: "enabled", budget_tokens: thinkingBudget }
1907
+ thinking: {
1908
+ type: thinkingType,
1909
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget }
1910
+ }
1895
1911
  },
1896
1912
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
1897
1913
  output_config: { effort: anthropicOptions.effort }
@@ -1919,7 +1935,7 @@ var AnthropicMessagesLanguageModel = class {
1919
1935
  messages: messagesPrompt.messages
1920
1936
  };
1921
1937
  if (isThinking) {
1922
- if (thinkingBudget == null) {
1938
+ if (thinkingType === "enabled" && thinkingBudget == null) {
1923
1939
  throw new UnsupportedFunctionalityError3({
1924
1940
  functionality: "thinking requires a budget"
1925
1941
  });
@@ -1948,7 +1964,7 @@ var AnthropicMessagesLanguageModel = class {
1948
1964
  details: "topP is not supported when thinking is enabled"
1949
1965
  });
1950
1966
  }
1951
- baseArgs.max_tokens = maxTokens + thinkingBudget;
1967
+ baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
1952
1968
  }
1953
1969
  if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
1954
1970
  if (maxOutputTokens != null) {
@@ -2745,8 +2761,17 @@ var AnthropicMessagesLanguageModel = class {
2745
2761
  return;
2746
2762
  }
2747
2763
  case "message_delta": {
2764
+ if (value.usage.input_tokens != null && usage.inputTokens !== value.usage.input_tokens) {
2765
+ usage.inputTokens = value.usage.input_tokens;
2766
+ }
2748
2767
  usage.outputTokens = value.usage.output_tokens;
2749
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2768
+ if (value.usage.cache_read_input_tokens != null) {
2769
+ usage.cachedInputTokens = value.usage.cache_read_input_tokens;
2770
+ }
2771
+ if (value.usage.cache_creation_input_tokens != null) {
2772
+ cacheCreationInputTokens = value.usage.cache_creation_input_tokens;
2773
+ }
2774
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = usage.outputTokens) != null ? _g : 0);
2750
2775
  finishReason = mapAnthropicStopReason({
2751
2776
  finishReason: value.delta.stop_reason,
2752
2777
  isJsonResponseFromTool: usesJsonResponseTool
@@ -2828,7 +2853,13 @@ var AnthropicMessagesLanguageModel = class {
2828
2853
  }
2829
2854
  };
2830
2855
  function getModelCapabilities(modelId) {
2831
- if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2856
+ if (modelId.includes("claude-opus-4-6")) {
2857
+ return {
2858
+ maxOutputTokens: 128e3,
2859
+ supportsStructuredOutput: true,
2860
+ isKnownModel: true
2861
+ };
2862
+ } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2832
2863
  return {
2833
2864
  maxOutputTokens: 64e3,
2834
2865
  supportsStructuredOutput: true,