Skip to content

Commit d9932a1

Browse files
dkindlundrekram1-node
authored andcommitted
fix(opencode): let config opt out of Anthropic thinking blockBinding
type is "adaptive" or "enabled", on the premise that "models that do not run the check accept the field, so it is safe on every Claude". That premise does not hold. Since 1.18.26 shipped, anomalyco#46729 collects the same failure on three independent surfaces -- AWS Bedrock, Google Vertex, and Anthropic-compatible proxy endpoints -- all returning: thinking.adaptive.block_binding: Extra inputs are not permitted Probing an Anthropic-compatible endpoint directly with curl (no opencode in the path) narrows it further: thinking {"type":"adaptive"} -> OK thinking {"type":"adaptive"} + block_binding -> rejected thinking {"type":"adaptive"} + block_binding + beta header -> rejected thinking {"type":"enabled",budget_tokens} + block_binding -> OK So the field is refused specifically under thinking.adaptive, and sending thinking-binding-controls-2026-08-01 does not change that. Because the injection is unconditional there is no way out: affected users must pin 1.18.25. That is worse on managed installs, where a root-owned config wins the merge, so overriding options.thinking.type or registering a corrected provider both fail. Honour an explicit blockBinding in config instead of always overwriting it: blockBinding: false -> omit the field entirely blockBinding: {...} -> use the caller's value absent (unchanged default) -> inject ANTHROPIC_BLOCK_BINDING as today Default behaviour is untouched, so deployments that accept the field keep it. Applies to @ai-sdk/anthropic, @ai-sdk/google-vertex/anthropic, and the bedrock reasoningConfig path alike. Tests: 4 added covering opt-out on adaptive, opt-out on a think-by-default model, preserving an explicit value, and the bedrock path. Verified red/green -- 440 pass / 4 fail without the source change, 444 pass / 0 fail with it.
1 parent ef27925 commit d9932a1

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

‎packages/opencode/src/provider/transform.ts‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,19 +705,32 @@ function anthropicBindsThinking(apiId: string) {
705705
// The patched AI SDK adds the thinking-binding-controls beta whenever it is set.
706706
const ANTHROPIC_BLOCK_BINDING = { prefixMismatchBehavior: "drop_block" }
707707

708+
// Not every Claude deployment accepts the field after all. Bedrock, Vertex and
709+
// Anthropic-compatible proxy endpoints have each been observed rejecting it with
710+
// thinking.adaptive.block_binding: Extra inputs are not permitted
711+
// (#46729), and sending the thinking-binding-controls beta does not change that.
712+
// Honour an explicit `blockBinding` in config so those deployments can opt out with
713+
// `blockBinding: false` (or pin their own value) instead of being stuck on 1.18.25.
714+
function applyBlockBinding(config: { [x: string]: any }) {
715+
if (!("blockBinding" in config)) return { ...config, blockBinding: ANTHROPIC_BLOCK_BINDING }
716+
if (config.blockBinding) return config
717+
const { blockBinding: _disabled, ...rest } = config
718+
return rest
719+
}
720+
708721
function anthropicBlockBinding(model: Provider.Model, options: { [x: string]: any }) {
709722
if (!anthropicBindsThinking(model.api.id)) return options
710723
switch (model.api.npm) {
711724
case "@ai-sdk/anthropic":
712725
case "@ai-sdk/google-vertex/anthropic": {
713726
const thinking = options.thinking ?? { type: "adaptive" }
714727
if (thinking.type !== "adaptive" && thinking.type !== "enabled") return options
715-
return { ...options, thinking: { ...thinking, blockBinding: ANTHROPIC_BLOCK_BINDING } }
728+
return { ...options, thinking: applyBlockBinding(thinking) }
716729
}
717730
case "@ai-sdk/amazon-bedrock": {
718731
const reasoningConfig = options.reasoningConfig ?? { type: "adaptive" }
719732
if (reasoningConfig.type !== "adaptive" && reasoningConfig.type !== "enabled") return options
720-
return { ...options, reasoningConfig: { ...reasoningConfig, blockBinding: ANTHROPIC_BLOCK_BINDING } }
733+
return { ...options, reasoningConfig: applyBlockBinding(reasoningConfig) }
721734
}
722735
}
723736
return options

‎packages/opencode/test/provider/transform.test.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,43 @@ describe("ProviderTransform.providerOptions", () => {
10481048
})
10491049
})
10501050

1051+
test("omits blockBinding when config opts out with false", () => {
1052+
const model = claude("@ai-sdk/anthropic", "claude-opus-5")
1053+
expect(
1054+
ProviderTransform.providerOptions(model, { thinking: { type: "adaptive", blockBinding: false } }),
1055+
).toEqual({
1056+
anthropic: { thinking: { type: "adaptive" } },
1057+
})
1058+
})
1059+
1060+
test("opt-out also works for models that think by default", () => {
1061+
const model = claude("@ai-sdk/anthropic", "claude-sonnet-5")
1062+
expect(
1063+
ProviderTransform.providerOptions(model, { thinking: { type: "enabled", budgetTokens: 4000, blockBinding: false } }),
1064+
).toEqual({
1065+
anthropic: { thinking: { type: "enabled", budgetTokens: 4000 } },
1066+
})
1067+
})
1068+
1069+
test("preserves an explicit blockBinding instead of overwriting it", () => {
1070+
const model = claude("@ai-sdk/anthropic", "claude-opus-5")
1071+
const custom = { prefixMismatchBehavior: "error" }
1072+
expect(
1073+
ProviderTransform.providerOptions(model, { thinking: { type: "adaptive", blockBinding: custom } }),
1074+
).toEqual({
1075+
anthropic: { thinking: { type: "adaptive", blockBinding: custom } },
1076+
})
1077+
})
1078+
1079+
test("bedrock reasoningConfig honours the opt-out", () => {
1080+
const model = claude("@ai-sdk/amazon-bedrock", "us.anthropic.claude-opus-5-v1:0")
1081+
expect(
1082+
ProviderTransform.providerOptions(model, { reasoningConfig: { type: "adaptive", blockBinding: false } }),
1083+
).toEqual({
1084+
bedrock: { reasoningConfig: { type: "adaptive" } },
1085+
})
1086+
})
1087+
10511088
test("does not touch bedrock non-anthropic models", () => {
10521089
const model = claude("@ai-sdk/amazon-bedrock", "amazon.nova-pro-v1:0")
10531090
expect(ProviderTransform.providerOptions(model, { reasoningConfig: { type: "enabled" } })).toEqual({

0 commit comments

Comments
 (0)