@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.
package/CHANGELOG.md CHANGED
@@ -1,11 +1,24 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.59
4
+
5
+ ### Patch Changes
6
+
7
+ - ca1f53a: feat(anthropic): add support for Opus 4.6
8
+
9
+ ## 2.0.58
10
+
11
+ ### Patch Changes
12
+
13
+ - 8479fe8: trigger for backport release
14
+ - 008ce2f: fix `input_tokens` compatibility
15
+
3
16
  ## 2.0.57
4
17
 
5
18
  ### Patch Changes
6
19
 
7
- - 4953414: fix: trigger new release for `@ai-v5` dist-tag
8
- - Updated dependencies [4953414]
20
+ - 526fe8d: fix: trigger new release for `@ai-v5` dist-tag
21
+ - Updated dependencies [526fe8d]
9
22
  - @ai-sdk/provider@2.0.1
10
23
  - @ai-sdk/provider-utils@3.0.20
11
24
 
package/dist/index.d.mts CHANGED
@@ -42,7 +42,7 @@ interface AnthropicMessageMetadata {
42
42
  } | null;
43
43
  }
44
44
 
45
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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' | (string & {});
45
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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-opus-4-6' | (string & {});
46
46
  declare const anthropicProviderOptions: z.ZodObject<{
47
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
48
48
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -50,10 +50,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
50
50
  jsonTool: "jsonTool";
51
51
  auto: "auto";
52
52
  }>>;
53
- thinking: z.ZodOptional<z.ZodObject<{
54
- type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
53
+ thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ type: z.ZodLiteral<"adaptive">;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ type: z.ZodLiteral<"enabled">;
55
57
  budgetTokens: z.ZodOptional<z.ZodNumber>;
56
- }, z.core.$strip>>;
58
+ }, z.core.$strip>, z.ZodObject<{
59
+ type: z.ZodLiteral<"disabled">;
60
+ }, z.core.$strip>]>>;
57
61
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
58
62
  cacheControl: z.ZodOptional<z.ZodObject<{
59
63
  type: z.ZodLiteral<"ephemeral">;
@@ -71,6 +75,7 @@ declare const anthropicProviderOptions: z.ZodObject<{
71
75
  low: "low";
72
76
  medium: "medium";
73
77
  high: "high";
78
+ max: "max";
74
79
  }>>;
75
80
  }, z.core.$strip>;
76
81
  type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
package/dist/index.d.ts CHANGED
@@ -42,7 +42,7 @@ interface AnthropicMessageMetadata {
42
42
  } | null;
43
43
  }
44
44
 
45
- type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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' | (string & {});
45
+ type AnthropicMessagesModelId = 'claude-3-5-haiku-20241022' | 'claude-3-5-haiku-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | 'claude-opus-4-20250514' | '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-opus-4-6' | (string & {});
46
46
  declare const anthropicProviderOptions: z.ZodObject<{
47
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
48
48
  structuredOutputMode: z.ZodOptional<z.ZodEnum<{
@@ -50,10 +50,14 @@ declare const anthropicProviderOptions: z.ZodObject<{
50
50
  jsonTool: "jsonTool";
51
51
  auto: "auto";
52
52
  }>>;
53
- thinking: z.ZodOptional<z.ZodObject<{
54
- type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
53
+ thinking: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
54
+ type: z.ZodLiteral<"adaptive">;
55
+ }, z.core.$strip>, z.ZodObject<{
56
+ type: z.ZodLiteral<"enabled">;
55
57
  budgetTokens: z.ZodOptional<z.ZodNumber>;
56
- }, z.core.$strip>>;
58
+ }, z.core.$strip>, z.ZodObject<{
59
+ type: z.ZodLiteral<"disabled">;
60
+ }, z.core.$strip>]>>;
57
61
  disableParallelToolUse: z.ZodOptional<z.ZodBoolean>;
58
62
  cacheControl: z.ZodOptional<z.ZodObject<{
59
63
  type: z.ZodLiteral<"ephemeral">;
@@ -71,6 +75,7 @@ declare const anthropicProviderOptions: z.ZodObject<{
71
75
  low: "low";
72
76
  medium: "medium";
73
77
  high: "high";
78
+ max: "max";
74
79
  }>>;
75
80
  }, z.core.$strip>;
76
81
  type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ var import_provider4 = require("@ai-sdk/provider");
31
31
  var import_provider_utils20 = require("@ai-sdk/provider-utils");
32
32
 
33
33
  // src/version.ts
34
- var VERSION = true ? "2.0.57" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.59" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -517,8 +517,10 @@ var anthropicMessagesChunkSchema = (0, import_provider_utils2.lazySchema)(
517
517
  }).nullish()
518
518
  }),
519
519
  usage: import_v42.z.looseObject({
520
+ input_tokens: import_v42.z.number().nullish(),
520
521
  output_tokens: import_v42.z.number(),
521
- cache_creation_input_tokens: import_v42.z.number().nullish()
522
+ cache_creation_input_tokens: import_v42.z.number().nullish(),
523
+ cache_read_input_tokens: import_v42.z.number().nullish()
522
524
  })
523
525
  }),
