Skip to content

fix(anthropic): carry the adaptive effort tier to every bridged Claude target - #38533

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_messages_adaptive_effort
Aug 27, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_messages_adaptive_effort

Conversation

@tin-berri

@tin-berri tin-berri commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • /v1/messages dropped the effort tier for bridged Claude models
  • max and minimal produced byte-identical upstream bodies
  • Only Bedrock kept it, via a hardcoded model-name prefix check

How it solves it:

  • Send those targets the tier as reasoning_effort, the param they take
  • Bedrock keeps taking output_config, which the two are not interchangeable for
  • An ARN resolves to no chat config, so reasoning_effort would be dropped there

User Flow

Before: a developer pointing Claude Code at a Claude model served through openrouter gets the same answer no matter which effort they pick

  1. Their admin registers openrouter/anthropic/claude-opus-4.7 and confirms it serves traffic
  2. They send POST https://litellm-domain/v1/messages with "thinking": {"type": "adaptive"} and "output_config": {"effort": "max"}
  3. The call returns 200 and reads normally, so nothing looks wrong
  4. They send the same request with "effort": "minimal", expecting a faster and cheaper answer
  5. Both requests are the same depth and the same price, because the provider was never told which tier to use

After: the tier the developer picks is the tier the provider is told

  1. Their admin registers the same model
  2. They send the same POST with "effort": "max"
  3. The provider is told to run at its top tier
  4. They send the same request with "effort": "minimal" and the provider is told to run at its lowest
  5. The two requests now differ in depth and price, matching what was asked

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5

Screenshots / Proof of Fix

Shared setup, identical for both runs. A local proxy holding the same Claude model on three provider shapes, all pointed at a local stub that records the body it received:

model_list:
  - model_name: claude-openrouter
    litellm_params:
      model: openrouter/anthropic/claude-opus-4.7
      api_key: os.environ/RIG_FAKE_KEY
      api_base: http://127.0.0.1:4495/v1
  - model_name: claude-azureai
    litellm_params:
      model: azure_ai/claude-opus-4-7
      api_key: os.environ/RIG_FAKE_KEY
      api_base: http://127.0.0.1:4495
  - model_name: claude-native
    litellm_params:
      model: anthropic/claude-opus-4-7
      api_key: os.environ/RIG_FAKE_KEY
      api_base: http://127.0.0.1:4495

litellm_settings:
  drop_params: false
LITELLM_LOCAL_MODEL_COST_MAP=True litellm --config rig/config.yaml --port 4496

Substitution declared: no key on this account carries these deployments, so the upstream is a local stub. The question here is which body the gateway decided to send, and the stub records exactly that. Bedrock does get a live leg, Case 3 below: a real us.anthropic.claude-opus-4-8 deployment on Bedrock Converse in us-east-1, hit with real credentials, with the request body the proxy sent taken from --detailed_debug output. Its config:

  - model_name: bedrock-opus-4-8
    litellm_params:
      model: bedrock/converse/us.anthropic.claude-opus-4-8
      aws_access_key_id: os.environ/AWS_ACCESS_KEY_ID
      aws_secret_access_key: os.environ/AWS_SECRET_ACCESS_KEY
      aws_region_name: us-east-1

Before (cd63c7e)

Case 1: /v1/messages

  1. Ask each deployment for two different tiers:
for g in claude-openrouter claude-azureai claude-native; do
  for e in max minimal; do
    curl -s -X POST http://127.0.0.1:4496/v1/messages \
      -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
      -d "{\"model\":\"$g\",\"max_tokens\":64,\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}],\"thinking\":{\"type\":\"adaptive\"},\"output_config\":{\"effort\":\"$e\"}}"
  done
done
  1. What the stub received:
claude-openrouter  effort=max      http=200  {"model":"anthropic/claude-opus-4.7","max_tokens":64,"thinking":{"type":"adaptive"},"usage":{"include":true}}
claude-openrouter  effort=minimal  http=200  {"model":"anthropic/claude-opus-4.7","max_tokens":64,"thinking":{"type":"adaptive"},"usage":{"include":true}}
claude-azureai     effort=max      http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"max"}}
claude-azureai     effort=minimal  http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"minimal"}}
claude-native      effort=max      http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"max"}}
claude-native      effort=minimal  http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"minimal"}}
  1. The two openrouter bodies are byte-identical, and neither carries a tier
  2. azure_ai and anthropic are already correct: those providers have a native /v1/messages config, so they never reach the bridge this PR changes

Case 2: /v1/chat/completions, the same models

  1. The same two tiers as plain reasoning_effort:
curl -s -X POST http://127.0.0.1:4496/v1/chat/completions \
  -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
  -d '{"model":"claude-openrouter","messages":[{"role":"user","content":"hi"}],"reasoning_effort":"max"}'
  1. What the stub received:
