@ai-sdk/anthropic 3.0.115 → 3.0.117

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.
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = '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-fable-5' | 'claude-sonnet-5' | (string & {});
5
+ type AnthropicMessagesModelId = '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-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -2,7 +2,7 @@ import { LanguageModelV3, LanguageModelV3CallOptions, LanguageModelV3GenerateRes
2
2
  import * as _ai_sdk_provider_utils from '@ai-sdk/provider-utils';
3
3
  import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
4
4
 
5
- type AnthropicMessagesModelId = '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-fable-5' | 'claude-sonnet-5' | (string & {});
5
+ type AnthropicMessagesModelId = '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-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
6
6
 
7
7
  type AnthropicMessagesConfig = {
8
8
  provider: string;
@@ -860,6 +860,21 @@ var anthropicFilePartProviderOptions = import_v43.z.object({
860
860
  context: import_v43.z.string().optional()
861
861
  });
862
862
  var anthropicSystemMessageProviderOptions = import_v43.z.object({
863
+ /**
864
+ * Clears this mid-conversation system message after the current turn.
865
+ *
866
+ * Requires the `mid-conversation-system-clear-at-2026-08-21` beta,
867
+ * which is added automatically.
868
+ */
869
+ clearAt: import_v43.z.literal("next_user_message").optional(),
870
+ /**
871
+ * Overrides the effort level for the turn following this
872
+ * mid-conversation system message.
873
+ *
874
+ * Requires the `mid-conversation-effort-2026-08-01` beta,
875
+ * which is added automatically.
876
+ */
877
+ effort: import_v43.z.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
863
878
  /**
864
879
  * Mid-conversation tool changes. Adds or removes tools from the
865
880
  * conversation's tool set between turns without invalidating the prompt
@@ -887,6 +902,9 @@ var anthropicSystemMessageProviderOptions = import_v43.z.object({
887
902
  ])
888
903
  ).optional()
889
904
  });
905
+ var anthropicThinkingBlockBinding = import_v43.z.object({
906
+ prefixMismatchBehavior: import_v43.z.literal("drop_block")
907
+ });
890
908
  var anthropicLanguageModelOptions = import_v43.z.object({
891
909
  /**
892
910
  * Whether to send reasoning to the model.
@@ -908,24 +926,41 @@ var anthropicLanguageModelOptions = import_v43.z.object({
908
926
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
909
927
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
910
928
  */
911
- thinking: import_v43.z.discriminatedUnion("type", [
912
- import_v43.z.object({
913
- /** for Sonnet 4.6, Opus 4.6, and newer models */
914
- type: import_v43.z.literal("adaptive"),
915
- /**
916
- * Controls whether thinking content is included in the response.
917
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
918
- * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
919
- */
920
- display: import_v43.z.enum(["omitted", "summarized"]).optional()
921
- }),
922
- import_v43.z.object({
923
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
924
- type: import_v43.z.literal("enabled"),
925
- budgetTokens: import_v43.z.number().optional()
926
- }),
929
+ thinking: import_v43.z.union([
930
+ import_v43.z.discriminatedUnion("type", [
931
+ import_v43.z.object({
932
+ /** for Sonnet 4.6, Opus 4.6, and newer models */
933
+ type: import_v43.z.literal("adaptive"),
934
+ /**
935
+ * Controls whether thinking content is included in the response.
936
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
937
+ * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
938
+ * - `"updates"`: Thinking updates are returned between tool calls.
939
+ */
940
+ display: import_v43.z.enum(["omitted", "summarized", "updates"]).optional(),
941
+ /**
942
+ * Controls how thinking blocks are bound to an assistant prefix.
943
+ *
944
+ * Requires the `thinking-binding-controls-2026-08-01` beta,
945
+ * which is added automatically.
946
+ */
947
+ blockBinding: anthropicThinkingBlockBinding.optional()
948
+ }),
949
+ import_v43.z.object({
950
+ /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
951
+ type: import_v43.z.literal("enabled"),
952
+ budgetTokens: import_v43.z.number().optional()
953
+ }),
954
+ import_v43.z.object({
955
+ type: import_v43.z.literal("disabled")
956
+ })
957
+ ]),
958
+ /**
959
+ * Configures prefix mismatch recovery without changing the model's
960
+ * default thinking mode.
961
+ */
927
962
  import_v43.z.object({
928
- type: import_v43.z.literal("disabled")
963
+ blockBinding: anthropicThinkingBlockBinding
929
964
  })
930
965
  ]).optional(),
931
966
  /**
@@ -2245,8 +2280,9 @@ async function convertToAnthropicMessagesPrompt({
2245
2280
  const type = block.type;
2246
2281
  switch (type) {
2247
2282
  case "system": {
2248
- const content = [];
2283
+ const systemMessages = [];
2249
2284
  let toolChangeCount = 0;
2285
+ let hasMidConversationOptions = false;
2250
2286
  for (const { content: text, providerOptions } of block.messages) {
2251
2287
  const systemMessageOptions = await (0, import_provider_utils14.parseProviderOptions)({
2252
2288
  provider: "anthropic",
@@ -2254,7 +2290,10 @@ async function convertToAnthropicMessagesPrompt({
2254
2290
  schema: anthropicSystemMessageProviderOptions
2255
2291
  });
2256
2292
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2257
- if (text !== "" || toolChanges.length === 0) {
2293
+ const clearAt = systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt;
2294
+ const effort = systemMessageOptions == null ? void 0 : systemMessageOptions.effort;
2295
+ const content = [];
2296
+ if (text !== "" || toolChanges.length === 0 && clearAt == null && effort == null) {
2258
2297
  content.push({
2259
2298
  type: "text",
2260
2299
  text,
@@ -2274,23 +2313,44 @@ async function convertToAnthropicMessagesPrompt({
2274
2313
  }
2275
2314
  });
2276
2315
  }
2316
+ hasMidConversationOptions || (hasMidConversationOptions = clearAt != null || effort != null);
2317
+ systemMessages.push({
2318
+ role: "system",
2319
+ content,
2320
+ ...clearAt != null && { clear_at: clearAt },
2321
+ ...effort != null && { output_config: { effort } }
2322
+ });
2277
2323
  }
2278
- if (i === 0 || system == null && toolChangeCount === 0) {
2324
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasMidConversationOptions) {
2279
2325
  if (toolChangeCount > 0) {
2280
2326
  warnings.push({
2281
2327
  type: "other",
2282
2328
  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."
2283
2329
  });
2284
2330
  }
2285
- system = content.filter(
2286
- (part) => part.type === "text"
2331
+ if (hasMidConversationOptions) {
2332
+ warnings.push({
2333
+ type: "other",
2334
+ message: "clearAt and effort on the initial system message are not supported by Anthropic. Configure these options on a mid-conversation system message instead. The options have been ignored."
2335
+ });
2336
+ }
2337
+ system = systemMessages.flatMap(
2338
+ (message) => message.content.filter(
2339
+ (part) => part.type === "text"
2340
+ )
2287
2341
  );
2288
2342
  } else {
2289
- messages.push({ role: "system", content });
2343
+ messages.push(...systemMessages);
2290
2344
  betas.add("mid-conversation-system-2026-04-07");
2291
2345
  if (toolChangeCount > 0) {
2292
2346
  betas.add("mid-conversation-tool-changes-2026-07-01");
2293
2347
  }
2348
+ if (systemMessages.some((message) => message.clear_at != null)) {
2349
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
2350
+ }
2351
+ if (systemMessages.some((message) => message.output_config != null)) {
2352
+ betas.add("mid-conversation-effort-2026-08-01");
2353
+ }
2294
2354
  }
2295
2355
  break;
2296
2356
  }
@@ -3406,7 +3466,7 @@ var AnthropicMessagesLanguageModel = class {
3406
3466
  providerOptions,
3407
3467
  stream
3408
3468
  }) {
3409
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
3469
+ var _a, _b, _c, _d, _e, _f, _g;
3410
3470
  const warnings = [];
3411
3471
  if (frequencyPenalty != null) {
3412
3472
  warnings.push({ type: "unsupported", feature: "frequencyPenalty" });
@@ -3549,7 +3609,9 @@ var AnthropicMessagesLanguageModel = class {
3549
3609
  cacheControlValidator,
3550
3610
  toolNameMapping
3551
3611
  });
3552
- if (rejectsThinkingDisabledAboveHighEffort && ((_e = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _e.type) === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3612
+ const thinking = anthropicOptions == null ? void 0 : anthropicOptions.thinking;
3613
+ const thinkingType = thinking != null && "type" in thinking ? thinking.type : void 0;
3614
+ if (rejectsThinkingDisabledAboveHighEffort && thinkingType === "disabled" && (anthropicOptions.effort === "xhigh" || anthropicOptions.effort === "max")) {
3553
3615
  warnings.push({
3554
3616
  type: "unsupported",
3555
3617
  feature: "providerOptions.anthropic.effort",
@@ -3557,11 +3619,12 @@ var AnthropicMessagesLanguageModel = class {
3557
3619
  });
3558
3620
  anthropicOptions.effort = "high";
3559
3621
  }
3560
- const thinkingType = (_f = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _f.type;
3561
3622
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3562
3623
  const sendThinking = isThinking || thinkingType === "disabled";
3563
- let thinkingBudget = thinkingType === "enabled" ? (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.budgetTokens : void 0;
3564
- const thinkingDisplay = thinkingType === "adaptive" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.display : void 0;
3624
+ let thinkingBudget = thinkingType === "enabled" && thinking != null && "budgetTokens" in thinking ? thinking.budgetTokens : void 0;
3625
+ const thinkingDisplay = thinkingType === "adaptive" && thinking != null && "display" in thinking ? thinking.display : void 0;
3626
+ const thinkingBlockBinding = thinking != null && "blockBinding" in thinking ? thinking.blockBinding : void 0;
3627
+ const sendThinkingConfig = sendThinking || thinkingBlockBinding != null;
3565
3628
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
3566
3629
  const baseArgs = {
3567
3630
  // model id:
@@ -3573,11 +3636,16 @@ var AnthropicMessagesLanguageModel = class {
3573
3636
  top_p: topP,
3574
3637
  stop_sequences: stopSequences,
3575
3638
  // provider specific settings:
3576
- ...sendThinking && {
3639
+ ...sendThinkingConfig && {
3577
3640
  thinking: {
3578
- type: thinkingType,
3641
+ ...thinkingType != null && { type: thinkingType },
3579
3642
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3580
- ...thinkingDisplay != null && { display: thinkingDisplay }
3643
+ ...thinkingDisplay != null && { display: thinkingDisplay },
3644
+ ...thinkingBlockBinding != null && {
3645
+ block_binding: {
3646
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
3647
+ }
3648
+ }
3581
3649
  }
3582
3650
  },
3583
3651
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -3614,7 +3682,7 @@ var AnthropicMessagesLanguageModel = class {
3614
3682
  ...(anthropicOptions == null ? void 0 : anthropicOptions.cacheControl) && {
3615
3683
  cache_control: anthropicOptions.cacheControl
3616
3684
  },
3617
- ...((_i = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _i.userId) != null && {
3685
+ ...((_e = anthropicOptions == null ? void 0 : anthropicOptions.metadata) == null ? void 0 : _e.userId) != null && {
3618
3686
  metadata: { user_id: anthropicOptions.metadata.userId }
3619
3687
  },
3620
3688
  // mcp servers:
@@ -3784,6 +3852,12 @@ var AnthropicMessagesLanguageModel = class {
3784
3852
  if (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) {
3785
3853
  betas.add("task-budgets-2026-03-13");
3786
3854
  }
3855
+ if (thinkingDisplay === "updates") {
3856
+ betas.add("thinking-display-updates-2026-08-18");
3857
+ }
3858
+ if (thinkingBlockBinding != null) {
3859
+ betas.add("thinking-binding-controls-2026-08-01");
3860
+ }
3787
3861
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
3788
3862
  betas.add("fast-mode-2026-02-01");
3789
3863
  }
@@ -3792,7 +3866,7 @@ var AnthropicMessagesLanguageModel = class {
3792
3866
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {
3793
3867
  betas.add("server-side-fallback-2026-06-01");
3794
3868
  }
3795
- const defaultEagerInputStreaming = stream && ((_j = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _j : true);
3869
+ const defaultEagerInputStreaming = stream && ((_f = anthropicOptions == null ? void 0 : anthropicOptions.toolStreaming) != null ? _f : true);
3796
3870
  const {
3797
3871
  tools: anthropicTools2,
3798
3872
  toolChoice: anthropicToolChoice,
@@ -3831,7 +3905,7 @@ var AnthropicMessagesLanguageModel = class {
3831
3905
  ...betas,
3832
3906
  ...toolsBetas,
3833
3907
  ...userSuppliedBetas,
3834
- ...(_k = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _k : []
3908
+ ...(_g = anthropicOptions == null ? void 0 : anthropicOptions.anthropicBeta) != null ? _g : []
3835
3909
  ]),
3836
3910
  usesJsonResponseTool: jsonResponseTool != null,
3837
3911
  toolNameMapping,