524
526
  import_v42.z.object({
@@ -580,10 +582,20 @@ var anthropicProviderOptions = import_v43.z.object({
580
582
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
581
583
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
582
584
  */
583
- thinking: import_v43.z.object({
584
- type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
585
- budgetTokens: import_v43.z.number().optional()
586
- }).optional(),
585
+ thinking: import_v43.z.discriminatedUnion("type", [
586
+ import_v43.z.object({
587
+ /** for Opus 4.6 and newer models */
588
+ type: import_v43.z.literal("adaptive")
589
+ }),
590
+ import_v43.z.object({
591
+ /** for models before Opus 4.6 */
592
+ type: import_v43.z.literal("enabled"),
593
+ budgetTokens: import_v43.z.number().optional()
594
+ }),
595
+ import_v43.z.object({
596
+ type: import_v43.z.literal("disabled")
597
+ })
598
+ ]).optional(),
587
599
  /**
588
600
  * Whether to disable parallel function calling during tool use. Default is false.
589
601
  * When set to true, Claude will use at most one tool per response.
@@ -615,7 +627,7 @@ var anthropicProviderOptions = import_v43.z.object({
615
627
  /**
616
628
  * @default 'high'
617
629
  */
618
- effort: import_v43.z.enum(["low", "medium", "high"]).optional()
630
+ effort: import_v43.z.enum(["low", "medium", "high", "max"]).optional()
619
631
  });
620
632
 
621
633
  // src/anthropic-prepare-tools.ts
@@ -1873,8 +1885,9 @@ var AnthropicMessagesLanguageModel = class {
1873
1885
  warnings,
1874
1886
  cacheControlValidator
1875
1887
  });
1876
- const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1877
- const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
1888
+ const thinkingType = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type;
1889
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
1890
+ let thinkingBudget = thinkingType === "enabled" ? (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens : void 0;
1878
1891
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1879
1892
  const baseArgs = {
1880
1893
  // model id:
@@ -1887,7 +1900,10 @@ var AnthropicMessagesLanguageModel = class {
1887
1900
  stop_sequences: stopSequences,
1888
1901
  // provider specific settings:
1889
1902
  ...isThinking && {
1890
- thinking: { type: "enabled", budget_tokens: thinkingBudget }
1903
+ thinking: {
1904
+ type: thinkingType,
1905
+ ...thinkingBudget != null && { budget_tokens: thinkingBudget }
1906
+ }
1891
1907
  },
1892
1908
  ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
1893
1909
  output_config: { effort: anthropicOptions.effort }
@@ -1915,7 +1931,7 @@ var AnthropicMessagesLanguageModel = class {
1915
1931
  messages: messagesPrompt.messages
1916
1932
  };
1917
1933
  if (isThinking) {
1918
- if (thinkingBudget == null) {
1934
+ if (thinkingType === "enabled" && thinkingBudget == null) {
1919
1935
  throw new import_provider3.UnsupportedFunctionalityError({
1920
1936
  functionality: "thinking requires a budget"
1921
1937
  });
@@ -1944,7 +1960,7 @@ var AnthropicMessagesLanguageModel = class {
1944
1960
  details: "topP is not supported when thinking is enabled"
1945
1961
  });
1946
1962
  }
1947
- baseArgs.max_tokens = maxTokens + thinkingBudget;
1963
+ baseArgs.max_tokens = maxTokens + (thinkingBudget != null ? thinkingBudget : 0);
1948
1964
  }
1949
1965
  if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
1950
1966
  if (maxOutputTokens != null) {
@@ -2741,8 +2757,17 @@ var AnthropicMessagesLanguageModel = class {
2741
2757
  return;
2742
2758
  }
2743
2759
  case "message_delta": {
2760
+ if (value.usage.input_tokens != null && usage.inputTokens !== value.usage.input_tokens) {
2761
+ usage.inputTokens = value.usage.input_tokens;
2762
+ }
2744
2763
  usage.outputTokens = value.usage.output_tokens;
2745
- usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = value.usage.output_tokens) != null ? _g : 0);
2764
+ if (value.usage.cache_read_input_tokens != null) {
2765
+ usage.cachedInputTokens = value.usage.cache_read_input_tokens;
2766
+ }
2767
+ if (value.usage.cache_creation_input_tokens != null) {
2768
+ cacheCreationInputTokens = value.usage.cache_creation_input_tokens;
2769
+ }
2770
+ usage.totalTokens = ((_f = usage.inputTokens) != null ? _f : 0) + ((_g = usage.outputTokens) != null ? _g : 0);
2746
2771
  finishReason = mapAnthropicStopReason({
2747
2772
  finishReason: value.delta.stop_reason,
2748
2773
  isJsonResponseFromTool: usesJsonResponseTool
@@ -2824,7 +2849,13 @@ var AnthropicMessagesLanguageModel = class {
2824
2849
  }
2825
2850
  };
2826
2851
  function getModelCapabilities(modelId) {
2827
- if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2852
+ if (modelId.includes("claude-opus-4-6")) {
2853
+ return {
2854
+ maxOutputTokens: 128e3,
2855
+ supportsStructuredOutput: true,
2856
+ isKnownModel: true
2857
+ };
2858
+ } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2828
2859
  return {
2829
2860
  maxOutputTokens: 64e3,
2830
2861
  supportsStructuredOutput: true,