claude-openrouter  effort=max      http=200  reasoning_effort='xhigh'
claude-openrouter  effort=minimal  http=200  reasoning_effort='minimal'
  1. This route already carries the tier for the same deployment, which is the disagreement

Case 3: /v1/messages against live Bedrock

  1. Two tiers against the real deployment:
for e in max low; do
  curl -s -X POST http://127.0.0.1:4101/v1/messages \
    -H "Authorization: Bearer $KEY" -H 'content-type: application/json' \
    -d "{\"model\":\"bedrock-opus-4-8\",\"max_tokens\":2048,\"messages\":[{\"role\":\"user\",\"content\":\"What is 27 * 43? Think it through.\"}],\"thinking\":{\"type\":\"adaptive\"},\"output_config\":{\"effort\":\"$e\"}}"
done
  1. What the proxy sent to https://bedrock-runtime.us-east-1.amazonaws.com/model/us.anthropic.claude-opus-4-8/converse:
effort=max  {"messages": [...], "inferenceConfig": {"maxTokens": 2048}, "additionalModelRequestFields": {"thinking": {"type": "adaptive"}, "output_config": {"effort": "max"}}, ...}
effort=low  {"messages": [...], "inferenceConfig": {"maxTokens": 2048}, "additionalModelRequestFields": {"thinking": {"type": "adaptive"}, "output_config": {"effort": "low"}}, ...}
  1. Both returned 200 with a thinking block followed by text, at 444 output tokens for max and 220 for low, so the tier already travels here: this is the carve-out the PR preserves

After (b6f0216)

Case 1: /v1/messages

  1. Same loop, same commands
  2. What the stub received:
claude-openrouter  effort=max      http=200  {"model":"anthropic/claude-opus-4.7","max_tokens":64,"reasoning_effort":"xhigh","thinking":{"type":"adaptive"},"usage":{"include":true}}
claude-openrouter  effort=minimal  http=200  {"model":"anthropic/claude-opus-4.7","max_tokens":64,"reasoning_effort":"low","thinking":{"type":"adaptive"},"usage":{"include":true}}
claude-azureai     effort=max      http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"max"}}
claude-azureai     effort=minimal  http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"minimal"}}
claude-native      effort=max      http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"max"}}
claude-native      effort=minimal  http=200  {"model":"claude-opus-4-7","thinking":{"type":"adaptive"},"output_config":{"effort":"minimal"}}
  1. The two openrouter bodies now differ, and each carries the tier the caller asked for. max arrives as xhigh and minimal as low because openrouter's own param mapping and the model's declared levels remap them, which is the same treatment /v1/chat/completions gives
  2. azure_ai and anthropic are byte-identical to the Before run, confirming the native path is untouched

Case 2: /v1/chat/completions, the same models

  1. Same commands
  2. What the stub received:
claude-openrouter  effort=max      http=200  reasoning_effort='xhigh'
claude-openrouter  effort=minimal  http=200  reasoning_effort='minimal'
  1. Byte-identical to Before. This route does not run the code this PR changes, and the two routes now agree that the tier travels

Case 3: /v1/messages against live Bedrock

  1. Same commands against the same deployment, plus an untiered adaptive request and a streaming one at "effort": "high"
  2. What the proxy sent to the same Converse URL:
effort=max   {..., "additionalModelRequestFields": {"thinking": {"type": "adaptive"}, "output_config": {"effort": "max"}}, ...}
effort=low   {..., "additionalModelRequestFields": {"thinking": {"type": "adaptive"}, "output_config": {"effort": "low"}}, ...}
no tier      {..., "additionalModelRequestFields": {"thinking": {"type": "adaptive"}}, ...}
  1. Byte-identical shape to Before, confirming the Bedrock arm survived the carve-out's removal. Live responses: max ran at 423 output tokens and low at 187, both with a thinking block, and untiered adaptive stayed bare at 178, leaving Bedrock's own default in charge
  2. The streaming run delivered a thinking content block then text over SSE and ended cleanly with message_stop at 178 output tokens
  3. A tier past this model's declared levels is refused before any Bedrock call: "effort": "minimal" came back 400 with Invalid reasoning_effort/output_config.effort value: 'minimal'. Must be one of: 'low', 'medium', 'high', 'xhigh', or 'max'.

