Skip to content

fix(llm): strip temperature/top_p for claude-opus-4-8 - #3427

Merged
juanmichelini merged 1 commit into
mainfrom
fix/claude-opus-4-8-strip-temperature
May 28, 2026
Merged

juanmichelini merged 1 commit into
mainfrom
fix/claude-opus-4-8-strip-temperature

Conversation

@juanmichelini

@juanmichelini juanmichelini commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Anthropic's claude-opus-4-8 is a reasoning-only model that rejects requests carrying temperature (or top_p) with:

AnthropicException - {"type":"error","error":{
  "type":"invalid_request_error",
  "message":"`temperature` is deprecated for this model."
}}

This breaks SWE-bench evaluation runs against the model — every conversation fails with LLMBadRequestError. Example: swebench/litellm_proxy-anthropic-claude-opus-4-8/26604804421 — all 3 critic attempts × all retries produced the same 400 from Anthropic.

Why the existing logic doesn't catch it

select_chat_options already strips temperature/top_p in two places:

  1. The reasoning-effort path — gated on _supports_reasoning_effort(), which delegates to litellm's get_supported_openai_params. Today litellm reports reasoning_effort: False for claude-opus-4-8 (and even temperature: True for the anthropic/... form), so this branch doesn't fire:

    claude-opus-4-8 -> temperature in supported: False | reasoning_effort: False
    anthropic/claude-opus-4-8 -> temperature in supported: True | reasoning_effort: False
    
  2. The extended-thinking path — gated on EXTENDED_THINKING_MODELS, but claude-opus-4-8 wasn't on the list.

Result: benchmark configs that explicitly set temperature=0.0 (e.g. SWE-bench litellm_extra_body) get the value forwarded and Anthropic rejects it.

The SDK integration tests in run 26599152082 didn't surface the issue because they leave LLM.temperature at its default None — so nothing was ever sent.

Fix

Add claude-opus-4-8 to EXTENDED_THINKING_MODELS. That routes it through the path already used for claude-sonnet-4-6 / claude-haiku-4-5, which:

  • strips temperature and top_p from the outgoing request, and
  • enables the thinking-budget header when extended_thinking_budget is configured (which the SWE-bench config already does: extended_thinking_budget=200000).

Changes

  • openhands-sdk/openhands/sdk/llm/utils/model_features.py — one entry added to EXTENDED_THINKING_MODELS with an explanatory comment.
  • tests/sdk/llm/test_model_features.py — extend the parametrized test_extended_thinking_support to cover bare, anthropic/ and litellm_proxy/anthropic/ forms of claude-opus-4-8, plus a negative for claude-opus-4-7.
  • tests/sdk/llm/test_chat_options.py — new test_claude_opus_4_8_strips_temp_and_top_p mirroring the existing sonnet-4-6 regression test.
 openhands-sdk/openhands/sdk/llm/utils/model_features.py |  5 +++++
 tests/sdk/llm/test_chat_options.py                      | 19 +++++++++++++++++++
 tests/sdk/llm/test_model_features.py                    |  4 ++++
 3 files changed, 28 insertions(+)

Validation

Targeted tests pass locally:

$ pytest tests/sdk/llm/test_model_features.py::test_extended_thinking_support \
         tests/sdk/llm/test_chat_options.py -q
33 passed

(Other failures observed in the broader tests/sdk/llm/ run are pre-existing environment issues — missing pytest-asyncio etc. — unrelated to this change.)

Follow-ups (not in this PR)

  • A more durable, model-agnostic fix would be to drop temperature/top_p whenever reasoning_effort or extended_thinking_budget is configured on an Anthropic model, so future reasoning-only Anthropic releases don't need a one-off entry here. Happy to do that as a separate PR if maintainers want it.

This PR was created by an AI agent (OpenHands) on behalf of the user.

@juanmichelini can click here to continue refining the PR


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.13-nodejs22-slim Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:f6e465f-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-f6e465f-python \
  ghcr.io/openhands/agent-server:f6e465f-python

All tags pushed for this build

ghcr.io/openhands/agent-server:f6e465f-golang-amd64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-golang-amd64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-golang-amd64
ghcr.io/openhands/agent-server:f6e465f-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:f6e465f-golang-arm64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-golang-arm64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-golang-arm64
ghcr.io/openhands/agent-server:f6e465f-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:f6e465f-java-amd64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-java-amd64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-java-amd64
ghcr.io/openhands/agent-server:f6e465f-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:f6e465f-java-arm64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-java-arm64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-java-arm64
ghcr.io/openhands/agent-server:f6e465f-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:f6e465f-python-amd64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-python-amd64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-python-amd64
ghcr.io/openhands/agent-server:f6e465f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-amd64
ghcr.io/openhands/agent-server:f6e465f-python-arm64
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-python-arm64
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-python-arm64
ghcr.io/openhands/agent-server:f6e465f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim-arm64
ghcr.io/openhands/agent-server:f6e465f-golang
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-golang
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-golang
ghcr.io/openhands/agent-server:f6e465f-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:f6e465f-java
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-java
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-java
ghcr.io/openhands/agent-server:f6e465f-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:f6e465f-python
ghcr.io/openhands/agent-server:f6e465fa490b1f7eb752fcad3b29232ad65d4f39-python
ghcr.io/openhands/agent-server:fix-claude-opus-4-8-strip-temperature-python
ghcr.io/openhands/agent-server:f6e465f-nikolaik_s_python-nodejs_tag_python3.13-nodejs22-slim

About Multi-Architecture Support

  • Each variant tag (e.g., f6e465f-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., f6e465f-python-amd64) are also available if needed

Anthropic's claude-opus-4-8 is a reasoning-only model that rejects
requests carrying `temperature` (and `top_p`) with:

    AnthropicException - {"type":"error","error":{
      "type":"invalid_request_error",
      "message":"`temperature` is deprecated for this model."
    }}

The model isn't yet flagged as supporting `reasoning_effort` by
litellm's `get_supported_openai_params`, so the reasoning-effort branch
in `select_chat_options` doesn't strip those params. Benchmark configs
(e.g. SWE-bench) that explicitly set `temperature=0.0` therefore fail
with a 400 on every call.

Add `claude-opus-4-8` to `EXTENDED_THINKING_MODELS` so it goes
through the extended-thinking path, which already strips temperature/top_p
and enables the thinking-budget header — consistent with how
claude-sonnet-4-6 and claude-haiku-4-5 are handled.

Co-authored-by: openhands <openhands@all-hands.dev>
@github-actions

Copy link
Copy Markdown
Contributor

Python API breakage checks — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@github-actions

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/llm/utils
   model_features.py58198%35
TOTAL28610830570% 

@juanmichelini
juanmichelini marked this pull request as ready for review May 28, 2026 23:25
@juanmichelini
juanmichelini enabled auto-merge (squash) May 28, 2026 23:26

all-hands-bot commented May 28, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Review complete.

This review was performed through OpenHands Cloud Automation. You can log in and view the conversation here.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: fix(llm): strip temperature/top_p for claude-opus-4-8

Clean, well-scoped fix. The approach — routing claude-opus-4-8 through the EXTENDED_THINKING_MODELS path — is the right lever to strip temperature/top_p before the Anthropic API sees them, and it is consistent with how other extended-thinking models are handled in this codebase.

What's well done:

  • Comment in EXTENDED_THINKING_MODELS clearly distinguishes the reason for including claude-opus-4-8 (API constraint: Anthropic rejects these params) from the reason other models appear here (performance). Future maintainers will not be confused about why this model is on the list.
  • test_claude_opus_4_8_strips_temp_and_top_p validates the actual end-to-end behavior (select_chat_options output) with the realistic litellm_proxy/anthropic/claude-opus-4-8 identifier used by SWE-bench runs.
  • test_extended_thinking_support additions cover three model-name variants (bare, anthropic/-prefixed, litellm_proxy/anthropic/-prefixed) and explicitly add claude-opus-4-7 as a negative case — a good regression guard.

Minor follow-up (out of scope for this PR): claude-opus-4-8 was already added to PROMPT_CACHE_MODELS before this change, but test_prompt_cache_support has no case for it. A follow-up test row there would close that coverage gap.

Overall, the change is minimal, well-documented, and well-tested. ✅

This review was generated by an AI agent (OpenHands) on behalf of the user through OpenHands Automation. View conversation

@juanmichelini
juanmichelini merged commit 45697f5 into main May 28, 2026
35 of 36 checks passed
@juanmichelini
juanmichelini deleted the fix/claude-opus-4-8-strip-temperature branch May 28, 2026 23:36

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ QA Report: PASS

The SDK now removes temperature and top_p from real LLM.completion() requests for litellm_proxy/anthropic/claude-opus-4-8.

Does this PR achieve its stated goal?

