@ai-sdk/anthropic 2.0.45 → 2.0.48

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,23 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 2.0.48
4
+
5
+ ### Patch Changes
6
+
7
+ - f2c6cbd: feat(provider/anthropic): Anthropic-native structured outputs
8
+
9
+ ## 2.0.47
10
+
11
+ ### Patch Changes
12
+
13
+ - 3a7a427: 'fix(anthropic): Opus 4.5 `maxOutputTokens` bump `32000` -> `64000`'
14
+
15
+ ## 2.0.46
16
+
17
+ ### Patch Changes
18
+
19
+ - 54a0480: Opus 4.5 and `effort` provider option
20
+
3
21
  ## 2.0.45
4
22
 
5
23
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -42,9 +42,14 @@ interface AnthropicMessageMetadata {
42
42
  } | null;
43
43
  }
44
44
 
45
- type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (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' | (string & {});
46
46
  declare const anthropicProviderOptions: z.ZodObject<{
47
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
48
+ structuredOutputMode: z.ZodOptional<z.ZodEnum<{
49
+ outputFormat: "outputFormat";
50
+ jsonTool: "jsonTool";
51
+ auto: "auto";
52
+ }>>;
48
53
  thinking: z.ZodOptional<z.ZodObject<{
49
54
  type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
50
55
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -62,6 +67,11 @@ declare const anthropicProviderOptions: z.ZodObject<{
62
67
  version: z.ZodOptional<z.ZodString>;
63
68
  }, z.core.$strip>>>;
64
69
  }, z.core.$strip>>;
70
+ effort: z.ZodOptional<z.ZodEnum<{
71
+ low: "low";
72
+ medium: "medium";
73
+ high: "high";
74
+ }>>;
65
75
  }, z.core.$strip>;
66
76
  type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
67
77
 
package/dist/index.d.ts CHANGED
@@ -42,9 +42,14 @@ interface AnthropicMessageMetadata {
42
42
  } | null;
43
43
  }
44
44
 
45
- type AnthropicMessagesModelId = 'claude-haiku-4-5' | 'claude-haiku-4-5-20251001' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-opus-4-1' | 'claude-opus-4-0' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-opus-4-20250514' | 'claude-sonnet-4-20250514' | 'claude-3-7-sonnet-latest' | 'claude-3-7-sonnet-20250219' | 'claude-3-5-haiku-latest' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | (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' | (string & {});
46
46
  declare const anthropicProviderOptions: z.ZodObject<{
47
47
  sendReasoning: z.ZodOptional<z.ZodBoolean>;
48
+ structuredOutputMode: z.ZodOptional<z.ZodEnum<{
49
+ outputFormat: "outputFormat";
50
+ jsonTool: "jsonTool";
51
+ auto: "auto";
52
+ }>>;
48
53
  thinking: z.ZodOptional<z.ZodObject<{
49
54
  type: z.ZodUnion<readonly [z.ZodLiteral<"enabled">, z.ZodLiteral<"disabled">]>;
50
55
  budgetTokens: z.ZodOptional<z.ZodNumber>;
@@ -62,6 +67,11 @@ declare const anthropicProviderOptions: z.ZodObject<{
62
67
  version: z.ZodOptional<z.ZodString>;
63
68
  }, z.core.$strip>>>;
64
69
  }, z.core.$strip>>;
70
+ effort: z.ZodOptional<z.ZodEnum<{
71
+ low: "low";
72
+ medium: "medium";
73
+ high: "high";
74
+ }>>;
65
75
  }, z.core.$strip>;
66
76
  type AnthropicProviderOptions = z.infer<typeof anthropicProviderOptions>;
67
77
 
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.45" : "0.0.0-test";
34
+ var VERSION = true ? "2.0.48" : "0.0.0-test";
35
35
 
36
36
  // src/anthropic-messages-language-model.ts
37
37
  var import_provider3 = require("@ai-sdk/provider");
@@ -552,6 +552,20 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
552
552
  });
