Skip to content

fix(proxy): map output_config.effort to reasoning_effort for non-Anthropic providers - #25120

Closed
glaziermag wants to merge 2 commits into
BerriAI:mainfrom
glaziermag:fix-output-config-reasoning-effort
Closed

glaziermag wants to merge 2 commits into
BerriAI:mainfrom
glaziermag:fix-output-config-reasoning-effort

Conversation

@glaziermag

Copy link
Copy Markdown

Fix output_config.effort mapping for Anthropic pass-through endpoint (#25079)

Expected Outcome

When a user sends a /v1/messages request to LiteLLM proxy with output_config: { effort: "high" }, and the model routes to an OpenAI model, the output_config.effort parameter should be implicitly translated to the reasoning_effort: "high" parameter for the OpenAI-compatible request.

Actual Outcome & Debugging (Before vs After)

Before Logs

When testing with a straightforward proxy script routing openai-response models, the parameter was ignored and reasoning_effort was None.

$ python test_issue_25079.py
OpenAI request:
{'model': 'openai-response', 'messages': [{'role': 'user', 'content': 'Hello'}], 'output_config': {'effort': 'high'}}
FAILURE: reasoning_effort not mapped.
reasoning_effort is: None

After Logs (The Fix)

The problem resided in translate_anthropic_to_openai. By mapping the incoming output_config dictionary and extracting effort for reasoning_effort, the internal ChatCompletionRequest is correctly populated.

$ python test_issue_25079.py
OpenAI request:
{'model': 'openai-response', 'messages': [{'role': 'user', 'content': 'Hello'}], 'reasoning_effort': 'high'}
SUCCESS: reasoning_effort mapped correctly.

Blast Radius Assessment

  1. Target Area: litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py within translate_anthropic_to_openai.
  2. Behavioral Impact: Safely extends translation mapping by an O(1) dictionary fetch. If output_config is absent, execution is unchanged.
  3. Performance Regressions: Negligible. The overhead is a single static method lookup and dict validation iteration within the request parser.

Epistemic Check

  • Confidence Level: 100%
  • Empirical Baseline: Script accurately replicates LiteLLM's LiteLLMAnthropicMessagesAdapter logic locally before and after the hotfix.
  • Blind Spots: I'm assuming that the provider-specific configurations further down the pipeline in litellm.completion natively support overriding or processing the standard reasoning_effort kwargs as translated from output_config without additional adapters. Given standard OpenAI mappings, reasoning_effort propagates to target providers fine.

@vercel

vercel Bot commented Apr 4, 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 Apr 4, 2026 1:10am

Request Review

@codspeed

codspeed Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing glaziermag:fix-output-config-reasoning-effort (9bb7fad) with main (127149c)

Open in CodSpeed

@glaziermag
glaziermag force-pushed the fix-output-config-reasoning-effort branch from 28bf694 to 779cc44 Compare April 4, 2026 00:36
@glaziermag
glaziermag force-pushed the fix-output-config-reasoning-effort branch from 779cc44 to 8a0ad3e Compare April 4, 2026 00:37
@glaziermag
glaziermag marked this pull request as ready for review April 4, 2026 00:54
@codecov

codecov Bot commented Apr 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.66667% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...perimental_pass_through/adapters/transformation.py 86.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Apr 4, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes the missing mapping of output_config.effort → reasoning_effort when Anthropic /v1/messages requests are routed to non-Anthropic providers through the pass-through adapter. The fix adds output_config to translatable_anthropic_params() (preventing it from being blindly forwarded as-is) and introduces a dedicated _translate_output_config_to_openai method that either forwards output_config for native Anthropic models or maps effort → reasoning_effort for OpenAI-compatible ones. A unit test covering both paths is included.

  • Core logic (transformation.py): New _translate_output_config_to_openai method correctly guards against missing/invalid output_config, respects the pre-existing _translate_thinking_to_openai result (won't overwrite reasoning_effort if already set), and is wired into translate_anthropic_to_openai before the catch-all _copy_untranslated_anthropic_params.
  • Test (test_anthropic_experimental_pass_through_adapters_transformation.py): Covers the two primary cases (OpenAI-mapped effort, Anthropic pass-through). The new test function is a standalone function rather than following the class-based pattern used throughout the rest of the file.
  • No real-network calls are introduced; no security-sensitive paths are touched.

Confidence Score: 4/5

Safe to merge after addressing the test structure inconsistency; core logic is correct and well-guarded.

The implementation correctly fixes the reported issue. Prior review threads already surfaced the two main logic concerns (falsy check and silent drop of non-effort fields), and the code was updated to use an explicit None check. The only remaining finding is a P2 style issue in the test file (standalone function vs class-based convention). No security, data, or correctness regressions introduced.

Test file — new test should follow the class-based pattern used throughout the rest of the file.

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Adds _translate_output_config_to_openai method and wires it into translate_anthropic_to_openai; output_config added to translatable_anthropic_params to prevent blind pass-through. Logic is correct for the defined cases.
tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py Adds two test cases for the new translation logic. New test is a standalone function rather than a class, inconsistent with the file's established class-based test structure; no real network calls are made.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["translate_anthropic_to_openai()"] --> B["_translate_thinking_to_openai()"]
    B --> C["_translate_output_format_to_openai()"]
    C --> D["_translate_output_config_to_openai() ← NEW"]
    D --> E{output_config present?}
    E -- No --> I["_copy_untranslated_anthropic_params()"]
    E -- Yes --> F{effort != None?}
    F -- No --> I
    F -- Yes --> G{is_anthropic_claude_model?}
    G -- Yes --> H1["new_kwargs['output_config'] = output_config"]
    G -- No --> H2{"reasoning_effort already set?"}
    H2 -- Yes --> I
    H2 -- No --> H3["new_kwargs['reasoning_effort'] = effort"]
    H1 --> I
    H3 --> I
    I --> J["return new_kwargs"]
Loading

Reviews (2): Last reviewed commit: "Address PR review comments from Greptile..." | Re-trigger Greptile

Comment on lines +1089 to +1091
effort = output_config.get("effort")
if not effort:
return

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.

P2 Falsy check skips 0-valued effort

if not effort: will silently return early for any falsy value (empty string "", 0, None). For string effort levels this is unlikely to matter in practice, but an explicit None check is more intentional and matches how the rest of this file guards optional fields.

Suggested change
effort = output_config.get("effort")
if not effort:
return
effort = output_config.get("effort")
if effort is None:
return

Comment on lines +1093 to +1095
model = new_kwargs.get("model", "")
if self.is_anthropic_claude_model(model):
new_kwargs["output_config"] = output_config # type: ignore

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.

P2 Silent drop of non-effort output_config fields for non-Anthropic models

For Anthropic models the whole output_config dict is forwarded (correct). But for non-Anthropic models, only effort is extracted and all other fields inside output_config (e.g. future Anthropic additions) are silently dropped. This is acceptable today since effort is the only defined field, but worth a comment so future maintainers know the intentional scope.

Suggested change
model = new_kwargs.get("model", "")
if self.is_anthropic_claude_model(model):
new_kwargs["output_config"] = output_config # type: ignore
if self.is_anthropic_claude_model(model):
# Forward the full output_config dict for native Anthropic handling
new_kwargs["output_config"] = output_config # type: ignore

@krrish-berri-2

Copy link
Copy Markdown
Contributor

Closed by #26111

This branch was successfully deployed

1 active deployment
Preview — 9bb7fad5 Deployed Apr 4, 2026 by vercel[bot]
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