Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/ai-provider-bridge/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
// The per-effort thinking options are covered end to end by
// `anthropic-thinking-wire.test.ts` (real SDK) and `anthropic-thinking-routing.test.ts`.
describe("anthropicRequestOptions", () => {
const request = { transport: "anthropic", clientOptions: { toolStreaming: false } } as const;
const request = { clientOptions: { toolStreaming: false } } as const;

it("merges client options with and without thinking options", () => {
expect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ export class AnthropicClient implements ModelClient {

const { providerOptions, headers: requestHeaders } = anthropicRequestOptions({
effort: params.thinkingEffort,
transport: "anthropic",
blockBinding: params.thinkingBlockBinding,
clientOptions: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class BedrockClient implements ModelClient {
const anthropicOptions = isAnthropic
? anthropicRequestOptions({
effort: params.thinkingEffort,
transport: "bedrock",
blockBinding: params.thinkingBlockBinding,
clientOptions: rejectsEagerInputStreaming(params.model) ? { toolStreaming: false } : {},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export class GoogleVertexClient implements ModelClient {
const { providerOptions, headers: requestHeaders } = isAnthropic
? anthropicRequestOptions({
effort: params.thinkingEffort,
transport: "vertex",
blockBinding: params.thinkingBlockBinding,
clientOptions: {},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export interface ModelClientChatParams {
* Host policy for Anthropic thinking-block binding. The host sets it only for
* models that run the prefix check; absent means no binding controls are
* sent. Clients on the Anthropic Messages wire apply it with adaptive
* thinking and may veto it on transport grounds; other clients ignore it.
* thinking; other clients ignore it.
*/
thinkingBlockBinding?: ThinkingBlockBinding;
/** Context length hint for the model (e.g., Ollama num_ctx). From ModelInfo.maxContextLength. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ export class PositAiClient implements ModelClient {
if (normalizedProtocol === "anthropic-messages") {
const { providerOptions, headers: requestHeaders } = anthropicRequestOptions({
effort: params.thinkingEffort,
transport: "positai",
blockBinding: params.thinkingBlockBinding,
clientOptions: {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ export class SnowflakeClient implements ModelClient {
// Cortex; opt those out (see rejectsEagerInputStreaming). Others accept it.
const { providerOptions, headers: requestHeaders } = anthropicRequestOptions({
effort: params.thinkingEffort,
transport: "snowflake",
blockBinding: params.thinkingBlockBinding,
clientOptions: rejectsEagerInputStreaming(params.model) ? { toolStreaming: false } : {},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ describe.each([
name: "Bedrock",
client: new BedrockClient({ region: "us-east-1" }),
model: "anthropic.claude-haiku-5-5",
bindsThinking: true,
},
{
name: "Google Vertex",
Expand All @@ -127,22 +126,18 @@ describe.each([
logger,
),
model: "claude-haiku-5-5",
bindsThinking: true,
},
{
name: "Snowflake",
client: new SnowflakeClient("token", "https://acct.snowflakecomputing.com/api/v2/cortex"),
model: "claude-haiku-5-5",
bindsThinking: true,
},
{
name: "Posit AI",
client: new PositAiClient("token", "https://api.posit.example", "test-agent", logger),
model: "claude-haiku-5-5",
// The gateway rejects the beta: 400 "disallowed Anthropic-Beta value".
bindsThinking: false,
},
])("$name Claude thinking options", ({ client, model, bindsThinking }) => {
])("$name Claude thinking options", ({ client, model }) => {
it('disables thinking for "off"', async () => {
expect(await anthropicOptions(client, model, "off")).toEqual({
thinking: { type: "disabled" },
Expand All @@ -156,26 +151,24 @@ describe.each([
});
});

it("forwards the block-binding policy with adaptive thinking, unless the transport vetoes it", async () => {
it("forwards the block-binding policy with adaptive thinking", async () => {
expect(await streamTextOptions(client, model, "medium", "drop_block")).toEqual({
anthropic: {
thinking: {
type: "adaptive",
display: "summarized",
...(bindsThinking ? { blockBinding: { prefixMismatchBehavior: "drop_block" } } : {}),
blockBinding: { prefixMismatchBehavior: "drop_block" },
},
effort: "medium",
},
headers: undefined,
});
});

it("sends only the beta header for header-only, unless the transport vetoes it", async () => {
it("sends only the beta header for header-only", async () => {
expect(await streamTextOptions(client, model, "medium", "header-only")).toEqual({
anthropic: { thinking: { type: "adaptive", display: "summarized" }, effort: "medium" },
headers: bindsThinking
? { "anthropic-beta": "thinking-binding-controls-2026-08-01" }
: undefined,
headers: { "anthropic-beta": "thinking-binding-controls-2026-08-01" },
});
});

Expand Down
29 changes: 5 additions & 24 deletions packages/ai-provider-bridge/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,6 @@ export type ThinkingBlockBinding = "error" | "drop_block" | "header-only";
/** Beta that enables `thinking.block_binding` and `input_transformations`. */
export const THINKING_BINDING_BETA = "thinking-binding-controls-2026-08-01";

/** The transport a request on the Anthropic Messages wire travels over. */
export type AnthropicTransport = "anthropic" | "bedrock" | "vertex" | "positai" | "snowflake";

/**
* Transports whose endpoint rejects or drops thinking-block binding. Requests
* over them never carry the beta or the body field. Add a transport here when
* live verification shows it fails; see
* plans/2026-10-09-1737-preserved-thinking-sequencing.md (phase 0).
*
* - `positai`: the gateway rejects the request with 400 `disallowed
* Anthropic-Beta value: "thinking-binding-controls-2026-08-01"` (verified
* 2026-10-12 against staging). Remove once the gateway allows the beta.
*/
const TRANSPORTS_WITHOUT_BLOCK_BINDING: ReadonlySet<AnthropicTransport> = new Set(["positai"]);

type AnthropicThinkingOptions = {
thinking?:
| { type: "disabled" }
Expand Down Expand Up @@ -89,23 +74,19 @@ export type AnthropicRequestOptions = {
*
* `blockBinding` applies only with adaptive thinking: the API rejects
* `block_binding` next to `disabled`, and with the provider default PA replays
* no thinking, so there is nothing to bind. A transport in
* `TRANSPORTS_WITHOUT_BLOCK_BINDING` vetoes it. `"error"` and `"drop_block"`
* set the body field (the SDK adds the beta header); `"header-only"` adds only
* the beta header.
* no thinking, so there is nothing to bind. `"error"` and `"drop_block"` set
* the body field (the SDK adds the beta header); `"header-only"` adds only the
* beta header.
*
* `clientOptions` are merged on top.
*/
export function anthropicRequestOptions(request: {
effort: string | undefined;
transport: AnthropicTransport;
blockBinding: ThinkingBlockBinding | undefined;
clientOptions: AnthropicClientOptions;
}): AnthropicRequestOptions {
const { effort, transport, clientOptions } = request;
const adaptive = isThinkingEnabled(effort);
const blockBinding =
adaptive && !TRANSPORTS_WITHOUT_BLOCK_BINDING.has(transport) ? request.blockBinding : undefined;
const { effort, clientOptions } = request;
const blockBinding = isThinkingEnabled(effort) ? request.blockBinding : undefined;
const thinkingOptions: AnthropicThinkingOptions =
effort === undefined
? {}
Expand Down
Loading