Skip to content

fix(anthropic): route thinking requests through OpenAI responses - #20755

Merged
2 commits merged into
BerriAI:litellm_oss_staging_02_09_2026from
whitehatjr1001:fix/20433-anthropic-thinking-routing
Feb 10, 2026
Merged

fix(anthropic): route thinking requests through OpenAI responses#20755
2 commits merged into
BerriAI:litellm_oss_staging_02_09_2026from
whitehatjr1001:fix/20433-anthropic-thinking-routing

Conversation

@whitehatjr1001

@whitehatjr1001 whitehatjr1001 commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Relevant issues

Fixes #20433 (OpenAI “thinking” requests routed via Anthropic adapter previously hit Chat Completions and returned only token counts).

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • [ x] I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • Added targeted tests in tests/litellm/llms/anthropic/experimental_pass_through/... that exercise the OpenAI-thinking routing change.
  • [ x] My PR passes all unit tests on make test-unit
  • [ x] My PR's scope is as isolated as possible, it only solves 1 specific problem
  • Change scope limited to the Anthropic experimental pass-through adapter, supporting test, and repro script.

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changes

1.)LiteLLMMessagesToCompletionTransformationHandler._route_openai_thinking_to_responses_api_if_needed in handler.py it now inspects the completion kwargs (inferring custom_llm_provider from the model when missing), rewrites OpenAI targets to responses/, and ensures reasoning_effort includes summary: "detailed" whenever thinking={"type":"enabled"} so the request heads through the Responses API and returns a reasoning “thinking” block instead of just token counts.
2.) Updated the Anthropic handler tests test_anthropic_experimental_pass_through_messages_handler.py to assert the new routing behavior.

@CLAassistant

CLAassistant commented Feb 9, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@vercel

vercel Bot commented Feb 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 10, 2026 3:01am

Request Review

@greptile-apps

greptile-apps Bot commented Feb 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR fixes an issue where OpenAI "thinking" requests routed via Anthropic adapter hit Chat Completions and only returned token counts instead of actual reasoning content. The fix routes these requests through OpenAI's Responses API by prepending responses/ to the model name and adding summary: "detailed" to the reasoning_effort parameter.

Key Changes:

  • Added _route_openai_thinking_to_responses_api_if_needed method that detects OpenAI models with thinking enabled and modifies the model path and reasoning_effort parameters
  • Updated test to verify the new routing behavior with correct model prefix and reasoning_effort structure
  • The fix is scoped to the Anthropic experimental pass-through adapter and doesn't affect other code paths

Confidence Score: 4/5

  • This PR is safe to merge with one minor consideration about model string manipulation
  • The implementation is clean and well-tested with a focused scope. The logic correctly routes OpenAI thinking requests through the Responses API. However, there's a potential edge case with the string prefix check that could be more robust.
  • handler.py line 66 - model string manipulation could benefit from stricter validation

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/handler.py Adds _route_openai_thinking_to_responses_api_if_needed method to route OpenAI thinking requests through Responses API and ensure reasoning summary is included
tests/test_litellm/llms/anthropic/experimental_pass_through/messages/test_anthropic_experimental_pass_through_messages_handler.py Updates test assertions to verify the new routing behavior with responses/ prefix and summary: "detailed" in reasoning_effort

Sequence Diagram

sequenceDiagram
    participant User
    participant AnthropicAdapter
    participant Handler as LiteLLMMessagesToCompletionTransformationHandler
    participant RouteLogic as _route_openai_thinking_to_responses_api_if_needed
    participant LiteLLM as litellm.completion
    participant OpenAI as OpenAI Responses API

    User->>AnthropicAdapter: messages.create(model="openai/gpt-5.2", thinking={"type": "enabled"})
    AnthropicAdapter->>Handler: anthropic_messages_handler()
    Handler->>Handler: _prepare_completion_kwargs()
    Note over Handler: Translates Anthropic format to OpenAI format<br/>Converts thinking to reasoning_effort
    Handler->>RouteLogic: _route_openai_thinking_to_responses_api_if_needed()
    
    alt is OpenAI model with thinking enabled
        RouteLogic->>RouteLogic: Check custom_llm_provider == "openai"
        RouteLogic->>RouteLogic: Check thinking.type == "enabled"
        RouteLogic->>RouteLogic: Prepend "responses/" to model
        Note over RouteLogic: model: "gpt-5.2" → "responses/gpt-5.2"
        RouteLogic->>RouteLogic: Add summary: "detailed" to reasoning_effort
        Note over RouteLogic: reasoning_effort: "minimal" →<br/>{"effort": "minimal", "summary": "detailed"}
    end
    
    Handler->>LiteLLM: completion(model="responses/gpt-5.2", reasoning_effort={...})
    LiteLLM->>OpenAI: POST to Responses API
    OpenAI-->>LiteLLM: Response with reasoning content block
    LiteLLM-->>Handler: ModelResponse
    Handler->>Handler: translate_completion_output_params()
    Handler-->>AnthropicAdapter: AnthropicMessagesResponse
    AnthropicAdapter-->>User: Response with thinking content
Loading

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

2 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread litellm/llms/anthropic/experimental_pass_through/adapters/handler.py Outdated
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
@ghost
ghost changed the base branch from main to litellm_oss_staging_02_09_2026 February 10, 2026 02:59
@ghost
ghost merged commit d2ee4a7 into BerriAI:litellm_oss_staging_02_09_2026 Feb 10, 2026
4 of 8 checks passed
model = completion_kwargs.get("model")
if isinstance(model, str) and model and not model.startswith("responses/"):

reasoning_effort = completion_kwargs.get("reasoning_effort")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

THis is an indentation error. Please be careful as this broke the whole pipeline

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure will double cheak do I need to make changes and commit ?? I see the pr is merged

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I handled it

Sameerlite pushed a commit that referenced this pull request Feb 10, 2026
)

* fix(anthropic): route thinking requests through OpenAI responses

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…riAI#20755)

* fix(anthropic): route thinking requests through OpenAI responses

* Apply suggestion from @greptile-apps[bot]

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>

---------

Co-authored-by: Krish Dholakia <krrishdholakia@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
This pull request was closed.
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.

[Bug]: anthropic.messages.acreate() with OpenAI target doesn't return reasoning content (uses Chat Completions instead of Responses API)

3 participants