Case 4: /v1/messages against live Vertex AI Claude, native path untouched

  1. The same max and low requests against a real vertex_ai/claude-sonnet-4-6 deployment in us-east5, on both this commit and the merge base
  2. All four runs sent the identical body to .../publishers/anthropic/models/claude-sonnet-4-6:rawPredict with 'thinking': {'type': 'adaptive'}, 'output_config': {'effort': ...} carried verbatim, because vertex has a native /v1/messages config and never enters the bridge

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • databricks trades a caller-set thinking.display for the tier
    • It rebuilds the thinking block while mapping reasoning_effort, replacing display
    • Its supported-params list omits output_config, so this bridge cannot send it the inert carrier
    • Pinned by a test rather than left silent, and the tier is the thing worth keeping
    • Bedrock avoids this entirely, taking output_config directly
  • A summary-bearing adaptive request needed a second fix
    • _apply_reasoning_summary_wrapping turns the tier into {"effort": ..., "summary": ...}
    • That path never ran for a Claude target before, since the old code returned first
    • databricks raises Invalid reasoning_effort on the dict, and bedrock drops output_config with it
    • The summary already travels inside the forwarded thinking, so the tier stays a plain string there
  • The bridged non-Bedrock arm has no live leg
    • Bedrock now has one, Case 3 above, run against a real Converse deployment
    • No working key on this account reaches an openrouter or databricks Claude deployment
    • That arm stays proven by the stub runs plus get_optional_params regression tests

Low

  • 28 map entries gain a tier they never had, across databricks and openrouter
    • Measured: 307 Claude-family entries, 229 on providers with a native /v1/messages config that never reach this code, 78 bridged
    • Of those 78, the ones whose provider accepts reasoning_effort are databricks (15) and openrouter (13)
    • The other 50 are unchanged, and vercel_ai_gateway already refuses thinking on this path today with drop_params off, so nothing regresses
  • tests/test_litellm/llms/bedrock/files/test_bedrock_files_transformation.py has 5 collection errors
    • Unrelated to this change, in Bedrock files embedding
    • Verified identical with this branch's production file reverted to the merge base, so it predates the branch

Final Attestation

  • The tests check the right things, including the edge cases

Note

Medium Risk
Changes request shaping for bridged Claude /v1/messages calls (reasoning depth/cost behavior), with a known databricks trade-off where thinking.display may be rewritten when the tier is mapped via reasoning_effort.

Overview
Fixes /v1/messages adaptive thinking so output_config.effort is not dropped for Claude models routed through non-Bedrock bridges (e.g. openrouter, databricks). Previously only Bedrock got output_config; other bridged targets forwarded thinking alone, so max and minimal could produce identical upstream bodies.

Bedrock (including inference-profile ARNs) is unchanged: thinking stays verbatim and effort still goes as output_config (minus format). Other bridged Claude targets now also set reasoning_effort from the declared adaptive tier (plain string—no summary dict, since thinking.summary is already forwarded). Budgeted enabled thinking is not coarsened into a tier; adaptive requests without an effort tier still omit both carriers.

Regression tests assert adapter output and, where relevant, get_optional_params wire shapes (ARN output_config, preserved thinking.display on Bedrock, databricks display trade-off documented).

Reviewed by Cursor Bugbot for commit b6f0216. Bugbot is set up for automated code reviews on this repo. Configure here.

Link to Devin session: https://app.devin.ai/sessions/6b3fde4eddf94860ae912165e0b7283b
Open in Devin Desktop: https://app.devin.ai/desktop/session/6b3fde4eddf94860ae912165e0b7283b?variant=devin

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Score: 4.5/5

No blocking issues found. The change is narrowly scoped and correctly preserves thinking while carrying adaptive output_config.effort through reasoning_effort, allowing each provider to apply its existing mapping. The Bedrock carve-out and model-prefix check are removed cleanly, and the tests cover all effort tiers, missing effort, budgeted thinking, Bedrock payload mapping, and the unchanged native path. The added assertions strengthen the existing tests rather than weakening them.

The only deduction is validation confidence: Bedrock is verified through get_optional_params rather than a live integration, and CI was still pending at review time.

@greptile-apps

greptile-apps Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR carries adaptive effort tiers through bridged Claude targets while preserving Bedrock’s output_config path.

  • Non-Bedrock bridged Claude targets receive the selected tier as a plain reasoning_effort.
  • Bedrock models and inference-profile ARNs continue receiving the tier through output_config.
  • Summary-bearing adaptive requests keep a string-valued tier, avoiding Databricks’s invalid-reasoning-effort error.
  • Regression tests cover bridged providers, Bedrock wire mappings, ARNs, untiered adaptive thinking, and budgeted thinking.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains; the previously reported Databricks rejection is fixed by retaining a plain string effort tier, and the added Bedrock wire-level and live Converse evidence closes the earlier validation gap.

Important Files Changed

Filename Overview
litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py Separates Bedrock and other bridged Claude effort carriers and correctly avoids summary-wrapping the string tier that previously broke Databricks.
tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py Adds focused regression coverage for provider wire shapes, all effort tiers, summary-bearing requests, Bedrock ARNs, and no-tier behavior.