Yes. I reproduced the pre-PR behavior by running an actual SDK LLM.completion() call against a local capture endpoint: the outgoing chat-completions payload included temperature: 0.0 and top_p: 1.0. After applying the PR head, the same call succeeded and the captured payload contained only messages and model, so the deprecated Anthropic sampling fields are no longer forwarded for the target model.

Phase Result
Environment Setup ✅ make build completed successfully and installed the repo environment.
CI Status ⚠️ Core build/test/check jobs are green; PR is already merged, with cleanup-on-approval failed and a qa-changes run still in progress/cancelled.
Functional Verification ✅ Real SDK completion path exercised with before/after payload capture.
Functional Verification

Test 1: Claude Opus 4.8 no longer forwards deprecated sampling parameters

Step 1 — Reproduce / establish baseline without the fix:
Checked out the PR base commit e65a8abd1f86726b4ea11714311d20b879ed42cb, started a local HTTP capture server, and ran an actual SDK completion configured like the reported SWE-bench path:

git switch --detach e65a8abd1f86726b4ea11714311d20b879ed42cb
OPENHANDS_SUPPRESS_BANNER=1 uv run python <capture LLM.completion script>

Observed output:

completion_return_type= LLMResponse
{"git_ref": "e65a8abd (pre-PR)", "has_temperature": true, "has_thinking": false, "has_top_p": true, "request_keys": ["messages", "model", "temperature", "top_p"], "request_path": "/chat/completions", "temperature": 0.0, "thinking": null, "top_p": 1.0}

This confirms the bug boundary: the SDK forwarded temperature and top_p for litellm_proxy/anthropic/claude-opus-4-8, matching the Anthropic rejection described in the PR.

Step 2 — Apply the PR's changes:
Checked out PR head f6e465fa490b1f7eb752fcad3b29232ad65d4f39.

Step 3 — Re-run with the fix in place:
Ran the same SDK completion capture command:

git switch --detach f6e465fa490b1f7eb752fcad3b29232ad65d4f39
OPENHANDS_SUPPRESS_BANNER=1 uv run python <same capture LLM.completion script>

Observed output:

completion_return_type= LLMResponse
{"git_ref": "f6e465fa (PR head)", "has_temperature": false, "has_thinking": false, "has_top_p": false, "request_keys": ["messages", "model"], "request_path": "/chat/completions", "temperature": null, "thinking": null, "top_p": null}

This shows the fix works for the reported user path: the same real SDK completion call no longer sends the deprecated parameters.

Test 2: Stripping also occurs when no thinking budget is configured

On PR head, I repeated the completion capture with temperature=0.0 and top_p=1.0 but without extended_thinking_budget:

{"has_temperature": false, "has_top_p": false, "request_keys": ["messages", "model"]}

This confirms the model-specific stripping applies even outside the benchmark-specific thinking-budget configuration.

Issues Found

None.

This review was created by an AI agent (OpenHands) on behalf of the user.

@adshrc

adshrc commented May 29, 2026

Copy link
Copy Markdown

anthropic/claude-opus-4-8 is an "adaptive thinking" model (all Claude 4.6+) that require thinking.type = "adaptive" + output_config.effort. The EXTENDED_THINKING_MODELS list is sending thinking.type = "enabled" which Anthropic rejects for these models.

So this PR basically broke the support for anthropic/claude-opus-4-8

@adshrc

adshrc commented May 29, 2026

Copy link
Copy Markdown

I have tested it, it does not work:

litellm.BadRequestError: AnthropicException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"\\\"thinking.type.enabled\\\" is not supported for this model. Use \\\"thinking.type.adaptive\\\" and \\\"output_config.effort\\\" to control thinking behavior.\"},\"request_id\":\"req_011CbWhUgPbqJZAHVQjzUPqy\"}\n\nConversation logs are stored at: workspace/conversations/42065969cd2e468b983235806d47b7e2\n\nTo help debug this issue, please file a bug report at:\n https://github.com/OpenHands/software-agent-sdk/issues/new\nand attach the conversation logs from the directory above."}

juanmichelini added a commit that referenced this pull request May 29, 2026
#3441)

Co-authored-by: openhands <openhands@all-hands.dev>
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
Co-authored-by: openhands <openhands@all-hands.dev>
StressTestor pushed a commit to StressTestor/software-agent-sdk that referenced this pull request Jun 1, 2026
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
Co-authored-by: openhands <openhands@all-hands.dev>
pengzhang-create pushed a commit to Pyromind-Dynamics/software-agent-sdk that referenced this pull request Aug 13, 2026
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.

4 participants