Skip to content

[Bug]: LiteLLM proxy models send both temperature and top_p to Anthropic (regression in v1.15.0) #2686

Closed

Description

@jpshackelford

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Describe the bug and reproduction steps

After PR #2277 ("Refine temperature/top_p handling for reasoning models"), models accessed via LiteLLM proxy incorrectly send both temperature and top_p to Anthropic, causing API errors.

Reproduction:

from openhands.sdk.llm.options.chat_options import select_chat_options

class MockLLM:
    model = "litellm_proxy/prod/claude-opus-4-5-20251101"
    temperature = 0.7
    top_p = 0.95
    top_k = None
    max_output_tokens = 4096
    extra_headers = None
    reasoning_effort = None
    extended_thinking_budget = None
    litellm_extra_body = None
    prompt_cache_retention = None

llm = MockLLM()
result = select_chat_options(llm, {}, has_tools=True)
print(result)
# v1.14.0: {'max_completion_tokens': 4096}  ✅
# v1.15.0+: {'top_p': 0.95, 'temperature': 0.7, 'max_completion_tokens': 4096}  ❌

Error from Anthropic:

AnthropicException - {"type":"error","error":{"type":"invalid_request_error",
"message":"`temperature` and `top_p` cannot both be specified for this model."}}

Root Cause

PR #2277 changed the logic to preserve temperature/top_p for Gemini models:

if supports_reasoning_effort:
    if "gemini" not in llm.model.lower():
        out.pop("temperature", None)
        out.pop("top_p", None)

However, supports_reasoning_effort relies on LiteLLM's get_supported_openai_params() which doesn't recognize proxy-prefixed models like prod/claude-opus-4-5-20251101 (after stripping litellm_proxy/).

Since supports_reasoning_effort returns False, the removal logic never triggers, and both parameters get sent.

Version Bisection

SDK Version Result
v1.14.0 ✅ Neither temperature nor top_p sent
v1.15.0 ❌ Both sent (regression)
v1.16.1 ❌ Both sent

Suggested Fix

The model pattern matching should be more robust. Options:

  1. Check for model name patterns (e.g., claude-opus) regardless of prefix
  2. Strip additional path components beyond litellm_proxy/ before querying LiteLLM
  3. Always remove one of temperature/top_p if both are set for Anthropic models

Related


This issue was created by an AI assistant (OpenHands) on behalf of the user.

Activity

  1. added
    bug
    and removed on Apr 2, 2026
  2. self-assigned this
    on Apr 2, 2026
  3. enyst commented on Apr 2, 2026

    @enyst
    Member

    We did two relevant things, I think:

    • remove default values for temperature and top_p
    • replace our hardcoded recognition of reasoning models with LiteLLM’s recognition.

    Though I don’t remember if both were as recent as 1.13 to 1.14

    Strange thing is, we run integration tests on litellm proxy. So I don’t think the agent is right on the assumed reason… but maybe I’m wrong.

    Just a thought: It might be worth verifying if the user has both temperature and top_p saved in agent_settings.json… 🤔 After the removal of default values, I’m guessing we don’t save them anymore

  4. enyst commented on Apr 2, 2026

    @enyst
    Member

    To note, 2277 is extremely unlikely to have caused this. It only keeps them for Gemini 🤔

    Curious what your investigation will uncover, thank you for taking at look at this!

  5. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    Good catch @enyst.

    Yes! The ~/.openhands/agent_settings.json file does have both temperature and top_p settings:
    • "temperature": 0.0
    • "top_p": 1.0

    Condenser LLM settings (nested under condenser.llm):
    • "temperature": 0.0
    • "top_p": 1.0

    Both are explicitly set in the configuration. But probably not explicitly set by the user. The user setup LLM via cli login.

  6. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    Investigation Results

    I've thoroughly investigated this issue and have findings that clarify both the agent's and @enyst's observations.

    TL;DR

    The agent identified the wrong PR. The regression was caused by PR #1990 (refactor(llm): use litellm params for reasoning support), not PR #2277.

    PR #2277 only adds a Gemini exception inside the if supports_reasoning_effort: block. Since supports_reasoning_effort is False for this model, PR #2277's changes never execute.


    Evidence

    1. v1.14.0 vs v1.15.0+ Model Recognition

    # Testing model: litellm_proxy/prod/claude-opus-4-5-20251101
    
    # v1.14.0 (substring matching against hardcoded REASONING_EFFORT_MODELS list):
    # "claude-opus-4-5" is a substring of the model name
    supports_reasoning_effort = True  # ✅
    
    # v1.15.0+ (LiteLLM function call):
    # After stripping "litellm_proxy/", model is "prod/claude-opus-4-5-20251101"
    # LiteLLM doesn't recognize "prod/..." as a valid model path
    get_supported_openai_params("prod/claude-opus-4-5-20251101") → 0 params
    supports_reasoning_effort = False  # ❌

    2. LiteLLM Recognition Issue

    Model                                      → params, reasoning_effort
    ─────────────────────────────────────────────────────────────────────
    prod/claude-opus-4-5-20251101              → 0, False
    claude-opus-4-5-20251101                   → 18, True
    anthropic/claude-opus-4-5-20251101         → 18, True
    

    The SDK strips litellm_proxy/ but leaves prod/, and LiteLLM doesn't recognize that as a valid model path.

    3. Why PR #2277 Is Not the Cause

    PR #2277 changed:

    # Before:
    if supports_reasoning_effort:
        out.pop("temperature", None)
        out.pop("top_p", None)
    
    # After:
    if supports_reasoning_effort:
        if "gemini" not in llm.model.lower():  # ← Only affects Gemini
            out.pop("temperature", None)
            out.pop("top_p", None)

    Since supports_reasoning_effort is False for litellm_proxy/prod/claude-opus-4-5-20251101, this entire block is skipped. PR #2277's changes are irrelevant.


    @enyst's Hypothesis

    @enyst correctly identified that the user has temperature=0.0 and top_p=1.0 in agent_settings.json. However, this is not the root cause — in v1.14.0, these values would still have been removed for reasoning models because the model was correctly identified via substring matching.


    Summary

    Claim Verdict
    Agent: PR #2277 caused regression ❌ Incorrect
    Engle: User config has temp/top_p ✅ True (but not root cause)
    Actual cause: PR #1990 ✅

    Suggested Fix

    The model normalization in _normalized_supported_openai_params() should be smarter about stripping proxy deployment path prefixes. Options:

    1. Strip additional path components after litellm_proxy/ (e.g., prod/)
    2. Use the original substring matching as a fallback when LiteLLM returns 0 params
    3. Try multiple normalization strategies until LiteLLM recognizes the model

    This investigation was conducted by an AI assistant (OpenHands) on behalf of the user.

  7. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    Investigation: How temperature: 0.0 and top_p: 1.0 Ended Up in agent_settings.json

    Root Cause

    The values in the user's ~/.openhands/agent_settings.json came from SDK default values that were serialized when the CLI saved the agent configuration during an older SDK version.

    Timeline

    1. Prior to SDK v1.12.0, the LLM class had these defaults:

      • temperature defaulted to 0.0 (set by get_default_temperature() function)
      • top_p defaulted to 1.0 (hardcoded)
    2. PR Set default temperature to None instead of 0.0 #1989 ("Set default temperature to None instead of 0.0") changed these to None:

      • Merged into SDK starting with v1.12.0
      • Both temperature and top_p now default to None
    3. When the user ran openhands login (or any CLI operation that calls AgentStore.save()) while using SDK v1.11.x or earlier:

      • The CLI creates an LLM instance without explicitly setting temperature/top_p
      • The LLM class applies its defaults (temperature=0.0, top_p=1.0)
      • The CLI serializes the entire Agent (including LLM with defaults) via model_dump_json()
      • These values get persisted to ~/.openhands/agent_settings.json

    Evidence

    Verified by installing SDK 1.11.0:

    from openhands.sdk import LLM
    llm = LLM(model='claude-sonnet-4-5-20250929', api_key='test-key')
    # SDK 1.11.0: temperature=0.0, top_p=1.0
    # SDK 1.16.1: temperature=None, top_p=None

    Why This Causes the Bug

    The user's stale settings file still contains temperature: 0.0 and top_p: 1.0. When loaded, these values are passed to the LLM API. For reasoning models (like Claude Opus 4.5):

    1. PR Refine temperature/top_p handling for reasoning models #2277 changed the logic to strip temp/top_p only when supports_reasoning_effort=True
    2. For proxy-prefixed models like litellm_proxy/prod/claude-opus-4-5-20251101, LiteLLM can't recognize them
    3. So supports_reasoning_effort=False, and the old saved values get sent
    4. Anthropic rejects requests that have both parameters set

    Solution Options

    1. User workaround: Delete ~/.openhands/agent_settings.json and re-run openhands login to regenerate with None defaults
    2. SDK fix: Better handling of proxy model names in supports_reasoning_effort() check
    3. CLI fix: Migration script to update stale settings, or exclude None-equivalent defaults from serialization

    This comment was created by an AI assistant (OpenHands) on behalf of the user.

  8. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    Reproduction Confirmed: LiteLLM Model Recognition Issue

    I've reproduced the issue identified in the investigation comments. The root cause is confirmed:

    The Problem

    When using a proxy model like litellm_proxy/prod/claude-opus-4-5-20251101:

    1. The SDK strips litellm_proxy/ prefix → prod/claude-opus-4-5-20251101
    2. LiteLLM's get_supported_openai_params() doesn't recognize prod/... as a valid model path
    3. Returns 0 params → supports_reasoning_effort = False
    4. Temperature/top_p are NOT stripped from the request
    5. Anthropic rejects with "temperature and top_p cannot both be specified"

    Reproduction Evidence

    Testing LiteLLM model recognition:
    ================================================================================
    Model                                              | Params | reasoning_effort
    --------------------------------------------------------------------------------
    prod/claude-opus-4-5-20251101                      | 0      | False   ❌
    claude-opus-4-5-20251101                           | 15     | True    ✅
    anthropic/claude-opus-4-5-20251101                 | 15     | True    ✅
    
    Testing select_chat_options() with temperature=0.0 and top_p=1.0:
    Model: litellm_proxy/prod/claude-opus-4-5-20251101
      supports_reasoning_effort: False
      ❌ BOTH temperature and top_p present: {'top_p': 1.0, 'temperature': 0.0, 'max_completion_tokens': 4096}
      --> Anthropic will reject: 'temperature and top_p cannot both be specified'
    
    Model: anthropic/claude-opus-4-5-20251101  
      supports_reasoning_effort: True
      ✅ Neither temperature nor top_p present: {'max_completion_tokens': 4096}
    

    Verified Fix Strategy

    Stripping deployment prefixes (prod/, dev/, staging/, etc.) in addition to litellm_proxy/ fixes the issue:

    After litellm_proxy/ removal: prod/claude-opus-4-5-20251101
        → 0 params, reasoning_effort=False
    
    After deployment prefix removal: claude-opus-4-5-20251101
        → 15 params, reasoning_effort=True ✅
    

    Summary

    Both identified causes are valid:

    1. agent_settings.json - Contains stale temperature: 0.0 and top_p: 1.0 from old SDK defaults
    2. LiteLLM model recognition - Fails to recognize proxy-prefixed models like prod/claude-opus-4-5-20251101

    A proper fix should address the model normalization in _normalized_supported_openai_params() to strip common deployment path prefixes.


    This comment was created by an AI assistant (OpenHands) on behalf of the user.

  9. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    I have also confirmed that when the old agent_settings.json file is removed, and we use openhands login, the temperature and top_p values are null.

    @enyst Given this analysis do we want to:

    a. Address the model normalization in _normalized_supported_openai_params() to strip common deployment path prefixes
    b. Have the CLI detect bad matches for thinking models on startup and clean up agent_settings.json
    c. Both a. and b.?

  10. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    SDK Fix Summary

    The fix is in _normalized_supported_openai_params() in model_features.py. After stripping litellm_proxy/, it needs to also strip common deployment path prefixes like prod/, dev/, staging/, etc.

    Current behavior:

    litellm_proxy/prod/claude-opus-4-5-20251101
      → strips litellm_proxy/
      → prod/claude-opus-4-5-20251101
      → LiteLLM returns 0 params (unrecognized)
      → supports_reasoning_effort = False ❌
    

    After fix:

    litellm_proxy/prod/claude-opus-4-5-20251101
      → strips litellm_proxy/
      → strips prod/
      → claude-opus-4-5-20251101
      → LiteLLM returns 15 params
      → supports_reasoning_effort = True ✅
    

    Implementation: Strip deployment prefixes (prod/, dev/, staging/, test/) after stripping litellm_proxy/.

    Note: The issue description incorrectly blames PR #2277. The actual regression was PR #1990 which switched from substring matching to LiteLLM's get_supported_openai_params().


    This comment was created by an AI assistant (OpenHands) on behalf of the user.

  11. added a commit that references this issue on Apr 3, 2026
    04c22b5
  12. enyst commented on Apr 3, 2026

    @enyst
    Member

    Wow ugh thank you for the investigation. 😓

    a. Address the model normalization in _normalized_supported_openai_params() to strip common deployment path prefixes
    b. Have the CLI detect bad matches for thinking models on startup and clean up agent_settings.json
    c. Both a. and b.?

    Trying to understand the cause here, so it seems that (a.) implies:

    • litellm SDK's model recognition fails for litellm_proxy/prod/claude-opus-4-5-20251101
    • that is, get_supported_openai_params() returns 0 params for that
    • but get_supported_openai_params() returns 15 params for claude-opus-4-5-20251101

    So litellm's get_supported_openai_params() works for regular models out there, 100x, 200x LLMs and providers, BUT not so well for a liteLLM Proxy installation, because then it doesn't recognize the names set by the user in the proxy

    Which is obvious but also funny.

    Is it possible to use canonical / canonical_model model name attribute from LLM class?

    I believe we have added a "canonical" extra precisely so that users that connect to Proxies with unusual names or changed model names, can tell us (and we tell litellm) the "canonical" model used in reality.

  13. jpshackelford commented on Apr 3, 2026

    @jpshackelford
    MemberAuthor

    Thanks for the suggestion @enyst! Using model_canonical_name is definitely the right approach architecturally.

    Immediate fix for this PR: We should update the PR to check model_canonical_name first and use it if set, before falling back to the prefix-stripping heuristics. Currently chat_options.py uses llm.model directly instead of llm._model_name_for_capabilities() which already handles this.

    For auto-discovery, we could move the heuristics into the LLM class so they're centralized. A few options:

    1. Lazy computation in _model_name_for_capabilities() - Keep the field optional, apply heuristics in this method when model_canonical_name isn't set. Least invasive change.

    2. Auto-set during LLM init - If model_canonical_name isn't provided, compute it from model using heuristics and store it. Makes canonical name always available.

    3. Computed property - Make model_canonical_name a property that returns the explicit value if set, otherwise computes it. Similar to Setup Makefile, Pre-commit, and initial Tool and Schema definition #1 but different API surface.

    All three keep the heuristics in the LLM class (where model configuration lives) rather than scattered in feature detection code. Users who need to override can still set model_canonical_name explicitly.

    Forcing users to manually supply the canonical name is a non-starter since that would mean changes to web UI and unnecessary manual steps for the user, but I don't think you were proposing that as part of the scope for addressing this issue.

    What's your preference? We can update the PR accordingly.


    This comment was created by an AI assistant (OpenHands) on behalf of @jpshackelford.

  14. enyst commented on Apr 3, 2026

    @enyst
    Member

    I'd love to know another thing, I didn't fully understand, sorry: why "prod", where did it come from?

    Workaround: Delete ~/.openhands/agent_settings.json and re-run openhands login to regenerate with current SDK defaults.

    So it came from openhands login ?

    I ask because a while ago, Xingyao has removed prod from proxies, I thought. Or maybe I'm wrong? Why are we setting "prod/"? If it's an openhands/ prefixed LLM, shouldn't we set

    • model name openhands/modelname, for which the SDK will send litellm_proxy/ I think
    • base url will be set by the SDK to app proxy

    So there's no prod ? Could it be that the CLI still sets some 'prod/' somehow, or?

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

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions