@ai-sdk/anthropic 4.0.46 → 4.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.
@@ -15,7 +15,7 @@ declare class AnthropicFiles implements FilesV4 {
15
15
  readonly specificationVersion = "v4";
16
16
  get provider(): string;
17
17
  constructor(config: AnthropicFilesConfig);
18
- uploadFile({ data, mediaType, filename, }: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult>;
18
+ uploadFile({ data, mediaType, filename, abortSignal, headers, }: FilesV4UploadFileCallOptions): Promise<FilesV4UploadFileResult>;
19
19
  }
20
20
 
21
21
  type AnthropicMessage = AnthropicUserMessage | AnthropicAssistantMessage | AnthropicSystemMessage;
@@ -26,6 +26,10 @@ type AnthropicCacheControl = {
26
26
  interface AnthropicSystemMessage {
27
27
  role: 'system';
28
28
  content: Array<AnthropicTextContent | AnthropicToolChangeContent>;
29
+ clear_at?: 'next_user_message';
30
+ output_config?: {
31
+ effort: 'low' | 'medium' | 'high' | 'xhigh' | 'max';
32
+ };
29
33
  }
30
34
  /**
31
35
  * Mid-conversation tool change content block. Adds or removes a tool from the
@@ -753,7 +757,7 @@ type Citation = NonNullable<(InferSchema<typeof anthropicResponseSchema>['conten
753
757
  type: 'text';
754
758
  })['citations']>[number];
755
759
 
756
- 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-fable-5' | 'claude-sonnet-5' | (string & {});
760
+ 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-fable-5' | 'claude-fable-5-1' | 'claude-sonnet-5' | (string & {});
757
761
 
758
762
  type AnthropicLanguageModelConfig = {
759
763
  provider: string;
@@ -890,9 +894,12 @@ declare class AnthropicLanguageModel implements LanguageModelV4 {
890
894
  effort?: "low" | "medium" | "high" | "xhigh" | "max" | undefined;
891
895
  } | undefined;
892
896
  thinking?: {
893
- display?: "omitted" | "summarized" | undefined;
897
+ block_binding?: {
898
+ prefix_mismatch_behavior: "drop_block";
899
+ } | undefined;
900
+ display?: "omitted" | "summarized" | "updates" | undefined;
894
901
  budget_tokens?: number | undefined;
895
- type: "enabled" | "adaptive" | "disabled";
902
+ type?: "enabled" | "adaptive" | "disabled" | undefined;
896
903
  } | undefined;
897
904
  model: AnthropicModelId;
898
905
  max_tokens: number;
@@ -57,7 +57,9 @@ var AnthropicFiles = class {
57
57
  async uploadFile({
58
58
  data,
59
59
  mediaType,
60
- filename
60
+ filename,
61
+ abortSignal,
62
+ headers
61
63
  }) {
62
64
  var _a, _b;
63
65
  const fileBytes = convertInlineFileDataToUint8Array(data);
@@ -70,14 +72,17 @@ var AnthropicFiles = class {
70
72
  }
71
73
  const { value: response } = await postFormDataToApi({
72
74
  url: `${this.config.baseURL}/files`,
73
- headers: combineHeaders(this.config.headers(), {
74
- "anthropic-beta": "files-api-2025-04-14"
75
- }),
75
+ headers: combineHeaders(
76
+ this.config.headers(),
77
+ { "anthropic-beta": "files-api-2025-04-14" },
78
+ headers
79
+ ),
76
80
  formData,
77
81
  failedResponseHandler: anthropicFailedResponseHandler,
78
82
  successfulResponseHandler: createJsonResponseHandler(
79
83
  anthropicUploadFileResponseSchema
80
84
  ),
85
+ abortSignal,
81
86
  fetch: this.config.fetch
82
87
  });
83
88
  return {
@@ -953,6 +958,20 @@ var anthropicFilePartProviderOptions = z4.object({
953
958
  context: z4.string().optional()
954
959
  });
955
960
  var anthropicSystemMessageProviderOptions = z4.object({
961
+ /**
962
+ * Controls when an ephemeral mid-conversation system message is cleared.
963
+ *
964
+ * Only supported on system messages that appear mid-conversation.
965
+ * The required `mid-conversation-system-clear-at-2026-08-21` beta is
966
+ * added automatically.
967
+ */
968
+ clearAt: z4.literal("next_user_message").optional(),
969
+ /**
970
+ * Sets the model effort for the turn that follows this mid-conversation
971
+ * system message. The required `mid-conversation-effort-2026-08-01` beta
972
+ * is added automatically.
973
+ */
974
+ effort: z4.enum(["low", "medium", "high", "xhigh", "max"]).optional(),
956
975
  /**
957
976
  * Mid-conversation tool changes. Adds or removes tools from the
958
977
  * conversation's tool set between turns without invalidating the prompt
@@ -1001,24 +1020,40 @@ var anthropicLanguageModelOptions = z4.object({
1001
1020
  * When enabled, responses include thinking content blocks showing Claude's thinking process before the final answer.
1002
1021
  * Requires a minimum budget of 1,024 tokens and counts towards the `max_tokens` limit.
1003
1022
  */
1004
- thinking: z4.discriminatedUnion("type", [
1005
- z4.object({
1006
- /** for Sonnet 4.6, Opus 4.6, and newer models */
1007
- type: z4.literal("adaptive"),
1008
- /**
1009
- * Controls whether thinking content is included in the response.
1010
- * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
1011
- * - `"summarized"`: Thinking content is returned. Required to see reasoning output.
1012
- */
1013
- display: z4.enum(["omitted", "summarized"]).optional()
1014
- }),
1015
- z4.object({
1016
- /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
1017
- type: z4.literal("enabled"),
1018
- budgetTokens: z4.number().optional()
1019
- }),
1023
+ thinking: z4.union([
1024
+ z4.discriminatedUnion("type", [
1025
+ z4.object({
1026
+ /** for Sonnet 4.6, Opus 4.6, and newer models */
1027
+ type: z4.literal("adaptive"),
1028
+ /**
1029
+ * Controls whether thinking content is included in the response.
1030
+ * - `"omitted"`: Thinking blocks are present but text is empty (default for Opus 4.7+).
1031
+ * - `"summarized"`: Thinking content is returned.
1032
+ * - `"updates"`: Thinking updates are returned between tool calls.
1033
+ */
1034
+ display: z4.enum(["omitted", "summarized", "updates"]).optional(),
1035
+ /**
1036
+ * Controls how thinking blocks are bound to an existing thinking
1037
+ * prefix. Requires the `thinking-binding-controls-2026-08-01` beta.
1038
+ */
1039
+ blockBinding: z4.object({
1040
+ prefixMismatchBehavior: z4.literal("drop_block")
1041
+ }).optional()
1042
+ }),
1043
+ z4.object({
1044
+ /** for models before Opus 4.6, except Sonnet 4.6 still supports it */
1045
+ type: z4.literal("enabled"),
1046
+ budgetTokens: z4.number().optional()
1047
+ }),
1048
+ z4.object({
1049
+ type: z4.literal("disabled")
1050
+ })
1051
+ ]),
1020
1052
  z4.object({
1021
- type: z4.literal("disabled")
1053
+ type: z4.never().optional(),
1054
+ blockBinding: z4.object({
1055
+ prefixMismatchBehavior: z4.literal("drop_block")
1056
+ })
1022
1057
  })
1023
1058
  ]).optional(),
1024
1059
  /**
@@ -2435,8 +2470,7 @@ async function convertToAnthropicPrompt({
2435
2470
  const type = block.type;
2436
2471
  switch (type) {
2437
2472
  case "system": {
2438
- const content = [];
2439
- let toolChangeCount = 0;
2473
+ const convertedMessages = [];
2440
2474
  for (const { content: text, providerOptions } of block.messages) {
2441
2475
  const systemMessageOptions = await parseProviderOptions({
2442
2476
  provider: "anthropic",
@@ -2444,7 +2478,8 @@ async function convertToAnthropicPrompt({
2444
2478
  schema: anthropicSystemMessageProviderOptions
2445
2479
  });
2446
2480
  const toolChanges = (_a = systemMessageOptions == null ? void 0 : systemMessageOptions.toolChanges) != null ? _a : [];
2447
- if (text !== "" || toolChanges.length === 0) {
2481
+ const content = [];
2482
+ if (text !== "" || toolChanges.length === 0 && (systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt) == null && (systemMessageOptions == null ? void 0 : systemMessageOptions.effort) == null) {
2448
2483
  content.push({
2449
2484
  type: "text",
2450
2485
  text,
@@ -2455,7 +2490,6 @@ async function convertToAnthropicPrompt({
2455
2490
  });
2456
2491
  }
2457
2492
  for (const toolChange of toolChanges) {
2458
- toolChangeCount++;
2459
2493
  content.push({
2460
2494
  type: toolChange.type,
2461
2495
  tool: {
@@ -2464,22 +2498,60 @@ async function convertToAnthropicPrompt({
2464
2498
  }
2465
2499
  });
2466
2500
  }
2501
+ convertedMessages.push({
2502
+ content,
2503
+ clearAt: systemMessageOptions == null ? void 0 : systemMessageOptions.clearAt,
2504
+ effort: systemMessageOptions == null ? void 0 : systemMessageOptions.effort,
2505
+ toolChangeCount: toolChanges.length
2506
+ });
2467
2507
  }
2468
- if (i === 0 || system == null && toolChangeCount === 0) {
2508
+ const toolChangeCount = convertedMessages.reduce(
2509
+ (count, message) => count + message.toolChangeCount,
2510
+ 0
2511
+ );
2512
+ const hasInlineSystemOptions = convertedMessages.some(
2513
+ (message) => message.clearAt != null || message.effort != null
2514
+ );
2515
+ if (i === 0 || system == null && toolChangeCount === 0 && !hasInlineSystemOptions) {
2469
2516
  if (toolChangeCount > 0) {
2470
2517
  warnings.push({
2471
2518
  type: "other",
2472
2519
  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."
2473
2520
  });
2474
2521
  }
2475
- system = content.filter(
2476
- (part) => part.type === "text"
2522
+ for (const message of convertedMessages) {
2523
+ if (message.clearAt != null || message.effort != null) {
2524
+ warnings.push({
2525
+ type: "other",
2526
+ message: "clearAt and effort on the initial system message are not supported by Anthropic. These options have been ignored."
2527
+ });
2528
+ }
2529
+ }
2530
+ system = convertedMessages.flatMap(
2531
+ (message) => message.content.filter(
2532
+ (part) => part.type === "text"
2533
+ )
2477
2534
  );
2478
2535
  } else {
2479
- messages.push({ role: "system", content });
2480
2536
  betas.add("mid-conversation-system-2026-04-07");
2481
- if (toolChangeCount > 0) {
2482
- betas.add("mid-conversation-tool-changes-2026-07-01");
2537
+ for (const message of convertedMessages) {
2538
+ messages.push({
2539
+ role: "system",
2540
+ content: message.content,
2541
+ ...message.clearAt != null && { clear_at: message.clearAt },
2542
+ ...message.effort != null && {
2543
+ output_config: { effort: message.effort }
2544
+ }
2545
+ });
2546
+ if (message.toolChangeCount > 0) {
2547
+ betas.add("mid-conversation-tool-changes-2026-07-01");
2548
+ }
2549
+ if (message.clearAt != null) {
2550
+ betas.add("mid-conversation-system-clear-at-2026-08-21");
2551
+ }
2552
+ if (message.effort != null) {
2553
+ betas.add("mid-conversation-effort-2026-08-01");
2554
+ }
2483
2555
  }
2484
2556
  }
2485
2557
  break;
@@ -3900,7 +3972,8 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3900
3972
  }
3901
3973
  const thinkingType = (_g = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _g.type;
3902
3974
  const isThinking = thinkingType === "enabled" || thinkingType === "adaptive";
3903
- const sendThinking = isThinking || thinkingType === "disabled";
3975
+ const thinkingBlockBinding = (anthropicOptions == null ? void 0 : anthropicOptions.thinking) != null && "blockBinding" in anthropicOptions.thinking ? anthropicOptions.thinking.blockBinding : void 0;
3976
+ const sendThinking = isThinking || thinkingType === "disabled" || thinkingBlockBinding != null;
3904
3977
  let thinkingBudget = thinkingType === "enabled" ? (_h = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _h.budgetTokens : void 0;
3905
3978
  const thinkingDisplay = thinkingType === "adaptive" ? (_i = anthropicOptions == null ? void 0 : anthropicOptions.thinking) == null ? void 0 : _i.display : void 0;
3906
3979
  const maxTokens = maxOutputTokens != null ? maxOutputTokens : maxOutputTokensForModel;
@@ -3916,9 +3989,14 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
3916
3989
  // provider specific settings:
3917
3990
  ...sendThinking && {
3918
3991
  thinking: {
3919
- type: thinkingType,
3992
+ ...thinkingType != null && { type: thinkingType },
3920
3993
  ...thinkingBudget != null && { budget_tokens: thinkingBudget },
3921
- ...thinkingDisplay != null && { display: thinkingDisplay }
3994
+ ...thinkingDisplay != null && { display: thinkingDisplay },
3995
+ ...thinkingBlockBinding != null && {
3996
+ block_binding: {
3997
+ prefix_mismatch_behavior: thinkingBlockBinding.prefixMismatchBehavior
3998
+ }
3999
+ }
3922
4000
  }
3923
4001
  },
3924
4002
  ...((anthropicOptions == null ? void 0 : anthropicOptions.effort) || (anthropicOptions == null ? void 0 : anthropicOptions.taskBudget) || useStructuredOutput && (responseFormat == null ? void 0 : responseFormat.type) === "json" && responseFormat.schema != null) && {
@@ -4134,6 +4212,12 @@ var AnthropicLanguageModel = class _AnthropicLanguageModel {
4134
4212
  if ((anthropicOptions == null ? void 0 : anthropicOptions.speed) === "fast") {
4135
4213
  betas.add("fast-mode-2026-02-01");
4136
4214
  }
4215
+ if (thinkingDisplay === "updates") {
4216
+ betas.add("thinking-display-updates-2026-08-18");
4217
+ }
4218
+ if (thinkingBlockBinding != null) {
4219
+ betas.add("thinking-binding-controls-2026-08-01");
4220
+ }
4137
4221
  if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) === "default") {
4138
4222
  betas.add("server-side-fallback-2026-07-01");
4139
4223
  } else if ((anthropicOptions == null ? void 0 : anthropicOptions.fallbacks) && anthropicOptions.fallbacks.length > 0) {