Skip to content

fix: don't send temperature to Claude models that reject it - #2217

Open
pcbeingused333 wants to merge 1 commit into
assafelovic:mainfrom
pcbeingused333:fix/claude-sampling-params
Open

pcbeingused333 wants to merge 1 commit into
assafelovic:mainfrom
pcbeingused333:fix/claude-sampling-params

Conversation

@pcbeingused333

Copy link
Copy Markdown

create_chat_completion sends temperature unless the model is in NO_SUPPORT_TEMPERATURE_MODELS. The Claude part of that list stops at claude-opus-4-7 and is matched exactly, so these models still get a temperature (0.25–0.4 depending on the step), and Anthropic answers with a 400:

  • claude-opus-4-8, claude-opus-5, claude-opus-5-5
  • claude-sonnet-5, claude-sonnet-5-5, claude-haiku-5-5 (the last two reject any non-default value)
  • claude-fable-5, claude-fable-5-1, claude-mythos-*
  • Bedrock and OpenRouter ids of the same models, e.g. anthropic.claude-opus-5-5, us.anthropic.claude-opus-4-7-v1:0, anthropic/claude-sonnet-5. Even claude-opus-4-7, which is on the list, isn't matched in that form.

Change

  • llm_provider/generic/base.py: new NO_SUPPORT_TEMPERATURE_MODEL_PREFIXES for the Claude families that reject sampling parameters, and supports_temperature(model). It checks the existing exact list first, then the prefixes on the bare model name, after dropping an anthropic. (Bedrock) or vendor/ (OpenRouter) prefix. The existing list is unchanged.
  • utils/llm.py: uses supports_temperature() instead of model not in NO_SUPPORT_TEMPERATURE_MODELS. That's the only place the list is read. The tool-calling path in utils/tools.py doesn't set a temperature, and its fallback goes through create_chat_completion.
  • tests/test_claude_temperature.py (new): the models above get temperature=None, and gpt-4.1 still gets the requested value.

Testing

$ pytest tests/test_claude_temperature.py tests/test_llm_kwargs_override.py tests/test_llm_max_tokens.py
17 passed        # before the change: 10 failed (temperature == 0.4), 1 passed

A wider pytest tests run (backend and docs excluded) gives 550 passed, 31 failed. The failures are the same with and without this change (MCP config, retriever and websocket-import tests that need optional packages or fail because of test order).

I made this change with Claude Code and checked the result myself.

🤖 Generated with Claude Code

The Claude entries in NO_SUPPORT_TEMPERATURE_MODELS stop at
claude-opus-4-7 and only match exact ids, so claude-opus-4-8, the
Claude 5 family (Opus, Sonnet, Haiku), Fable and Mythos got a
temperature and failed with a 400, as did Bedrock and OpenRouter
ids such as anthropic.claude-opus-5-5 or anthropic/claude-sonnet-5.
Match those families by prefix after dropping the provider prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant