Skip to content

fix: force temperature=1 when thinking is enabled or adaptive#1

Merged
dotCipher merged 1 commit into
dotCipher:mainfrom
mateusz28011:fix/temperature-thinking-constraint
Mar 23, 2026
Merged

fix: force temperature=1 when thinking is enabled or adaptive#1
dotCipher merged 1 commit into
dotCipher:mainfrom
mateusz28011:fix/temperature-thinking-constraint

Conversation

@mateusz28011
Copy link
Copy Markdown
Contributor

Summary

  • Fixes temperature may only be set to 1 when thinking is enabled or in adaptive mode API error
  • The bridge auto-injects thinking: { type: "adaptive" } for non-Haiku models, but forwards the original temperature value unchanged — Anthropic rejects any value other than 1 (or omitted) when thinking is active

Change

After the existing thinking injection block in the fetch wrapper, adds a guard that forces temperature = 1 when:

  • thinking.type is "enabled" or "adaptive", AND
  • temperature is explicitly set to something other than 1

If temperature is not present in the body at all, it is left untouched (the API defaults to 1).

Testing

Verified on OpenCode 1.2.27 with Claude Sonnet 4.6 via OAuth — the error no longer occurs.

Reference

https://docs.claude.com/en/docs/build-with-claude/extended-thinking#important-considerations-when-using-extended-thinking

@dotCipher
Copy link
Copy Markdown
Owner

Thanks @mateusz28011 — verified this against the API. temperature=0.5 with thinking=adaptive returns a clear 400: "temperature may only be set to 1 when thinking is enabled or in adaptive mode". The guard is clean and correctly scoped (only forces when temperature is explicitly set to non-1). Merging.

@dotCipher dotCipher merged commit 2ccd8ea into dotCipher:main Mar 23, 2026
dotCipher added a commit that referenced this pull request Mar 23, 2026
Fixes Anthropic API rejection when OpenCode sends a custom temperature
with adaptive thinking active. Credit: @mateusz28011 (#1)
@dotCipher
Copy link
Copy Markdown
Owner

Released in v1.5.0. Upgrade: cd ~/.cache/opencode && npm install opencode-claude-bridge@latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants