Skip to content

fix(bedrock): resolve adaptive-thinking capability via base_model for opaque model ids - #40109

Closed
kalavt wants to merge 4 commits into
BerriAI:mainfrom
kalavt:fix-bedrock-appprofile-adaptive-thinking
Closed

kalavt wants to merge 4 commits into
BerriAI:mainfrom
kalavt:fix-bedrock-appprofile-adaptive-thinking

Conversation

@kalavt

@kalavt kalavt commented Sep 7, 2026

Copy link
Copy Markdown

What

AnthropicModelInfo's adaptive-thinking / always-on-thinking / legacy-thinking capability lookups (_is_adaptive_thinking_model, _is_always_on_thinking_model, _supports_legacy_thinking) resolve entirely from the model string — an explicit cost-map entry, or the fallback_generalizations version-regex rule. A Bedrock application inference profile ARN (arn:aws:bedrock:<region>:<account>:application-inference-profile/<id>) carries no claude substring and no version number, so every one of those lookups resolves to None/False for it.

Consequence: an adaptive-thinking request against a profile-ARN deployment is silently downgraded to legacy thinking.type=enabled, which Claude 5-family models reject with 400 thinking.type.enabled is not supported.

Fix

litellm_params.base_model is the existing opaque-model-string fallback (Azure deployments already use it for model-type detection — see ProviderConfigManager.get_provider_chat_config's base_model param). This PR threads that same fallback through the Anthropic capability-resolution chain:

  • AnthropicModelInfo._supports_model_capability (and its callers _is_adaptive_thinking_model, _is_always_on_thinking_model, _supports_legacy_thinking, maybe_drop_disabled_thinking, translate_legacy_thinking_for_adaptive_model, _legacy_budget_to_effort) now accept an optional base_model: str | None = None kwarg, retried when the direct lookups on model are inconclusive.
  • AmazonConverseConfig.map_openai_params and its Bedrock-side helpers (_handle_reasoning_effort_parameter, _process_tools_and_beta, _transform_request_helper) thread base_model from litellm_params.base_model through to those calls.
  • get_optional_params (litellm/utils.py) passes its existing base_model param into AmazonConverseConfig().map_openai_params(...) for the bedrock/converse route.

So a chart/config entry like:

litellm_params:
  model: bedrock/arn:aws:bedrock:ap-northeast-1:<account>:application-inference-profile/<id>
model_info:
  base_model: claude-sonnet-5

now resolves adaptive-thinking correctly, instead of every profile-ARN deployment silently downgrading.

Compatibility

Every new parameter is an optional kwarg defaulting to None. All existing call sites (which pass 2-3 positional/keyword args) are unaffected — verified by grepping every call site of the touched functions across the codebase.

Testing

Added test_is_adaptive_thinking_model_falls_back_to_base_model_for_opaque_ids in tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py, alongside the existing test_is_adaptive_thinking_model_is_sourced_from_cost_map parametrized test it complements.

… opaque model ids

AnthropicModelInfo's adaptive-thinking / always-on-thinking / legacy-thinking
capability lookups resolve entirely from the model string (an explicit
cost-map entry, or the fallback_generalizations version-regex rule). A Bedrock
application inference profile ARN
(arn:aws:bedrock:...:application-inference-profile/<id>) carries no "claude"
substring and no version number, so every such lookup returns None/False for
it — an adaptive-thinking request against a profile-ARN deployment is silently
downgraded to legacy thinking.type=enabled, which Claude 5-family models
reject with 400 "thinking.type.enabled is not supported".

litellm_params.base_model is the existing opaque-id fallback (Azure
deployments already use it for model-type detection); this threads it through
the same capability-resolution chain so a chart/config pin (model_info.base_model:
claude-sonnet-5, or litellm_params.base_model) resolves the correct
adaptive-thinking behavior for an ARN the direct lookups can't parse.

All new parameters are optional kwargs defaulting to None, so every existing
call site (bare 2-3 positional args) is unaffected.
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds base-model fallback capability resolution for opaque Bedrock inference-profile identifiers and propagates it through Converse thinking transformations

  • Retries Anthropic thinking capability lookups against the configured base model
  • Threads base_model through Converse parameter mapping and request transformation
  • Adds direct helper coverage for adaptive-thinking lookup
  • Still needs behavior-level regression coverage for the production propagation path

Confidence Score: 4/5

The capability changes appear correct, but repository requirements must be satisfied by removing the unnecessary comment and adding production-path regression coverage

No behavioral failure remains established, but the added test does not protect the new Converse propagation wiring and a changed source comment violates CLAUDE.md

Files Needing Attention: litellm/llms/bedrock/chat/converse_transformation.py; tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py

Important Files Changed

Filename Overview
litellm/llms/anthropic/common_utils.py Adds optional base-model fallback across Anthropic adaptive, always-on, legacy, and effort capability helpers
litellm/llms/bedrock/chat/converse_transformation.py Propagates the configured base model through Converse thinking transformations, with one source-comment policy violation
litellm/utils.py Forwards the existing base_model value into Bedrock Converse parameter mapping
tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py Tests helper fallback behavior but does not exercise the production opaque-ARN request-transformation path

Reviews (1): Last reviewed commit: "fix(bedrock): resolve adaptive-thinking ..." | Re-trigger Greptile

Comment on lines +1613 to +1618
# Application inference profile ARNs (litellm_params.model) carry no
# version substring, so the adaptive-thinking capability lookup below
# resolves nothing for them. litellm_params.base_model is the same
# opaque-id fallback Azure deployments use for model-type detection —
# thread it through so a chart/config pin (e.g. base_model:
# claude-sonnet-5) still gets the right adaptive-thinking behavior.

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 Unnecessary source comment

This six-line explanation covers straightforward plumbing and violates CLAUDE.md's source-comment policy, so remove it before merging

Suggested change
# Application inference profile ARNs (litellm_params.model) carry no
# version substring, so the adaptive-thinking capability lookup below
# resolves nothing for them. litellm_params.base_model is the same
# opaque-id fallback Azure deployments use for model-type detection —
# thread it through so a chart/config pin (e.g. base_model:
# claude-sonnet-5) still gets the right adaptive-thinking behavior.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Comment on lines +2903 to +2907
assert (
AnthropicConfig._is_adaptive_thinking_model(opaque_model, "bedrock", base_model="claude-sonnet-5")
is True
)
assert (

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 Missing end-to-end regression coverage

This helper-only test still passes if Converse base_model propagation breaks, violating CLAUDE.md's regression-test requirement; production-path coverage is required before merging

Context Used: CLAUDE.md (source)

@codspeed

codspeed Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing kalavt:fix-bedrock-appprofile-adaptive-thinking (6245e14) with litellm_internal_staging (02522a5)1

Open in CodSpeed

Footnotes

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

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

CI's lint job checks litellm/**/*.py against the changed-files diff with the
pinned ruff==0.15.3 formatter; one line in the previous commit exceeded the
wrap threshold under that version.
@kalavt
kalavt changed the base branch from main to litellm_internal_staging September 7, 2026 11:14
@kalavt
kalavt requested a review from a team September 7, 2026 11:14
@CLAassistant

CLAassistant commented Sep 7, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

… with BaseConfig

CI's basedpyright budget gate flagged reportIncompatibleMethodOverride: adding
base_model as a map_openai_params parameter changed its signature away from
BaseConfig's abstract declaration, which the repo's strict type-checking
budget (ratchet-only, never raised) does not allow.

Thread base_model via a declared instance attribute (configured_base_model,
set by get_optional_params before the call) instead of a method parameter, so
the override signature is unchanged. Every other touched method
(_handle_reasoning_effort_parameter, _process_tools_and_beta,
_transform_request_helper) is AmazonConverseConfig's own private helper, never
declared on BaseConfig, so their added base_model parameters were never an
override-compatibility issue.
@kalavt

kalavt commented Sep 7, 2026

Copy link
Copy Markdown
Author

@mateo-berri CI is green and CLA is signed — would appreciate a review when you have a moment. Happy to address any feedback.

@yuneng-berri
yuneng-berri deleted the branch BerriAI:main September 13, 2026 04:50
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:40
@ryan-crabbe-berri

Copy link
Copy Markdown
Contributor

Thanks for digging into this. Closing in favor of #46569, which also covers request building and warns when base_model is missing

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.

4 participants