553
553
  var anthropicProviderOptions = import_v43.z.object({
554
554
  sendReasoning: import_v43.z.boolean().optional(),
555
+ /**
556
+ * Determines how structured outputs are generated.
557
+ *
558
+ * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
559
+ * - `jsonTool`: Use a special 'json' tool to specify the structured output format (default).
560
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool'.
561
+ */
562
+ structuredOutputMode: import_v43.z.enum(["outputFormat", "jsonTool", "auto"]).optional(),
563
+ /**
564
+ * Configuration for enabling Claude's extended thinking.
565
+ *
566
+ * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
567
+ * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
568
+ */
555
569
  thinking: import_v43.z.object({
556
570
  type: import_v43.z.union([import_v43.z.literal("enabled"), import_v43.z.literal("disabled")]),
557
571
  budgetTokens: import_v43.z.number().optional()
@@ -583,7 +597,11 @@ var anthropicProviderOptions = import_v43.z.object({
583
597
  version: import_v43.z.string().optional()
584
598
  })
585
599
  ).optional()
586
- }).optional()
600
+ }).optional(),
601
+ /**
602
+ * @default 'high'
603
+ */
604
+ effort: import_v43.z.enum(["low", "medium", "high"]).optional()
587
605
  });
588
606
 
589
607
  // src/anthropic-prepare-tools.ts
@@ -1765,7 +1783,7 @@ var AnthropicMessagesLanguageModel = class {
1765
1783
  toolChoice,
1766
1784
  providerOptions
1767
1785
  }) {
1768
- var _a, _b, _c, _d;
1786
+ var _a, _b, _c, _d, _e;
1769
1787
  const warnings = [];
1770
1788
  if (frequencyPenalty != null) {
1771
1789
  warnings.push({
@@ -1815,27 +1833,33 @@ var AnthropicMessagesLanguageModel = class {
1815
1833
  });
1816
1834
  }
1817
1835
  }
1818
- const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null ? {
1819
- type: "function",
1820
- name: "json",
1821
- description: "Respond with a JSON object.",
1822
- inputSchema: responseFormat.schema
1823
- } : void 0;
1824
1836
  const anthropicOptions = await (0, import_provider_utils11.parseProviderOptions)({
1825
1837
  provider: "anthropic",
1826
1838
  providerOptions,
1827
1839
  schema: anthropicProviderOptions
1828
1840
  });
1841
+ const {
1842
+ maxOutputTokens: maxOutputTokensForModel,
1843
+ supportsStructuredOutput,
1844
+ isKnownModel
1845
+ } = getModelCapabilities(this.modelId);
1846
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : "jsonTool";
1847
+ const useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
1848
+ const jsonResponseTool = (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && !useStructuredOutput ? {
1849
+ type: "function",
1850
+ name: "json",
1851
+ description: "Respond with a JSON object.",
1852
+ inputSchema: responseFormat.schema
1853
+ } : void 0;
1829
1854
  const cacheControlValidator = new CacheControlValidator();
1830
1855
  const { prompt: messagesPrompt, betas } = await convertToAnthropicMessagesPrompt({
1831
1856
  prompt,
1832
- sendReasoning: (_a = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _a : true,
1857
+ sendReasoning: (_b = anthropicOptions == null ? void 0 : anthropicOptions.sendReasoning) != null ? _b : true,
1833
1858
  warnings,
1834
1859
  cacheControlValidator
1835
1860
  });
1836
- const isThinking = ((_b = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _b.type) === "enabled";
1837
- const thinkingBudget = (_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.budgetTokens;
1838
- const { maxOutputTokens: maxOutputTokensForModel, knownModel } = getMaxOutputTokensForModel(this.modelId);
1861
+ const isThinking = ((_c = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _c.type) === "enabled";
1862
+ const thinkingBudget = (_d = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _d.budgetTokens;
1839
1863
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
1840
1864
  const baseArgs = {
1841
1865
  // model id:
@@ -1850,11 +1874,21 @@ var AnthropicMessagesLanguageModel = class {
1850
1874
  ...isThinking && {
1851
1875
  thinking: { type: "enabled", budget_tokens: thinkingBudget }
1852
1876
  },
1877
+ ...(anthropicOptions == null ? void 0 : anthropicOptions.effort) && {
1878
+ output_config: { effort: anthropicOptions.effort }
1879
+ },
1880
+ // structured output:
1881
+ ...useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null && {
1882
+ output_format: {
1883
+ type: "json_schema",
1884
+ schema: responseFormat.schema
1885
+ }
1886
+ },
1853
1887
  // container with agent skills:
1854
1888
  ...(anthropicOptions == null ? void 0 : anthropicOptions.container) && {
1855
1889
  container: {
1856
1890
  id: anthropicOptions.container.id,
1857
- skills: (_d = anthropicOptions.container.skills) == null ? void 0 : _d.map((skill) => ({
1891
+ skills: (_e = anthropicOptions.container.skills) == null ? void 0 : _e.map((skill) => ({
1858
1892
  type: skill.type,
1859
1893
  skill_id: skill.skillId,
1860
1894
  version: skill.version
@@ -1897,7 +1931,7 @@ var AnthropicMessagesLanguageModel = class {
1897
1931
  }
1898
1932
  baseArgs.max_tokens = maxTokens + thinkingBudget;
1899
1933
  }
1900
- if (knownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
1934
+ if (isKnownModel && baseArgs.max_tokens > maxOutputTokensForModel) {
1901
1935
  if (maxOutputTokens != null) {
1902
1936
  warnings.push({
1903
1937
  type: "unsupported-setting",
@@ -1920,6 +1954,12 @@ var AnthropicMessagesLanguageModel = class {
1920
1954
  });
1921
1955
  }
1922
1956
  }
1957
+ if (anthropicOptions == null ? void 0 : anthropicOptions.effort) {
1958
+ betas.add("effort-2025-11-24");
1959
+ }
1960
+ if (useStructuredOutput) {
1961
+ betas.add("structured-outputs-2025-11-13");
1962
+ }
1923
1963
  const {
1924
1964
  tools: anthropicTools2,
1925
1965
  toolChoice: anthropicToolChoice,
@@ -2722,17 +2762,49 @@ var AnthropicMessagesLanguageModel = class {
2722
2762
  };
2723
2763
  }
2724
2764
  };
2725
- function getMaxOutputTokensForModel(modelId) {
2726
- if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
2727
- return { maxOutputTokens: 64e3, knownModel: true };
2765
+ function getModelCapabilities(modelId) {
2766
+ if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5")) {
2767
+ return {
2768
+ maxOutputTokens: 64e3,
2769
+ supportsStructuredOutput: true,
2770
+ isKnownModel: true
2771
+ };
2772
+ } else if (modelId.includes("claude-opus-4-1")) {
2773
+ return {
2774
+ maxOutputTokens: 32e3,
2775
+ supportsStructuredOutput: true,
2776
+ isKnownModel: true
2777
+ };
2778
+ } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet") || modelId.includes("claude-haiku-4-5")) {
2779
+ return {
2780
+ maxOutputTokens: 64e3,
2781
+ supportsStructuredOutput: false,
2782
+ isKnownModel: true
2783
+ };
2728
2784
  } else if (modelId.includes("claude-opus-4-")) {
2729
- return { maxOutputTokens: 32e3, knownModel: true };
2785
+ return {
2786
+ maxOutputTokens: 32e3,
2787
+ supportsStructuredOutput: false,
2788
+ isKnownModel: true
2789
+ };
2730
2790
  } else if (modelId.includes("claude-3-5-haiku")) {
2731
- return { maxOutputTokens: 8192, knownModel: true };
2791
+ return {
2792
+ maxOutputTokens: 8192,
2793
+ supportsStructuredOutput: false,
2794
+ isKnownModel: true
2795
+ };
2732
2796
  } else if (modelId.includes("claude-3-haiku")) {
2733
- return { maxOutputTokens: 4096, knownModel: true };
2797
+ return {
2798
+ maxOutputTokens: 4096,
2799
+ supportsStructuredOutput: false,
2800
+ isKnownModel: true
2801
+ };
2734
2802
  } else {
2735
- return { maxOutputTokens: 4096, knownModel: false };
2803
+ return {
2804
+ maxOutputTokens: 4096,
2805
+ supportsStructuredOutput: false,
2806
+ isKnownModel: false
2807
+ };
2736
2808
  }
2737
2809
  }
2738
2810