Repository navigation
fix(adapter): normalize reasoning effort with graceful degradation - #26111
Conversation
…_info _get_model_info_helper constructs ModelInfoBase explicitly but never reads supports_xhigh/minimal/none_reasoning_effort from the cost map JSON. Add the three fields so get_model_info() returns them correctly. Also add supports_minimal_reasoning_effort to the ModelInfo TypedDict (xhigh and none were already declared, minimal was missing).
….6/4.7 Claude Opus 4.7 supports max reasoning effort (above xhigh). The field was present for Opus 4.6 but missing for all Opus 4.7 entries (base, dated, Bedrock, Vertex AI, Azure AI). All Claude 4.6/4.7 models (Opus 4.6, Sonnet 4.6, Opus 4.7) support minimal reasoning effort via adaptive thinking. Add the field to all provider variants.
…5079) Anthropic's adaptive thinking (thinking.type="adaptive") and output_config.effort were silently dropped when translating to OpenAI format, resulting in no reasoning_effort on the outgoing request. Adapter changes (format translation): - adapters/transformation.py: add "adaptive" branch to translate_anthropic_thinking_to_reasoning_effort(); pass through output_config.effort as-is in _translate_thinking_to_openai(); add "output_config" to translatable_anthropic_params - adapters/handler.py: extract output_config from extra_kwargs into request_data so it reaches the translation layer - responses_adapters/transformation.py: add "adaptive" branch and output_config param to translate_thinking_to_reasoning() Handler changes (model-aware normalization): - utils.py: add normalize_reasoning_effort_value() that uses get_model_info() to map "max" → "xhigh"/"high" and "minimal" → "minimal"/"low" based on model capabilities - adapters/handler.py: call normalization before responses routing - responses_adapters/handler.py: call normalization after translation Relates to BerriAI#25079
…rmalize logic Test coverage for: - get_model_info returning supports_minimal/max_reasoning_effort fields - JSON registry entries for claude 4.6/4.7 across all providers - normalize_reasoning_effort_value degradation chains and exception fallback - Adapter translation of adaptive thinking + output_config.effort
Greptile SummaryThis PR fixes silent dropping of Anthropic adaptive thinking ( Confidence Score: 5/5Safe to merge — all findings are P2 or lower; logic, tests, and registry additions are correct. No P0/P1 issues found. The normalization logic is correct, degradation chains are properly tested with mocks, adapter wiring handles both completions and responses paths, and capability flags follow the established model registry pattern. The previous thread concerns around custom_llm_provider forwarding in responses_adapters/handler.py have been addressed. No files require special attention.
|
| Filename | Overview |
|---|---|
| litellm/llms/anthropic/experimental_pass_through/utils.py | Adds normalize_reasoning_effort_value() with lazy get_model_info import and exception fallback; logic and degradation chains are correct. |
| litellm/llms/anthropic/experimental_pass_through/adapters/handler.py | Adds _normalize_reasoning_effort static method and output_config extraction from extra_kwargs; normalization correctly runs before _route_openai_thinking to avoid model-name mangling. |
| litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py | Adds adaptive thinking branch returning 'medium' default; output_config.effort override in _set_reasoning_effort is correctly applied after the early-return guard. |
| litellm/llms/anthropic/experimental_pass_through/responses_adapters/handler.py | Adds post-translation normalization for reasoning.effort in responses path; custom_llm_provider correctly extracted from extra_kwargs (previous thread concern addressed). |
| litellm/llms/anthropic/experimental_pass_through/responses_adapters/transformation.py | translate_thinking_to_reasoning refactored to handle adaptive/enabled/disabled types distinctly; output_config parameter added with correct fallback to 'medium' default. |
| litellm/types/utils.py | Adds supports_minimal_reasoning_effort and supports_max_reasoning_effort to ProviderSpecificModelInfo TypedDict with Optional[bool] as expected. |
| litellm/utils.py | _get_model_info_helper correctly reads both new fields from model registry JSON with None default. |
| model_prices_and_context_window.json | Capability flags added to Claude 4.6/4.7 entries across all provider variants (Bedrock, Vertex, Azure AI, OpenRouter); matches PR description's scope. |
| tests/test_litellm/llms/anthropic/experimental_pass_through/test_reasoning_effort_fields.py | 29 tests covering degradation chains, JSON registry correctness, and adapter translation; all use mocks or local file reads — no real network calls. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Anthropic /v1/messages request\n(thinking: adaptive or enabled,\noutput_config.effort)"] --> B{Adapter path}
B -->|completions| C["handler.py\nExtract output_config → request_data"]
B -->|responses| D["responses_adapters/handler.py\ntranslate_request()"]
C --> E["transformation.py\ntranslate_anthropic_thinking_to_reasoning_effort()"]
E -->|type == adaptive| F["reasoning_effort = 'medium'"]
E -->|type == enabled| G["reasoning_effort from budget_tokens\n≥10000→high, ≥5000→med, ≥2000→low, else→minimal"]
F --> H["_set_reasoning_effort()\noverride with output_config.effort if present"]
G --> H
H --> I["_normalize_reasoning_effort()\ncompletion_kwargs"]
I --> J["normalize_reasoning_effort_value()\nlookup model_info via get_model_info()"]
D --> K["translate_thinking_to_reasoning()\nadaptive→effort=medium or output_config.effort\nenabled→budget_tokens mapping"]
K --> L["normalize_reasoning_effort_value()\nlookup model_info via get_model_info()"]
J --> M{effort level}
L --> M
M -->|max| N["supports_max? → max\nsupports_xhigh? → xhigh\nelse → high"]
M -->|xhigh| O["supports_xhigh? → xhigh\nelse → high"]
M -->|minimal| P["supports_minimal? → minimal\nelse → low"]
M -->|high/medium/low| Q["pass through unchanged"]
N --> R["Final OpenAI/Responses API request\nwith normalized reasoning_effort"]
O --> R
P --> R
Q --> R
Reviews (3): Last reviewed commit: "fix: forward custom_llm_provider to norm..." | Re-trigger Greptile
| if model_info.get("supports_minimal_reasoning_effort"): | ||
| return "minimal" | ||
| return "low" | ||
| return "medium" |
There was a problem hiding this comment.
Unreachable
return "medium" — dead code
The early guard on line 29 guarantees that by the time execution reaches the if/elif chain, effort is one of "max", "xhigh", or "minimal". Each branch has an explicit return, so this final return "medium" can never be reached. It could mislead future maintainers into thinking there is a code path that falls through to it.
| return "medium" |
There was a problem hiding this comment.
Keeping it intentionally as a defensive fallback — if future changes add new effort levels or modify the early guard, this ensures a safe default instead of falling off the function. No runtime cost.
| ) | ||
|
|
||
| effort = reasoning["effort"] | ||
| normalized = normalize_reasoning_effort_value(effort, model=model) |
There was a problem hiding this comment.
custom_llm_provider not forwarded to normalize call
The parallel call in adapters/handler.py passes custom_llm_provider so that get_model_info can resolve Bedrock/Vertex model entries correctly. This call omits it, which means capability lookups for provider-prefixed model names (e.g. vertex_ai/claude-opus-4-7) may silently fall back to the bare-model entry — or miss it entirely — and produce wrong degradation.
| normalized = normalize_reasoning_effort_value(effort, model=model) | |
| normalized = normalize_reasoning_effort_value(effort, model=model, custom_llm_provider=responses_kwargs.get("custom_llm_provider")) |
There was a problem hiding this comment.
Good catch. Fixed.
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@greptileai request re-review |
…in responses adapter
7621690 to
70855c9
Compare
|
@Vigilans can you include a screenshot of this working? |
|
b42b86d
into
BerriAI:litellm_oss_staging_04_22_2026
LiteLLM v1.83.13-nightly 的内置 deepseek/ 适配器尚未登记 V4 新模型( deepseek-v4-flash / deepseek-v4-pro),直接用 deepseek/ 前缀可能报 unknown model。 改用 openai/ 前缀 + 显式 api_base: https://api.deepseek.com,走 DeepSeek 官方的 OpenAI 兼容端点,不依赖 LiteLLM 模型表更新,未来新模型立刻能用。 同时把 reasoning_effort / thinking 这些自定义参数统一放到 extra_body, 避免被 LiteLLM 的 OpenAI-effort 校验 "graceful degrade"(BerriAI#26111)。 README 排查清单新增两条对应症状。 Made-with: Cursor



