@ai-sdk/anthropic 2.0.105 → 2.0.107

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.
@@ -661,9 +661,10 @@ var anthropicSystemMessageProviderOptions = z3.object({
661
661
  */
662
662
  clearAt: z3.literal("next_user_message").optional(),
663
663
  /**
664
- * Overrides the effort for the turn following this mid-conversation system
665
- * message. The required `mid-conversation-output-config-2026-07-01` beta is added
666
- * automatically.
664
+ * Sets the model effort from the next user turn until a later message
665
+ * changes it. An effort-only system message with empty content can appear
666
+ * first. The required `mid-conversation-output-config-2026-07-01` beta is
667
+ * added automatically.
667
668
  */
668
669
  effort: z3.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
669
670
  /**
@@ -713,7 +714,7 @@ var anthropicProviderOptions = z3.object({
713
714
  *
714
715
  * - `outputFormat`: Use the `output_format` parameter to specify the structured output format.
715
716
  * - `jsonTool`: Use a special JSON response tool to specify the structured output format (default for most models).
716
- * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Opus 5.5 and Fable 5.1).
717
+ * - `auto`: Use 'outputFormat' when supported, otherwise use 'jsonTool' (default for Sonnet 5.5, Opus 5.5, and Fable 5.1).
717
718
  */
718
719
  structuredOutputMode: z3.enum(["outputFormat", "jsonTool", "auto"]).optional(),
719
720
  /**
@@ -726,6 +727,9 @@ var anthropicProviderOptions = z3.object({
726
727
  * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
727
728
  * provider drops the unsupported setting, emits a warning, and sends an
728
729
  * adaptive thinking request. Use `effort` to control how much they think.
730
+ *
731
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
732
+ * and the provider uses it in place of `disabled` for that model.
729
733
  */
730
734
  thinking: z3.union([
731
735
  z3.object({
@@ -757,6 +761,14 @@ var anthropicProviderOptions = z3.object({
757
761
  z3.object({
758
762
  type: z3.literal("disabled")
759
763
  }),
764
+ z3.object({
765
+ /**
766
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
767
+ * between tool calls are returned as summarized thinking blocks.
768
+ * Only supported at `low`, `medium`, and `high` effort.
769
+ */
770
+ type: z3.literal("between_tools")
771
+ }),
760
772
  z3.object({
761
773
  /**
762
774
  * Configure prefix mismatch handling without changing the model's
@@ -1659,7 +1671,7 @@ async function convertToAnthropicMessagesPrompt({
1659
1671
  cacheControlValidator,
1660
1672
  toolsetNames = {}
1661
1673
  }) {
1662
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1674
+ var _a, _b, _c, _d, _e, _f, _g;
1663
1675
  const betas = /* @__PURE__ */ new Set();
1664
1676
  const blocks = groupIntoBlocks(prompt);
1665
1677
  const validator = cacheControlValidator || new CacheControlValidator();
@@ -1691,10 +1703,9 @@ async function convertToAnthropicMessagesPrompt({
1691
1703
  const type = block.type;
1692
1704
  switch (type) {
1693
1705
  case "system": {
1694
- const content = [];
1706
+ const systemMessages = [];
1695
1707
  let toolChangeCount = 0;
1696
- let clearAt = void 0;
1697
- let effort = void 0;
1708
+ let hasMidConversationOptions = false;
1698
1709
  for (const { content: text, providerOptions } of block.messages) {
1699
1710
  const systemMessageOptions = await parseProviderOptions({
1700
1711
  provider: "anthropic",
@@ -1702,8 +1713,9 @@ async function convertToAnthropicMessagesPrompt({
1702
1713
  schema: anthropicSystemMessageProviderOptions
1703
1714
  });
1704
1715
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
1705
- clearAt = (_b = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) != null ? _b : clearAt;
1706
- effort = (_c = systemMessageOptions == null ? void 0 : systemMessageOptions.effort) != null ? _c : effort;
1716
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
1717
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
1718
+ const content = [];
1707
1719
  if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
1708
1720
  content.push({
1709
1721
  type: "text",
@@ -1724,33 +1736,47 @@ async function convertToAnthropicMessagesPrompt({
1724
1736
  }
1725
1737
  });
1726
1738
  }
1739
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
1740
+ systemMessages.push({
1741
+ role: "system",
1742
+ content,
1743
+ ...clearAt != null && { clear_at: clearAt },
1744
+ ...effort != null && { output_config: { effort } }
1745
+ });
1727
1746
  }
1728
- const hasMidConversationOptions = toolChangeCount > 0 || clearAt != null || effort != null;
1729
- if (i === 0 || system == null && !hasMidConversationOptions) {
1730
- if (hasMidConversationOptions) {
1747
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
1748
+ if (toolChangeCount > 0) {
1731
1749
  warnings.push({
1732
1750
  type: "other",
1733
- message: "mid-conversation Anthropic system message options on the initial system message are not supported. The options have been ignored."
1751
+ 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."
1734
1752
  });
1735
1753
  }
1736
- system = content.filter(
1737
- (part) => part.type === "text"
1754
+ for (const message of systemMessages) {
1755
+ if (message.content.length === 0 && message.clear_at == null && message.output_config != null) {
1756
+ messages.push(message);
1757
+ betas.add("mid-conversation-output-config-2026-07-01");
1758
+ } else if (message.clear_at != null || message.output_config != null) {
1759
+ warnings.push({
1760
+ type: "other",
1761
+ message: "clearAt and effort on this initial system message are not supported by Anthropic. Use a separate effort-only system message with empty content to set effort. These options have been ignored."
1762
+ });
1763
+ }
1764
+ }
1765
+ system = systemMessages.flatMap(
1766
+ (message) => message.content.filter(
1767
+ (part) => part.type === "text"
1768
+ )
1738
1769
  );
1739
1770
  } else {
1740
- messages.push({
1741
- role: "system",
1742
- content,
1743
- ...clearAt != null && { clear_at: clearAt },
1744
- ...effort != null && { output_config: { effort } }
1745
- });
1771
+ messages.push(...systemMessages);
1746
1772
  betas.add("mid-conversation-system-2026-04-07");
1747
1773
  if (toolChangeCount > 0) {
1748
1774
  betas.add("mid-conversation-tool-changes-2026-07-01");
1749
1775
  }
1750
- if (clearAt != null) {
1776
+ if (systemMessages.some((message) => message.clear_at != null)) {
1751
1777
  betas.add("mid-conversation-system-clear-at-2026-08-21");
1752
1778
  }
1753
- if (effort != null) {
1779
+ if (systemMessages.some((message) => message.output_config != null)) {
1754
1780
  betas.add("mid-conversation-output-config-2026-07-01");
1755
1781
  }
1756
1782
  }
@@ -1765,10 +1791,10 @@ async function convertToAnthropicMessagesPrompt({
1765
1791
  for (let j = 0; j < content.length; j++) {
1766
1792
  const part = content[j];
1767
1793
  const isLastPart = j === content.length - 1;
1768
- const cacheControl = (_d = validator.getCacheControl(part.providerOptions, {
1794
+ const cacheControl = (_b = validator.getCacheControl(part.providerOptions, {
1769
1795
  type: "user message part",
1770
1796
  canCache: true
1771
- })) != null ? _d : isLastPart ? validator.getCacheControl(message.providerOptions, {
1797
+ })) != null ? _b : isLastPart ? validator.getCacheControl(message.providerOptions, {
1772
1798
  type: "user message",
1773
1799
  canCache: true
1774
1800
  }) : void 0;
@@ -1813,7 +1839,7 @@ async function convertToAnthropicMessagesPrompt({
1813
1839
  media_type: "application/pdf",
1814
1840
  data: convertToBase64(part.data)
1815
1841
  },
1816
- title: (_e = metadata.title) != null ? _e : part.filename,
1842
+ title: (_c = metadata.title) != null ? _c : part.filename,
1817
1843
  ...metadata.context && { context: metadata.context },
1818
1844
  ...enableCitations && {
1819
1845
  citations: { enabled: true }
@@ -1837,7 +1863,7 @@ async function convertToAnthropicMessagesPrompt({
1837
1863
  media_type: "text/plain",
1838
1864
  data: convertToString(part.data)
1839
1865
  },
1840
- title: (_f = metadata.title) != null ? _f : part.filename,
1866
+ title: (_d = metadata.title) != null ? _d : part.filename,
1841
1867
  ...metadata.context && { context: metadata.context },
1842
1868
  ...enableCitations && {
1843
1869
  citations: { enabled: true }
@@ -1859,10 +1885,10 @@ async function convertToAnthropicMessagesPrompt({
1859
1885
  for (let i2 = 0; i2 < content.length; i2++) {
1860
1886
  const part = content[i2];
1861
1887
  const isLastPart = i2 === content.length - 1;
1862
- const cacheControl = (_g = validator.getCacheControl(part.providerOptions, {
1888
+ const cacheControl = (_e = validator.getCacheControl(part.providerOptions, {
1863
1889
  type: "tool result part",
1864
1890
  canCache: true
1865
- })) != null ? _g : isLastPart ? validator.getCacheControl(message.providerOptions, {
1891
+ })) != null ? _e : isLastPart ? validator.getCacheControl(message.providerOptions, {
1866
1892
  type: "tool result message",
1867
1893
  canCache: true
1868
1894
  }) : void 0;
@@ -1950,16 +1976,16 @@ async function convertToAnthropicMessagesPrompt({
1950
1976
  for (let k = 0; k < content.length; k++) {
1951
1977
  const part = content[k];
1952
1978
  const isLastContentPart = k === content.length - 1;
1953
- const cacheControl = (_h = validator.getCacheControl(part.providerOptions, {
1979
+ const cacheControl = (_f = validator.getCacheControl(part.providerOptions, {
1954
1980
  type: "assistant message part",
1955
1981
  canCache: true
1956
- })) != null ? _h : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1982
+ })) != null ? _f : isLastContentPart ? validator.getCacheControl(message.providerOptions, {
1957
1983
  type: "assistant message",
1958
1984
  canCache: true
1959
1985
  }) : void 0;
1960
1986
  switch (part.type) {
1961
1987
  case "text": {
1962
- const textMetadata = (_i = part.providerOptions) == null ? void 0 : _i.anthropic;
1988
+ const textMetadata = (_g = part.providerOptions) == null ? void 0 : _g.anthropic;
1963
1989
  if ((textMetadata == null ? void 0 : textMetadata.type) === "compaction") {
1964
1990
  anthropicContent.push({
1965
1991
  type: "compaction",
@@ -2639,6 +2665,7 @@ var AnthropicMessagesLanguageModel = class {
2639
2665
  rejectsThinkingDisabledAboveHighEffort,
2640
2666
  rejectsThinkingDisabled,
2641
2667
  rejectsForcedToolUse,
2668
+ supportsBetweenToolsThinking,
2642
2669
  isKnownModel
2643
2670
  } = getModelCapabilities(this.modelId);
2644
2671
  if (!isKnownModel && maxOutputTokens == null) {
@@ -2674,7 +2701,7 @@ var AnthropicMessagesLanguageModel = class {
2674
2701
  }
2675
2702
  }
2676
2703
  const isAnthropicModel = isKnownModel || this.modelId.includes("claude-");
2677
- const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") || this.modelId.includes("claude-opus-5-5") ? "auto" : "jsonTool";
2704
+ const structureOutputMode = (_a = anthropicOptions == null ? void 0 : anthropicOptions.structuredOutputMode) != null ? _a : this.modelId.includes("claude-fable-5-1") || this.modelId.includes("claude-opus-5-5") || this.modelId.includes("claude-sonnet-5-5") ? "auto" : "jsonTool";
2678
2705
  let useStructuredOutput = structureOutputMode === "outputFormat" || structureOutputMode === "auto" && supportsStructuredOutput;
2679
2706
  if (!useStructuredOutput && rejectsForcedToolUse && supportsStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) {
2680
2707
  warnings.push({
@@ -2709,7 +2736,14 @@ var AnthropicMessagesLanguageModel = class {
2709
2736
  });
2710
2737
  if (rejectsThinkingDisabled && (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null) {
2711
2738
  const thinking = anthropicOptions.thinking;
2712
- if ("type" in thinking && thinking.type === "disabled") {
2739
+ if ("type" in thinking && thinking.type === "disabled" && supportsBetweenToolsThinking) {
2740
+ warnings.push({
2741
+ type: "unsupported-setting",
2742
+ setting: "providerOptions.anthropic.thinking",
2743
+ details: `thinking cannot be disabled for ${this.modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
2744
+ });
2745
+ anthropicOptions.thinking = { type: "between_tools" };
2746
+ } else if ("type" in thinking && thinking.type === "disabled") {
2713
2747
  warnings.push({
2714
2748
  type: "unsupported-setting",
2715
2749
  setting: "providerOptions.anthropic.thinking",
@@ -2740,7 +2774,15 @@ var AnthropicMessagesLanguageModel = class {
2740
2774
  });
2741
2775
  anthropicOptions.effort = "high";
2742
2776
  }
2743
- const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
2777
+ if (thinkingType === "between_tools" && anthropicOptions != null && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
2778
+ warnings.push({
2779
+ type: "unsupported-setting",
2780
+ setting: "providerOptions.anthropic.effort",
2781
+ details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
2782
+ });
2783
+ anthropicOptions.effort = "high";
2784
+ }
2785
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
2744
2786
  let thinkingBudget = thinkingOptions != null && "budgetTokens" in thinkingOptions ? thinkingOptions.budgetTokens : void 0;
2745
2787
  const thinkingDisplay = thinkingOptions != null && "display" in thinkingOptions ? thinkingOptions.display : void 0;
2746
2788
  const thinkingBlockBinding = thinkingOptions != null && "blockBinding" in thinkingOptions ? thinkingOptions.blockBinding : void 0;
@@ -4105,7 +4147,18 @@ var AnthropicMessagesLanguageModel = class {
4105
4147
  }
4106
4148
  };
4107
4149
  function getModelCapabilities(modelId) {
4108
- if (modelId.includes("claude-opus-5-5")) {
4150
+ if (modelId.includes("claude-sonnet-5-5")) {
4151
+ return {
4152
+ maxOutputTokens: 128e3,
4153
+ supportsStructuredOutput: true,
4154
+ rejectsSamplingParameters: true,
4155
+ rejectsThinkingDisabledAboveHighEffort: true,
4156
+ rejectsThinkingDisabled: true,
4157
+ rejectsForcedToolUse: true,
4158
+ supportsBetweenToolsThinking: true,
4159
+ isKnownModel: true
4160
+ };
4161
+ } else if (modelId.includes("claude-opus-5-5")) {
4109
4162
  return {
4110
4163
  maxOutputTokens: 128e3,
4111
4164
  supportsStructuredOutput: true,
@@ -4113,6 +4166,7 @@ function getModelCapabilities(modelId) {
4113
4166
  rejectsThinkingDisabledAboveHighEffort: true,
4114
4167
  rejectsThinkingDisabled: true,
4115
4168
  rejectsForcedToolUse: true,
4169
+ supportsBetweenToolsThinking: false,
4116
4170
  isKnownModel: true
4117
4171
  };
4118
4172
  } else if (modelId.includes("claude-opus-5")) {
@@ -4123,6 +4177,7 @@ function getModelCapabilities(modelId) {
4123
4177
  rejectsThinkingDisabledAboveHighEffort: true,
4124
4178
  rejectsThinkingDisabled: false,
4125
4179
  rejectsForcedToolUse: false,
4180
+ supportsBetweenToolsThinking: false,
4126
4181
  isKnownModel: true
4127
4182
  };
4128
4183
  } else if (modelId.includes("claude-fable-5-1")) {
@@ -4133,6 +4188,7 @@ function getModelCapabilities(modelId) {
4133
4188
  rejectsThinkingDisabledAboveHighEffort: false,
4134
4189
  rejectsThinkingDisabled: true,
4135
4190
  rejectsForcedToolUse: true,
4191
+ supportsBetweenToolsThinking: false,
4136
4192
  isKnownModel: true
4137
4193
  };
4138
4194
  } else if (modelId.includes("claude-fable-5")) {
@@ -4143,6 +4199,7 @@ function getModelCapabilities(modelId) {
4143
4199
  rejectsThinkingDisabledAboveHighEffort: false,
4144
4200
  rejectsThinkingDisabled: true,
4145
4201
  rejectsForcedToolUse: false,
4202
+ supportsBetweenToolsThinking: false,
4146
4203
  isKnownModel: true
4147
4204
  };
4148
4205
  } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
@@ -4153,6 +4210,7 @@ function getModelCapabilities(modelId) {
4153
4210
  rejectsThinkingDisabledAboveHighEffort: false,
4154
4211
  rejectsThinkingDisabled: false,
4155
4212
  rejectsForcedToolUse: false,
4213
+ supportsBetweenToolsThinking: false,
4156
4214
  isKnownModel: true
4157
4215
  };
4158
4216
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -4163,6 +4221,7 @@ function getModelCapabilities(modelId) {
4163
4221
  rejectsThinkingDisabledAboveHighEffort: false,
4164
4222
  rejectsThinkingDisabled: false,
4165
4223
  rejectsForcedToolUse: false,
4224
+ supportsBetweenToolsThinking: false,
4166
4225
  isKnownModel: true
4167
4226
  };
4168
4227
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -4173,6 +4232,7 @@ function getModelCapabilities(modelId) {
4173
4232
  rejectsThinkingDisabledAboveHighEffort: false,
4174
4233
  rejectsThinkingDisabled: false,
4175
4234
  rejectsForcedToolUse: false,
4235
+ supportsBetweenToolsThinking: false,
4176
4236
  isKnownModel: true
4177
4237
  };
4178
4238
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -4183,6 +4243,7 @@ function getModelCapabilities(modelId) {
4183
4243
  rejectsThinkingDisabledAboveHighEffort: false,
4184
4244
  rejectsThinkingDisabled: false,
4185
4245
  rejectsForcedToolUse: false,
4246
+ supportsBetweenToolsThinking: false,
4186
4247
  isKnownModel: true
4187
4248
  };
4188
4249
  } else if (modelId.includes("claude-sonnet-4-") || modelId.includes("claude-3-7-sonnet")) {
@@ -4193,6 +4254,7 @@ function getModelCapabilities(modelId) {
4193
4254
  rejectsThinkingDisabledAboveHighEffort: false,
4194
4255
  rejectsThinkingDisabled: false,
4195
4256
  rejectsForcedToolUse: false,
4257
+ supportsBetweenToolsThinking: false,
4196
4258
  isKnownModel: true
4197
4259
  };
4198
4260
  } else if (modelId.includes("claude-opus-4-")) {
@@ -4203,6 +4265,7 @@ function getModelCapabilities(modelId) {
4203
4265
  rejectsThinkingDisabledAboveHighEffort: false,
4204
4266
  rejectsThinkingDisabled: false,
4205
4267
  rejectsForcedToolUse: false,
4268
+ supportsBetweenToolsThinking: false,
4206
4269
  isKnownModel: true
4207
4270
  };
4208
4271
  } else if (modelId.includes("claude-3-haiku")) {
@@ -4213,6 +4276,7 @@ function getModelCapabilities(modelId) {
4213
4276
  rejectsThinkingDisabledAboveHighEffort: false,
4214
4277
  rejectsThinkingDisabled: false,
4215
4278
  rejectsForcedToolUse: false,
4279
+ supportsBetweenToolsThinking: false,
4216
4280
  isKnownModel: true
4217
4281
  };
4218
4282
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -4223,6 +4287,7 @@ function getModelCapabilities(modelId) {
4223
4287
  rejectsThinkingDisabledAboveHighEffort: false,
4224
4288
  rejectsThinkingDisabled: false,
4225
4289
  rejectsForcedToolUse: false,
4290
+ supportsBetweenToolsThinking: false,
4226
4291
  isKnownModel: false
4227
4292
  };
4228
4293
  } else if (modelId.includes("claude-")) {
@@ -4233,6 +4298,7 @@ function getModelCapabilities(modelId) {
4233
4298
  rejectsThinkingDisabledAboveHighEffort: true,
4234
4299
  rejectsThinkingDisabled: false,
4235
4300
  rejectsForcedToolUse: false,
4301
+ supportsBetweenToolsThinking: false,
4236
4302
  isKnownModel: false
4237
4303
  };
4238
4304
  } else {
@@ -4243,6 +4309,7 @@ function getModelCapabilities(modelId) {
4243
4309
  rejectsThinkingDisabledAboveHighEffort: false,
4244
4310
  rejectsThinkingDisabled: false,
4245
4311
  rejectsForcedToolUse: false,
4312
+ supportsBetweenToolsThinking: false,
4246
4313
  isKnownModel: false
4247
4314
  };
4248
4315
  }