Reviews (2): Last reviewed commit: "fix(anthropic): carry the adaptive effor..." | Re-trigger Greptile

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@tin-berri
tin-berri force-pushed the litellm_messages_adaptive_effort branch from 3f3ea7a to 3193e4f Compare August 27, 2026 16:22
@tin-berri

Copy link
Copy Markdown
Contributor Author

Confirmed and fixed in 3193e4f. Bedrock also dropped output_config with the wrapped dict, so the tier stays a plain string for Claude targets.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5.

The fix is well-scoped and the core translation is correct: adaptive output_config.effort is carried as reasoning_effort for Claude-family bridge targets, while thinking remains intact. This removes the Bedrock-specific model-prefix carve-out and lets each provider perform its own mapping.

The regression coverage is strong: all effort tiers, bare adaptive thinking, budget-based thinking, summary wrapping, the Bedrock payload path, and the non-Claude path are covered.

I’m stopping at 4 rather than 5 because Bedrock coverage is indirect (get_optional_params) rather than a live integration test, and the Databricks/OpenRouter wire-shape assertion only checks that a value is present rather than verifying the exact mapped value. CI is also still pending.

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 3193e4f. Configure here.

@tin-berri
tin-berri force-pushed the litellm_messages_adaptive_effort branch from 3193e4f to 673610a Compare August 27, 2026 16:41
@tin-berri

Copy link
Copy Markdown
Contributor Author

Tightened the wire assertions to the exact tier each provider sends, so a mapping that changed the value now fails instead of passing.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Score: 4/5.

This is a well-scoped and well-tested fix. The bridge now carries adaptive output_config.effort as reasoning_effort, allowing each provider to apply its existing mapping instead of dropping the tier or forwarding an unsupported raw output_config. The implementation also preserves provider defaults when no effort is specified, avoids coarsening budget-based thinking, and correctly handles summary-bearing requests for Claude and non-Claude targets.

The tests cover all effort tiers, no-tier and budgeted cases, summary-bearing requests, and the Bedrock/Databricks/OpenRouter mappings. I’m not giving 5/5 only because this changes a shared translation path across several bridged providers, while Bedrock is validated through get_optional_params rather than a live integration request. No blocking correctness issue is apparent from the diff.

@codspeed

codspeed Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_messages_adaptive_effort (b6f0216) with litellm_internal_staging (ca9007b)1

Open in CodSpeed

Footnotes

  1. No successful run was found on litellm_internal_staging (955b26a) during the generation of this report, so ca9007b was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

…e target

/v1/messages forwarded `thinking` verbatim for a Claude-family model and then returned,
carrying `output_config.effort` only when the model string started with a Bedrock prefix.
Every other bridged provider got a bare adaptive thinking block, so the caller's effort did
nothing: max and minimal produced byte-identical upstream bodies.

Send those targets the tier as `reasoning_effort`, which is the param they take. Bedrock keeps
taking `output_config`, since the two are not interchangeable there: an application inference
profile ARN resolves to no chat config, so `reasoning_effort` is dropped and the tier vanishes,
and a provider that rebuilds `output_config` from it overwrites a caller-set `thinking.display`
on the way. The tier stays a plain string, the summary already travelling inside the forwarded
`thinking` block. Adaptive with no tier, and budgeted thinking, both stay exactly as they were.
@tin-berri
tin-berri force-pushed the litellm_messages_adaptive_effort branch from 673610a to b6f0216 Compare August 27, 2026 18:36
@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5.

I found no blocking correctness issues. The change cleanly separates the two required paths: Bedrock keeps output_config.effort, while other bridged Claude targets carry the tier through reasoning_effort. It also avoids wrapping reasoning_effort into a summary-bearing dict for Claude targets, preserves adaptive requests without an explicit tier, and does not coarsen budget-based thinking. The added tests cover all effort levels, OpenRouter/Databricks provider mappings, Bedrock ARNs, caller-specified display settings, and the non-Claude regression path.

I’m not giving 5/5 because the Bedrock behavior is validated through get_optional_params rather than a live integration, and the PR notes existing unrelated Bedrock test collection failures. Within that limitation, the fix is well-scoped and the regression coverage is strong.

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit b6f0216. Configure here.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

@greptileai a live Bedrock leg now backs the proof section, Case 3, real Converse deployment. Can you re-score with that gap closed?

@tin-berri
tin-berri enabled auto-merge (squash) August 27, 2026 22:47
@tin-berri
tin-berri merged commit 44d8436 into litellm_internal_staging Aug 27, 2026
83 checks passed
@tin-berri
tin-berri deleted the litellm_messages_adaptive_effort branch August 27, 2026 22:48
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.

/v1/messages drops output_config.effort for Claude models served by openrouter or azure_ai

2 participants