Relevant issues
Pre-Submission checklist
tests/test_litellm/directorymake test-unit@greptileaiand received a Confidence Score of at least 4/5Type
🐛 Bug Fix
Changes
Problem
Anthropic's adaptive thinking (
thinking.type="adaptive") andoutput_config.effortare silently dropped when translating/v1/messagesrequests to OpenAI format — the outgoing request has noreasoning_effort, so the model doesn't use extended thinking.Additionally, clients that request effort levels like
maxorminimalget hard failures if the target model doesn't support that exact level, instead of degrading gracefully.Solution
1.
normalize_reasoning_effort_value()— graceful degradationA normalize function that maps unsupported effort levels to the closest supported one, using model capability fields from the registry:
max→max/xhigh/high(depending onsupports_max_reasoning_effort)xhigh→xhigh/high(depending onsupports_xhigh_reasoning_effort)minimal→minimal/low(depending onsupports_minimal_reasoning_effort)high,medium,lowpass through unchangedThis lets clients request
maxeffort without knowing model-specific constraints.2. Capability fields in model registry
supports_max_reasoning_effort: truefor all Opus 4.7 entriessupports_minimal_reasoning_effort: truefor all Claude 4.6/4.7 entries (Opus 4.6, Sonnet 4.6, Opus 4.7) across all provider variants (Bedrock, Vertex AI, Azure AI)supports_minimal_reasoning_effortadded toProviderSpecificModelInfoTypedDict +_get_model_info_helper3. Adapter path wiring
type: "adaptive") now maps toreasoning_effort: "medium"by defaultoutput_config.effortextracted and passed through asreasoning_effortFiles changed:
.../utils.pynormalize_reasoning_effort_value()+is_reasoning_auto_summary_enabled().../adapters/transformation.pyoutput_configpassthrough.../adapters/handler.pyoutput_config, call normalize before routing.../responses_adapters/transformation.pytranslate_thinking_to_reasoning().../responses_adapters/handler.pylitellm/types/utils.pysupports_minimal_reasoning_effortto TypedDictlitellm/utils.pysupports_minimal_reasoning_effortin_get_model_info_helpermodel_prices_and_context_window.jsonTest plan
29 tests:
Model registry fields:
get_model_inforeturnssupports_minimal_reasoning_effortandsupports_max_reasoning_effortsupports_max=True, all 4.6/4.7 havesupports_minimal=Truenormalize_reasoning_effort_value:max→xhigh→high,xhigh→high,minimal→lowhigh/medium/lowAdapter translation:
mediumdefaultoutput_config.effortoverrides reasoning_effort