@ai-sdk/anthropic 4.0.65 → 4.0.67

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,27 @@
1
1
  # @ai-sdk/anthropic
2
2
 
3
+ ## 4.0.67
4
+
5
+ ### Patch Changes
6
+
7
+ - e361d39: feat(anthropic): add Claude Sonnet 5.5 support
8
+
9
+ - add the `claude-sonnet-5-5` model ID to `@ai-sdk/anthropic` and `@ai-sdk/google-vertex`, `anthropic.claude-sonnet-5-5` and `us.anthropic.claude-sonnet-5-5` to `@ai-sdk/amazon-bedrock`, and `anthropic/claude-sonnet-5.5` to `@ai-sdk/gateway`
10
+ - add the `between_tools` thinking type (`thinking: { type: 'between_tools' }`), the lowest thinking setting on `claude-sonnet-5-5`; `xhigh` and `max` effort are lowered to `high` with a warning because the API rejects them with `between_tools`
11
+ - `claude-sonnet-5-5` rejects disabled thinking: `thinking: { type: 'disabled' }` is replaced with `between_tools` thinking (with a warning), `reasoning: 'none'` maps to `between_tools` thinking, and budget-based thinking is converted to adaptive thinking
12
+ - `claude-sonnet-5-5` rejects forced tool use: `required` and named tool choices fall back to `auto`, and `structuredOutputMode: 'jsonTool'` falls back to native structured outputs, each with a warning
13
+
14
+ - 8373a22: Normalize dangling programmatic tool caller references in conversation history after pruning. Before a subsequent user message, omit caller metadata whose source code execution call is missing and emit a warning, preserving the retained tool calls and results. Keep caller metadata unchanged for active tool continuations.
15
+
16
+ ## 4.0.66
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [e3605f6]
21
+ - Updated dependencies [525efc5]
22
+ - @ai-sdk/provider-utils@5.0.50
23
+ - @ai-sdk/provider@4.0.19
24
+
3
25
  ## 4.0.65
4
26
 
5
27
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -219,7 +219,7 @@ interface AnthropicMessageMetadata {
219
219
  } | null;
220
220
  }
221
221
 
222
- type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
222
+ type AnthropicModelId = 'claude-3-haiku-20240307' | 'claude-haiku-4-5-20251001' | 'claude-haiku-4-5' | 'claude-opus-4-0' | 'claude-opus-4-20250514' | 'claude-opus-4-1-20250805' | 'claude-opus-4-1' | '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-sonnet-4-6' | 'claude-opus-4-6' | 'claude-opus-4-7' | 'claude-opus-4-8' | 'claude-opus-5' | 'claude-opus-5-5' | 'claude-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | 'claude-sonnet-5-5' | (string & {});
223
223
  /**
224
224
  * Anthropic provider options for system messages.
225
225
  */
