From 923bda07a274447a44885c1ed4787d19ab5cc7f3 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Fri, 11 Sep 2026 12:29:18 -0500 Subject: [PATCH] feat(ai): always send interleaved thinking beta for Anthropic (#48521) --- packages/ai/src/protocols/anthropic-messages.ts | 5 ++++- packages/ai/test/provider/anthropic-compaction.test.ts | 4 +++- .../ai/test/provider/anthropic-thinking-binding.test.ts | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/packages/ai/src/protocols/anthropic-messages.ts b/packages/ai/src/protocols/anthropic-messages.ts index 1c4c32da3b8..b9d058d4ca8 100644 --- a/packages/ai/src/protocols/anthropic-messages.ts +++ b/packages/ai/src/protocols/anthropic-messages.ts @@ -1708,7 +1708,10 @@ export const transport = < } function requiredBetaHeaders(body: Pick) { - const betas: string[] = [] + // Always request interleaved thinking. The API accepts the header on any + // model and ignores it where unsupported, while manual-thinking models need + // it for thinking between tool calls. + const betas: string[] = ["interleaved-thinking-2025-05-14"] const requestsCompaction = (body.context_management?.edits.length ?? 0) > 0 const replaysCompaction = body.messages.some((message) => message.content.some((block) => block.type === "compaction"), diff --git a/packages/ai/test/provider/anthropic-compaction.test.ts b/packages/ai/test/provider/anthropic-compaction.test.ts index 04ce6e719cb..c23f881c1c4 100644 --- a/packages/ai/test/provider/anthropic-compaction.test.ts +++ b/packages/ai/test/provider/anthropic-compaction.test.ts @@ -69,7 +69,9 @@ for (const model of [ dynamicResponse(({ request, text, respond }) => Effect.sync(() => { const body = JSON.parse(text) - expect(request.headers["anthropic-beta"]).toBe("existing-beta,compact-2026-01-12") + expect(request.headers["anthropic-beta"]).toBe( + "existing-beta,interleaved-thinking-2025-05-14,compact-2026-01-12", + ) if (body.messages.length === 1) { expect(body.context_management.edits).toEqual([ { diff --git a/packages/ai/test/provider/anthropic-thinking-binding.test.ts b/packages/ai/test/provider/anthropic-thinking-binding.test.ts index 1258089f6de..3df8e873b77 100644 --- a/packages/ai/test/provider/anthropic-thinking-binding.test.ts +++ b/packages/ai/test/provider/anthropic-thinking-binding.test.ts @@ -32,7 +32,9 @@ for (const [id, enabled] of [ enabled ? { type: "adaptive", block_binding: { prefix_mismatch_behavior: "drop_block" } } : undefined, ) expect(prepared.request.headers["anthropic-beta"]).toBe( - enabled ? "existing-beta,thinking-binding-controls-2026-08-01" : "existing-beta", + enabled + ? "existing-beta,interleaved-thinking-2025-05-14,thinking-binding-controls-2026-08-01" + : "existing-beta,interleaved-thinking-2025-05-14", ) }), ) @@ -53,7 +55,9 @@ it.effect("preserves explicit thinking settings and combines required beta heade const prepared = yield* AnthropicMessages.route.prepareTransport(compiled.body, request) expect(compiled.body.thinking).toEqual(thinking) expect(prepared.request.headers["anthropic-beta"]).toBe( - thinking.type === "disabled" ? "compact-2026-01-12" : "compact-2026-01-12,thinking-binding-controls-2026-08-01", + thinking.type === "disabled" + ? "interleaved-thinking-2025-05-14,compact-2026-01-12" + : "interleaved-thinking-2025-05-14,compact-2026-01-12,thinking-binding-controls-2026-08-01", ) } }),