Skip to content

refactor(bedrock): remove the dead BedrockLLM invoke code path - #35188

Merged
mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_remove_dead_bedrock_invoke_path
Jul 30, 2026
Merged

mateo-berri merged 2 commits into
litellm_internal_stagingfrom
litellm_remove_dead_bedrock_invoke_path

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

  • Deletes the BedrockLLM class from invoke_handler.py
  • Live helpers (make_call, make_sync_call, stream decoders, AmazonCohereChatConfig) stay
  • Remaining references now use BaseAWSLLM directly
  • Ports the openai-route response and error tests onto the live config

Relevant issues

Follow-up to the RCA on stream_chunk_size leaking into invoke request bodies: PR #8290 moved Bedrock Invoke onto AmazonInvokeConfig (base_invoke_transformation.py) but left the old BedrockLLM completion path behind, PR #17357 then popped stream_chunk_size only on that dead path, and PR #30240 fixed the live path. This removes the dead path itself

Linear ticket

Pre-Submission checklist

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

  • I have added meaningful tests (the openai-route response-parsing and error tests are ported onto the live AmazonBedrockOpenAIConfig, and the live-path regression tests from fix(bedrock): stop stream_chunk_size leaking into invoke request bodies #30240 are kept)
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • 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 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Live proxy booted from this branch at a71d8d8 with real Bedrock calls (us.anthropic.claude-sonnet-5, us-east-1), config has one invoke-route and one converse-route deployment:

python litellm/proxy/proxy_cli.py --config qa_config.yaml --port 28471

Invoke route, non-streaming:

curl -s http://localhost:28471/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model": "sonnet5-invoke", "messages": [{"role": "user", "content": "Say INVOKE-OK and nothing else"}], "max_tokens": 20}'

{"id":"chatcmpl-489bb13e-fd05-4482-a6a9-017e2a82763e","created":1785383977,"model":"sonnet5-invoke","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"INVOKE-OK","role":"assistant",...

Invoke route, streaming with stream_chunk_size in the request body (the exact trigger from the original regression; a leak into the invoke body would 400):

curl -s http://localhost:28471/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model": "sonnet5-invoke", "messages": [{"role": "user", "content": "Say INVOKE-STREAM-OK and nothing else"}], "max_tokens": 20, "stream": true, "stream_chunk_size": 4096}'

data: {"id":"chatcmpl-f3c57a91-720b-4208-bea3-03d6a6a212cd","object":"chat.completion.chunk","created":1785383979,"model":"sonnet5-invoke","choices":[{"index":0,"delta":{"role":"assistant","content":"IN"}}]}
data: {"id":"chatcmpl-f3c57a91-720b-4208-bea3-03d6a6a212cd","object":"chat.completion.chunk","created":1785383979,"model":"sonnet5-invoke","choices":[{"index":0,"delta":{"content":"VOKE-STREA"}}]}
data: {"id":"chatcmpl-f3c57a91-720b-4208-bea3-03d6a6a212cd","object":"chat.completion.chunk","created":1785383979,"model":"sonnet5-invoke","choices":[{"index":0,"delta":{"content":"M-OK"}}]}

Converse route, streaming with stream_chunk_size and non-streaming:

curl -s http://localhost:28471/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model": "sonnet5-converse", "messages": [{"role": "user", "content": "Say CONVERSE-OK and nothing else"}], "max_tokens": 20, "stream": true, "stream_chunk_size": 4096}'

data: {"id":"chatcmpl-095bb2bb-ac7d-483b-8aec-80b1fe929b3c","created":1785383986,"model":"sonnet5-converse","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"CONVERSE-O","role":"assistant"}}],"provider_specific_fields":{}}
data: {"id":"chatcmpl-095bb2bb-ac7d-483b-8aec-80b1fe929b3c","created":1785383986,"model":"sonnet5-converse","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"K"}}],"provider_specific_fields":{}}

curl -s http://localhost:28471/v1/chat/completions -H "Authorization: Bearer sk-1234" -H "Content-Type: application/json" \
  -d '{"model": "sonnet5-converse", "messages": [{"role": "user", "content": "Say CONVERSE-OK and nothing else"}], "max_tokens": 20}'

{"id":"chatcmpl-598dc34c-6729-44c6-b681-d977fddbc70e","created":1785383988,"model":"sonnet5-converse","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"CONVERSE-OK","role":"assistant"}}],...

pytest tests/test_litellm/llms/bedrock/ passes at this head (1107 passed, 1 skipped), as do the two ported openai-route tests in tests/llm_translation/test_bedrock_completion.py

Type

🧹 Refactoring

Changes

litellm.completion has routed every Bedrock invoke request through AmazonInvokeConfig + base_llm_http_handler since PR #8290; BedrockLLM.completion and everything under it (process_response, convert_messages_to_prompt, async_completion, async_streaming, _async_anthropic_messages_completion) had no callers left. This deletes the class (951 lines) and its now-unused imports from invoke_handler.py, and drops the stale "TODO: DELETE FILE" module docstring since the file still hosts the live make_call/make_sync_call helpers, the AWS event-stream decoders, MockResponseIterator, and AmazonCohereChatConfig

The only live use of the class was common_utils.get_bedrock_chat_config calling the get_bedrock_invoke_provider staticmethod that BedrockLLM inherited from BaseAWSLLM; that call site now uses BaseAWSLLM directly, which is the identical code path as before. litellm/main.py and litellm/llms/bedrock/chat/__init__.py stop importing the class

Tests that exercised only the dead path are removed with it: the legacy-path re-chunk test in tests/test_litellm/llms/bedrock/chat/test_invoke_handler.py (the live-path make_call/make_sync_call chunk-size regression tests from PR #30240 remain), the shallow TestBedrockLLMSSLVerify duplicate of TestBaseAWSLLMSSLVerify, and the tests/llm_translation prompt-conversion test, since the live openai route passes messages through with no prompt conversion. The other two openai-route tests are ported onto the live config instead: test_bedrock_openai_response_parsing now goes through AmazonBedrockOpenAIConfig.transform_response and test_bedrock_openai_error_handling now covers the previously untested get_error_class BedrockError override. Two credential fixtures that only used BedrockLLM as a vessel for BaseAWSLLM.get_credentials now instantiate BaseAWSLLM

Deleting the untyped legacy code lowered the lint and type-check violation counts, so ruff-strict-budget.json, type-discipline-budget.json, and basedpyright-code-budget.json are ratcheted down accordingly (440 violations total)

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

@greptile-apps

greptile-apps Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

Removes the obsolete BedrockLLM invoke implementation while retaining the live streaming helpers and decoders

  • Replaces the remaining inherited provider-detection call with BaseAWSLLM
  • Removes stale BedrockLLM imports and tests
  • Ports OpenAI response and error coverage to AmazonBedrockOpenAIConfig
  • Ratchets static-analysis budgets to reflect the deleted legacy code

Confidence Score: 5/5

The PR appears safe to merge

No blocking failure remains

Important Files Changed

Filename Overview
litellm/llms/bedrock/chat/invoke_handler.py Deletes the unused BedrockLLM class and its imports while preserving live Bedrock streaming helpers, decoders, and configuration
litellm/llms/bedrock/common_utils.py Uses BaseAWSLLM directly for the inherited Bedrock invoke-provider lookup
litellm/main.py Removes the obsolete BedrockLLM import from the provider dispatch entrypoint
tests/llm_translation/test_bedrock_completion.py Moves OpenAI-on-Bedrock response and error tests onto the live transformation config and removes dead-path coverage

Reviews (2): Last reviewed commit: "test(bedrock): port the openai-route inv..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri
mateo-berri merged commit 4d54324 into litellm_internal_staging Jul 30, 2026
76 checks passed
@mateo-berri
mateo-berri deleted the litellm_remove_dead_bedrock_invoke_path branch July 30, 2026 04:21
@codspeed

codspeed Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_remove_dead_bedrock_invoke_path (a71d8d8) with litellm_internal_staging (47f1fb3)

Open in CodSpeed

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