@@ -266,6 +266,8 @@ declare const anthropicLanguageModelOptions: z.ZodObject<{
266
266
  budgetTokens: z.ZodOptional<z.ZodNumber>;
267
267
  }, z.core.$strip>, z.ZodObject<{
268
268
  type: z.ZodLiteral<"disabled">;
269
+ }, z.core.$strip>, z.ZodObject<{
270
+ type: z.ZodLiteral<"between_tools">;
269
271
  }, z.core.$strip>]>, z.ZodObject<{
270
272
  type: z.ZodOptional<z.ZodNever>;
271
273
  blockBinding: z.ZodObject<{
package/dist/index.js CHANGED
@@ -1071,6 +1071,9 @@ var anthropicLanguageModelOptions = z4.object({
1071
1071
  * `claude-fable-5-1`) reject `enabled` and `disabled`. For those models the
1072
1072
  * provider drops the unsupported setting, emits a warning, and sends an
1073
1073
  * adaptive thinking request. Use `effort` to control how much they think.
1074
+ *
1075
+ * `claude-sonnet-5-5` supports `between_tools`, its lowest thinking setting,
1076
+ * and the provider uses it in place of `disabled` for that model.
1074
1077
  */
1075
1078
  thinking: z4.union([
1076
1079
  z4.discriminatedUnion("type", [
@@ -1099,6 +1102,14 @@ var anthropicLanguageModelOptions = z4.object({
1099
1102
  }),
1100
1103
  z4.object({
1101
1104
  type: z4.literal("disabled")
1105
+ }),
1106
+ z4.object({
1107
+ /**
1108
+ * for `claude-sonnet-5-5`: no upfront thinking, but progress notes
1109
+ * between tool calls are returned as summarized thinking blocks.
1110
+ * Only supported at `low`, `medium`, and `high` effort.
1111
+ */
1112
+ type: z4.literal("between_tools")
1102
1113
  })
1103
1114
  ]),
1104
1115
  z4.object({
@@ -2789,6 +2800,7 @@ async function convertToAnthropicPrompt({
2789
2800
  const validator = cacheControlValidator || new CacheControlValidator();
2790
2801
  let system = void 0;
2791
2802
  const messages = [];
2803
+ let lastUserMessageIndex = -1;
2792
2804
  async function shouldEnableCitations(providerMetadata) {
2793
2805
  const anthropicOptions = await parseProviderOptions({
2794
2806
  provider: "anthropic",
@@ -2921,6 +2933,9 @@ async function convertToAnthropicPrompt({
2921
2933
  const { role, content } = message;
2922
2934
  switch (role) {
2923
2935
  case "user": {
2936
+ if (content.length > 0) {
2937
+ lastUserMessageIndex = messages.length;
2938
+ }
2924
2939
  for (let j = 0; j < content.length; j++) {
2925
2940
  const part = content[j];
2926
2941
  const isLastPart = j === content.length - 1;
@@ -3803,6 +3818,42 @@ async function convertToAnthropicPrompt({
3803
3818
  }
3804
3819
  }
3805
3820
  }
3821
+ const codeExecutionToolCallIds = /* @__PURE__ */ new Set();
3822
+ for (const message of messages) {
3823
+ if (message.role !== "assistant") {
3824
+ continue;
3825
+ }
3826
+ for (const part of message.content) {
3827
+ if (part.type === "server_tool_use" && part.name === "code_execution") {
3828
+ codeExecutionToolCallIds.add(part.id);
3829
+ }
3830
+ }
3831
+ }
3832
+ const warnedToolCallIds = /* @__PURE__ */ new Set();
3833
+ for (let i = 0; i < lastUserMessageIndex; i++) {
3834
+ const message = messages[i];
3835
+ if (message.role !== "assistant") {
3836
+ continue;
3837
+ }
3838
+ for (const part of message.content) {
3839
+ if (!("caller" in part)) {
3840
+ continue;
3841
+ }
3842
+ const caller = part.caller;
3843
+ if (caller == null || caller.type === "direct" || codeExecutionToolCallIds.has(caller.tool_id)) {
3844
+ continue;
3845
+ }
3846
+ const toolCallId = "id" in part ? part.id : part.tool_use_id;
3847
+ delete part.caller;
3848
+ if (!warnedToolCallIds.has(toolCallId)) {
3849
+ warnedToolCallIds.add(toolCallId);
3850
+ warnings.push({
3851
+ type: "other",
3852
+ message: `Omitted caller metadata for tool ${toolCallId} because source code execution tool ${caller.tool_id} is missing from the conversation history.`
3853
+ });
3854
+ }
3855
+ }
3856
+ }
3806
3857
  return {
3807
3858
  prompt: { system, messages },
3808
3859
  betas
@@ -4286,6 +4337,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4286
4337
  rejectsThinkingDisabledAboveHighEffort,
4287
4338
  rejectsThinkingDisabled,
4288
4339
  rejectsForcedToolUse,
4340
+ supportsBetweenToolsThinking,
4289
4341
  isKnownModel
4290
4342
  } = getModelCapabilities(modelId);
4291
4343
  if (!isKnownModel && maxOutputTokens == null) {
@@ -4400,6 +4452,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4400
4452
  supportsAdaptiveThinking,
4401
4453
  supportsXhighEffort,
4402
4454
  rejectsThinkingDisabled,
4455
+ supportsBetweenToolsThinking,
4403
4456
  maxOutputTokensForModel,
4404
4457
  warnings
4405
4458
  });
@@ -4414,7 +4467,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4414
4467
  }
4415
4468
  if (rejectsThinkingDisabled && anthropicOptions?.thinking != null) {
4416
4469
  const thinking = anthropicOptions.thinking;
4417
- if (thinking.type === "disabled") {
4470
+ if (thinking.type === "disabled" && supportsBetweenToolsThinking) {
4471
+ warnings.push({
4472
+ type: "unsupported",
4473
+ feature: "providerOptions.anthropic.thinking",
4474
+ details: `thinking cannot be disabled for ${modelId}. Using 'between_tools' thinking, the lowest thinking setting, instead.`
4475
+ });
4476
+ anthropicOptions.thinking = { type: "between_tools" };
4477
+ } else if (thinking.type === "disabled") {
4418
4478
  warnings.push({
4419
4479
  type: "unsupported",
4420
4480
  feature: "providerOptions.anthropic.thinking",
@@ -4438,8 +4498,16 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4438
4498
  });
4439
4499
  anthropicOptions.effort = "high";
4440
4500
  }
4501
+ if (anthropicOptions?.thinking?.type === "between_tools" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
4502
+ warnings.push({
4503
+ type: "unsupported",
4504
+ feature: "providerOptions.anthropic.effort",
4505
+ details: `effort '${anthropicOptions.effort}' is not supported with 'between_tools' thinking. The effort has been lowered to 'high'.`
4506
+ });
4507
+ anthropicOptions.effort = "high";
4508
+ }
4441
4509
  const thinkingType = anthropicOptions?.thinking?.type;
4442
- const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
4510
+ const isThinking = thinkingType === "enabled" || thinkingType === "adaptive" || thinkingType === "between_tools";
4443
4511
  const thinkingBlockBinding = anthropicOptions?.thinking != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
4444
4512
  const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
4445
4513
  let thinkingBudget = thinkingType === "enabled" ? anthropicOptions?.thinking?.budgetTokens : void 0;
@@ -6332,7 +6400,7 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
6332
6400
  }
6333
6401
  };
6334
6402
  function getModelCapabilities(modelId) {
6335
- if (modelId.includes("claude-opus-5-5")) {
6403
+ if (modelId.includes("claude-sonnet-5-5")) {
6336
6404
  return {
6337
6405
  maxOutputTokens: 128e3,
6338
6406
  supportsStructuredOutput: true,
@@ -6342,6 +6410,20 @@ function getModelCapabilities(modelId) {
6342
6410
  rejectsThinkingDisabledAboveHighEffort: true,
6343
6411
  rejectsThinkingDisabled: true,
6344
6412
  rejectsForcedToolUse: true,
6413
+ supportsBetweenToolsThinking: true,
6414
+ isKnownModel: true
6415
+ };
6416
+ } else if (modelId.includes("claude-opus-5-5")) {
6417
+ return {
6418
+ maxOutputTokens: 128e3,
6419
+ supportsStructuredOutput: true,
6420
+ supportsAdaptiveThinking: true,
6421
+ rejectsSamplingParameters: true,
6422
+ supportsXhighEffort: true,
6423
+ rejectsThinkingDisabledAboveHighEffort: true,
6424
+ rejectsThinkingDisabled: true,
6425
+ rejectsForcedToolUse: true,
6426
+ supportsBetweenToolsThinking: false,
6345
6427
  isKnownModel: true
6346
6428
  };
6347
6429
  } else if (modelId.includes("claude-opus-5")) {
@@ -6354,6 +6436,7 @@ function getModelCapabilities(modelId) {
6354
6436
  rejectsThinkingDisabledAboveHighEffort: true,
6355
6437
  rejectsThinkingDisabled: false,
6356
6438
  rejectsForcedToolUse: false,
6439
+ supportsBetweenToolsThinking: false,
6357
6440
  isKnownModel: true
6358
6441
  };
6359
6442
  } else if (modelId.includes("claude-fable-5-1")) {
@@ -6366,6 +6449,7 @@ function getModelCapabilities(modelId) {
6366
6449
  rejectsThinkingDisabledAboveHighEffort: false,
6367
6450
  rejectsThinkingDisabled: true,
6368
6451
  rejectsForcedToolUse: true,
6452
+ supportsBetweenToolsThinking: false,
6369
6453
  isKnownModel: true
6370
6454
  };
6371
6455
  } else if (modelId.includes("claude-fable-5")) {
@@ -6378,6 +6462,7 @@ function getModelCapabilities(modelId) {
6378
6462
  rejectsThinkingDisabledAboveHighEffort: false,
6379
6463
  rejectsThinkingDisabled: true,
6380
6464
  rejectsForcedToolUse: false,
6465
+ supportsBetweenToolsThinking: false,
6381
6466
  isKnownModel: true
6382
6467
  };
6383
6468
  } else if (modelId.includes("claude-opus-4-8") || modelId.includes("claude-opus-4-7") || modelId.includes("claude-sonnet-5")) {
@@ -6390,6 +6475,7 @@ function getModelCapabilities(modelId) {
6390
6475
  rejectsThinkingDisabledAboveHighEffort: false,
6391
6476
  rejectsThinkingDisabled: false,
6392
6477
  rejectsForcedToolUse: false,
6478
+ supportsBetweenToolsThinking: false,
6393
6479
  isKnownModel: true
6394
6480
  };
6395
6481
  } else if (modelId.includes("claude-sonnet-4-6") || modelId.includes("claude-opus-4-6")) {
@@ -6402,6 +6488,7 @@ function getModelCapabilities(modelId) {
6402
6488
  rejectsThinkingDisabledAboveHighEffort: false,
6403
6489
  rejectsThinkingDisabled: false,
6404
6490
  rejectsForcedToolUse: false,
6491
+ supportsBetweenToolsThinking: false,
6405
6492
  isKnownModel: true
6406
6493
  };
6407
6494
  } else if (modelId.includes("claude-sonnet-4-5") || modelId.includes("claude-opus-4-5") || modelId.includes("claude-haiku-4-5")) {
@@ -6414,6 +6501,7 @@ function getModelCapabilities(modelId) {
6414
6501
  rejectsThinkingDisabledAboveHighEffort: false,
6415
6502
  rejectsThinkingDisabled: false,
6416
6503
  rejectsForcedToolUse: false,
6504
+ supportsBetweenToolsThinking: false,
6417
6505
  isKnownModel: true
6418
6506
  };
6419
6507
  } else if (modelId.includes("claude-opus-4-1")) {
@@ -6426,6 +6514,7 @@ function getModelCapabilities(modelId) {
6426
6514
  rejectsThinkingDisabledAboveHighEffort: false,
6427
6515
  rejectsThinkingDisabled: false,
6428
6516
  rejectsForcedToolUse: false,
6517
+ supportsBetweenToolsThinking: false,
6429
6518
  isKnownModel: true
6430
6519
  };
6431
6520
  } else if (/claude-sonnet-4(?:-|@)/.test(modelId)) {
@@ -6438,6 +6527,7 @@ function getModelCapabilities(modelId) {
6438
6527
  rejectsThinkingDisabledAboveHighEffort: false,
6439
6528
  rejectsThinkingDisabled: false,
6440
6529
  rejectsForcedToolUse: false,
6530
+ supportsBetweenToolsThinking: false,
6441
6531
  isKnownModel: true
6442
6532
  };
6443
6533
  } else if (/claude-opus-4(?:-|@)/.test(modelId)) {
@@ -6450,6 +6540,7 @@ function getModelCapabilities(modelId) {
6450
6540
  rejectsThinkingDisabledAboveHighEffort: false,
6451
6541
  rejectsThinkingDisabled: false,
6452
6542
  rejectsForcedToolUse: false,
6543
+ supportsBetweenToolsThinking: false,
6453
6544
  isKnownModel: true
6454
6545
  };
6455
6546
  } else if (modelId.includes("claude-3-haiku")) {
@@ -6462,6 +6553,7 @@ function getModelCapabilities(modelId) {
6462
6553
  rejectsThinkingDisabledAboveHighEffort: false,
6463
6554
  rejectsThinkingDisabled: false,
6464
6555
  rejectsForcedToolUse: false,
6556
+ supportsBetweenToolsThinking: false,
6465
6557
  isKnownModel: true
6466
6558
  };
6467
6559
  } else if (/claude-(?:instant(?:-|$)|v?2(?=$|[-.:])|3(?=$|[-.]))/.test(modelId)) {
@@ -6474,6 +6566,7 @@ function getModelCapabilities(modelId) {
6474
6566
  rejectsThinkingDisabledAboveHighEffort: false,
6475
6567
  rejectsThinkingDisabled: false,
6476
6568
  rejectsForcedToolUse: false,
6569
+ supportsBetweenToolsThinking: false,
6477
6570
  isKnownModel: false
6478
6571
  };
6479
6572
  } else if (modelId.includes("claude-")) {
@@ -6486,6 +6579,7 @@ function getModelCapabilities(modelId) {
6486
6579
  rejectsThinkingDisabledAboveHighEffort: true,
6487
6580
  rejectsThinkingDisabled: false,
6488
6581
  rejectsForcedToolUse: false,
6582
+ supportsBetweenToolsThinking: false,
6489
6583
  isKnownModel: false
6490
6584
  };
6491
6585
  } else {
@@ -6498,6 +6592,7 @@ function getModelCapabilities(modelId) {
6498
6592
  rejectsThinkingDisabledAboveHighEffort: false,
6499
6593
  rejectsThinkingDisabled: false,
6500
6594
  rejectsForcedToolUse: false,
6595
+ supportsBetweenToolsThinking: false,
6501
6596
  isKnownModel: false
6502
6597
  };
6503
6598
  }
@@ -6526,6 +6621,7 @@ function resolveAnthropicReasoningConfig({
6526
6621
  supportsAdaptiveThinking,
6527
6622
  supportsXhighEffort,
6528
6623
  rejectsThinkingDisabled,
6624
+ supportsBetweenToolsThinking,
6529
6625
  maxOutputTokensForModel,
6530
6626
  warnings
6531
6627
  }) {
@@ -6533,6 +6629,9 @@ function resolveAnthropicReasoningConfig({
6533
6629
  return void 0;
6534
6630
  }
6535
6631
  if (reasoning === "none") {
6632
+ if (supportsBetweenToolsThinking) {
6633
+ return { thinking: { type: "between_tools" } };
6634
+ }
6536
6635
  if (rejectsThinkingDisabled) {
6537
6636
  warnings.push({
6538
6637
  type: "compatibility",
@@ -8306,7 +8405,7 @@ var AnthropicSkills = class {
8306
8405
  };
8307
8406
 
8308
8407
  // src/version.ts
8309
- var VERSION = true ? "4.0.65" : "0.0.0-test";
8408
+ var VERSION = true ? "4.0.67" : "0.0.0-test";
8310
8409
 
8311
8410
  // src/anthropic-provider.ts
8312
8411
  var ANTHROPIC_API_URL = "https://api.anthropic.com";