Skip to content

fix(sagemaker,bedrock): answer 502 when a 200 AWS event stream decodes to no events or ends mid-frame - #53482

Merged
mateo-berri merged 6 commits into
BerriAI:mainfrom
linhqm:litellm_aws_event_stream_empty_200
Nov 22, 2026
Merged

mateo-berri merged 6 commits into
BerriAI:mainfrom
linhqm:litellm_aws_event_stream_empty_200

Conversation

@linhqm

@linhqm linhqm commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

When SageMaker or a Bedrock agent answers HTTP 200 but the stream holds no usable events, or its last event is cut short, the proxy now returns a 502 that names the AWS request instead of an empty reply that looks successful. Retries and fallbacks now kick in, as they have for Bedrock chat streams since #43213

Details

TLDR

Problem this solves:

  • SageMaker streams return an empty 200 when AWS sends no events
  • A cut last event is dropped, so partial text looks complete
  • Bedrock agents do the same, and also drop AWS throttling errors
  • Fallbacks never run, because the empty reply counts as a success

How it solves it:

  • No events, leftover bytes or a body that is not an event stream now raise a 502 naming the request
  • Mid-stream, complete chunks arrive first, then the 502 as a stream error
  • Agent exception events and error frames raise their AWS error, e.g. 429 on throttling

Bedrock chat streams got this fix in #43213. A paired PR brings it to lts/1.108.x

User Flow

Before: an app streaming from a sagemaker/, sagemaker_chat/ or bedrock/agent/ model through the proxy gets a blank reply marked finished when AWS answers 200 with no events

  1. The app sends POST https://litellm-domain/v1/chat/completions with "stream": true for that model
  2. AWS answers HTTP 200 with an empty, or cut short, event stream
  3. The proxy streams one chunk with finish_reason: "stop" and no text, then [DONE], as HTTP 200
  4. The fallback model never runs, so the user sees a blank answer

After: the same request fails fast with a 502 naming the AWS request, so the fallback answers instead

  1. The app sends POST https://litellm-domain/v1/chat/completions with "stream": true for that model
  2. AWS answers HTTP 200 with an empty, or cut short, event stream
  3. The proxy answers HTTP 502 BadGatewayError naming the content-type, x-amzn-requestid and bytes received
  4. The fallback model streams the real answer, and a cut stream ends in a 502 stream error

Pre-Submission checklist

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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

A local stand-in serves the broken AWS 200s, and live rows call real SageMaker and Bedrock

Every row ran at 8d98527, with 3115254 as the before leg

Setup

Both legs run the proxy with 2 workers from their own tree, the same config.yaml and the same live SageMaker endpoint (TGI 3.3.6, Qwen2.5-0.5B-Instruct, us-east-1). AWS will not send an empty or cut 200 on demand, so aws_upstream.py serves them on 127.0.0.1:20431 in real AWS event-stream framing. Agent cases are scripted, since AWS refuses new Bedrock agents for our account (Maintenance Mode). Live Bedrock rows use Claude Haiku 5.5

  1. python aws_upstream.py 20431
  2. With AWS credentials exported for the live models, python litellm/proxy/proxy_cli.py --config config.yaml --port <port> --num_workers 2
  3. zsh cases.sh <port> <case>..., zsh matrix.sh <port> and zsh rust-cases.sh <port> from the gist, each printing the command it runs and then its output
  4. With the same credentials, zsh direct.sh sends the matrix prompts straight to AWS
Case What it sends Before After
sm-tgi-empty sagemaker/ stream, empty body 200, empty, stop 502
sm-tgi-truncated sagemaker/, first event cut 200, empty, stop 502
sm-tgi-midstream sagemaker/, last event cut cut text, stop text, then 502 event
sm-chat-empty sagemaker_chat/ stream, empty body 200, empty, stop 502
sm-chat-midstream sagemaker_chat/, last event cut text, then 500 event text, then 502 event
agent-empty bedrock/agent/, empty body 200, empty text 502
agent-truncated agent, first event cut 200, empty text 502
agent-midstream agent, last event cut 200, cut text 502
agent-empty-stream agent stream, empty body 200, empty, stop 502
agent-throttled agent, throttling event 200, empty text 429
agent-error-frame agent, untyped error frame 200, cut text 503
sm-tgi-html sagemaker/ stream, HTML page 500, checksum 502
sm-chat-json sagemaker_chat/ stream, JSON body 500, checksum 502
agent-html agent, HTML page 500, checksum 502
agent-zeros agent, 16 zero bytes 500, checksum 502
bedrock-html bedrock/ stream, HTML page 500, checksum 502
agent-trace-ok agent, trace events 200, text 200, text
agent-trace-ok-stream agent stream, trace events 200, text 200, text
messages-sm-tgi-empty /v1/messages stream, empty body end_turn, no text 502 error event
messages-agent-midstream-drop /v1/messages, agent cut 200, cut text 502
responses-sm-chat-empty /v1/responses stream, empty body completed, no text failed, 502
fallback empty body, fallback set 200, empty fallback answers
messages-bedrock-html, -json, -zeros Bedrock Claude /v1/messages stream, body not an event stream 500, checksum 502
live-* 8 live SageMaker and Bedrock calls, each surface 200, text 200, text
matrix 48 live cells, 4 models x 3 routes x stream or not x 1 or 2 turns, plus direct AWS calls 200, text 200, text

Before (3115254)

sm-tgi-empty

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-13e9508e-39e4-4778-848c-e18aa9aa17ab","created":1795383390,"model":"sm-tgi-empty","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

sm-tgi-empty

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: SagemakerException - SageMaker answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-tgi-empty', 0 bytes received)\n\nLiteLLM: model group 'sm-tgi-empty' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502

Raw output for every case is in the gist

sm-tgi-truncated

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-truncated","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-27c7ac0b-4e2f-403d-b7c3-c51d7e9b7d36","created":1795383390,"model":"sm-tgi-truncated","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-truncated","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: SagemakerException - SageMaker answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-tgi-truncated', 132 bytes received)\n\nLiteLLM: model group 'sm-tgi-truncated' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
sm-tgi-midstream

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-midstream","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-66125349-4f32-4348-b5eb-b6d4336d26eb","created":1795383390,"model":"sm-tgi-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello","role":"assistant"}}]}

data: {"id":"chatcmpl-66125349-4f32-4348-b5eb-b6d4336d26eb","created":1795383390,"model":"sm-tgi-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"}}]}

data: {"id":"chatcmpl-66125349-4f32-4348-b5eb-b6d4336d26eb","created":1795383390,"model":"sm-tgi-midstream","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-midstream","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-198f34e6-03a6-4059-83d6-54d47435f33c","created":1795383400,"model":"sm-tgi-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello","role":"assistant"}}]}

data: {"id":"chatcmpl-198f34e6-03a6-4059-83d6-54d47435f33c","created":1795383400,"model":"sm-tgi-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"}}]}

data: {"error": {"message": "litellm.BadGatewayError: SagemakerException - SageMaker stream ended with 140 undecoded bytes after 2 events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-tgi-midstream', 421 bytes received)", "type": "internal_server_error", "param": null, "code": "502"}}

data: [DONE]


HTTP 200
sm-chat-empty

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-d3b4e851-ac08-486b-b9c4-f28bbab7e44c","created":1795383390,"model":"sm-chat-empty","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: Sagemaker_chatException - SageMaker answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-messages-empty', 0 bytes received)\n\nLiteLLM: model group 'sm-chat-empty' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
sm-chat-midstream

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-midstream","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-upstream","created":1795383390,"model":"sm-chat-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello","role":"assistant"}}]}

data: {"id":"chatcmpl-upstream","created":1795383390,"model":"sm-chat-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"}}]}

data: {"error": {"message": "litellm.APIConnectionError: Sagemaker_chatException - Stream ended before a finish_reason was received", "type": "internal_server_error", "param": null, "code": "500"}}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-midstream","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-upstream","created":1795383405,"model":"sm-chat-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello","role":"assistant"}}]}

data: {"id":"chatcmpl-upstream","created":1795383405,"model":"sm-chat-midstream","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":" world"}}]}

data: {"error": {"message": "litellm.BadGatewayError: Sagemaker_chatException - SageMaker stream ended with 321 undecoded bytes after 2 events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-messages-midstream', 964 bytes received)", "type": "internal_server_error", "param": null, "code": "502"}}

data: [DONE]


HTTP 200
agent-empty

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-empty","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-943c3dd6-4d50-47f1-91d3-092bc4204dd8","created":1795383390,"model":"agent-empty","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-empty","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-empty', 0 bytes received)\n\nLiteLLM: model group 'agent-empty' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-truncated

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-truncated","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-40c34e2f-0498-4cee-b2c0-64ac8b2c06b7","created":1795383391,"model":"agent-truncated","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-truncated","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-truncated', 104 bytes received)\n\nLiteLLM: model group 'agent-truncated' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-midstream

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-midstream","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-a8c04375-610f-4b5a-aab7-910c1672b432","created":1795383391,"model":"agent-midstream","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello world","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-midstream","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents stream ended with 116 undecoded bytes after 2 events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-midstream', 340 bytes received)\n\nLiteLLM: model group 'agent-midstream' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-empty-stream

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-dcf1b445-d883-40f2-909d-64b882720213","created":1795383391,"model":"agent-empty","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"","role":"assistant"}}]}

data: {"id":"chatcmpl-dcf1b445-d883-40f2-909d-64b882720213","created":1795383391,"model":"agent-empty","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-empty","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-empty', 0 bytes received)\n\nLiteLLM: model group 'agent-empty' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-throttled

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-throttled","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-f7a98a0e-09d1-4d99-a21f-6fbf48270690","created":1795383391,"model":"agent-throttled","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-throttled","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.RateLimitError: BedrockException: Rate Limit Error - throttlingException {\"message\":\"Rate exceeded\"}\n\nLiteLLM: model group 'agent-throttled' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"throttling_error","param":null,"code":"429"}}
HTTP 429
agent-error-frame

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-error-frame","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-05a44630-29cc-47ba-852c-b0afc677d3f9","created":1795383391,"model":"agent-error-frame","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":0,"total_tokens":0}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-error-frame","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.ServiceUnavailableError: BedrockException - InternalFailure agent runtime failed\n\nLiteLLM: model group 'agent-error-frame' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"503"}}
HTTP 503
sm-tgi-html

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-html","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.APIConnectionError: Checksum mismatch: expected 0x6f64793e, calculated 0x71429e58","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-html","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: SagemakerException - SageMaker answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='text/html', x-amzn-requestid='upstream-sm-tgi-html', 45 bytes received)\n\nLiteLLM: model group 'sm-tgi-html' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
sm-chat-json

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-json","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.APIConnectionError: Checksum mismatch: expected 0x65223a22, calculated 0xa98fe9c5","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-json","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: Sagemaker_chatException - SageMaker answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='application/json', x-amzn-requestid='upstream-sm-messages-json', 33 bytes received)\n\nLiteLLM: model group 'sm-chat-json' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-html

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-html","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.APIConnectionError: BedrockException - Error processing response: Checksum mismatch: expected 0x6f64793e, calculated 0x71429e58\n\nLiteLLM: model group 'agent-html' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-html","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='text/html', x-amzn-requestid='upstream-agent-html', 45 bytes received)\n\nLiteLLM: model group 'agent-html' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-zeros

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-zeros","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.APIConnectionError: BedrockException - Error processing response: Checksum mismatch: expected 0x00000000, calculated 0x6522df69\n\nLiteLLM: model group 'agent-zeros' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-zeros","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock Agents answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-zeros', 16 bytes received)\n\nLiteLLM: model group 'agent-zeros' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
bedrock-html

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"bedrock-html","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.APIConnectionError: Checksum mismatch: expected 0x6f64793e, calculated 0x71429e58","type":"internal_server_error","param":null,"code":"500"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"bedrock-html","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"error":{"message":"litellm.BadGatewayError: BedrockException - Bedrock answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='text/html', x-amzn-requestid='upstream-bedrock-html', 45 bytes received)\n\nLiteLLM: model group 'bedrock-html' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model.","type":"internal_server_error","param":null,"code":"502"}}
HTTP 502
agent-trace-ok

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-trace-ok","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-b48d5d10-d3f0-43d6-8763-c5f2bc7075b0","created":1795383391,"model":"agent-trace-ok","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello world","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":7,"total_tokens":7}}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-trace-ok","messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-9384acca-52bf-4ad3-bda0-75abdc3d27b1","created":1795383428,"model":"agent-trace-ok","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"Hello world","role":"assistant"}}],"usage":{"completion_tokens":0,"prompt_tokens":7,"total_tokens":7}}
HTTP 200
agent-trace-ok-stream

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-trace-ok","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-cc518e37-9630-41ca-a30a-66b53906581b","created":1795383391,"model":"agent-trace-ok","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello world","role":"assistant"}}]}

data: {"id":"chatcmpl-cc518e37-9630-41ca-a30a-66b53906581b","created":1795383391,"model":"agent-trace-ok","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-trace-ok","stream":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-33f379a8-069d-4f83-8af9-4a4679a99fdd","created":1795383428,"model":"agent-trace-ok","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"Hello world","role":"assistant"}}]}

data: {"id":"chatcmpl-33f379a8-069d-4f83-8af9-4a4679a99fdd","created":1795383428,"model":"agent-trace-ok","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200
messages-sm-tgi-empty

Before (3115254)

$ curl -sN localhost:24617/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
event: message_start
data: {"type":"message_start","message":{"id":"msg_b7299ca5-c0fd-4a88-81bc-2fb47121ba20","type":"message","role":"assistant","content":[],"model":"sm-tgi-empty","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":0,"output_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}}

event: content_block_start
data: {"type": "content_block_start", "index": 0, "content_block": {"type": "text", "text": ""}}

event: content_block_stop
data: {"type": "content_block_stop", "index": 0}

event: message_delta
data: {"type": "message_delta", "delta": {"stop_reason": "end_turn"}, "usage": {"input_tokens": 0, "output_tokens": 0}}

event: message_stop
data: {"type": "message_stop"}


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
event: message_start
data: {"type":"message_start","message":{"id":"msg_2ceebc07-3cc8-4b39-958d-2918d63314ee","type":"message","role":"assistant","content":[],"model":"sm-tgi-empty","stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":0,"output_tokens":0,"cache_creation_input_tokens":0,"cache_read_input_tokens":0}}}

event: error
data: {"type": "error", "error": {"type": "api_error", "message": "litellm.BadGatewayError: SagemakerException - SageMaker answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-tgi-empty', 0 bytes received)"}}


HTTP 200
messages-agent-midstream-drop

Before (3115254)

$ curl -sN localhost:24617/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-midstream","max_tokens":20,"drop_params":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"id":"chatcmpl-441bd364-4297-442f-b3a8-761ca49353ef","type":"message","role":"assistant","model":"agent-midstream","stop_sequence":null,"usage":{"input_tokens":0,"output_tokens":0},"content":[{"type":"text","text":"Hello world"}],"stop_reason":"end_turn","stop_details":null}
HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"agent-midstream","max_tokens":20,"drop_params":true,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"type":"error","error":{"type":"api_error","message":"litellm.BadGatewayError: BedrockException - Bedrock Agents stream ended with 116 undecoded bytes after 2 events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-agent-midstream', 340 bytes received)\n\nLiteLLM: model group 'agent-midstream' failed with the error above and no fallback model group was found for it, so the request was not retried on another model. Fallbacks are configured for: sm-tgi-empty-with-fallback. Add a fallbacks entry for that model group (Router fallbacks or proxy router_settings.fallbacks) to retry on another model."}}
HTTP 502
responses-sm-chat-empty

Before (3115254)

$ curl -sN localhost:24617/v1/responses -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-empty","stream":true,"input":"say hi"}' -w '\nHTTP %{http_code}\n'

The output is long, so it is in the gist under === responses-sm-chat-empty

After (8d98527)

$ curl -sN localhost:26093/v1/responses -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-chat-empty","stream":true,"input":"say hi"}' -w '\nHTTP %{http_code}\n'
event: response.failed
data: {"type":"response.failed","response":{"id":"resp_8e920c93f1cf42a98f72c08cc151ec96","created_at":1795383444,"error":{"code":"server_error","message":"litellm.BadGatewayError: Sagemaker_chatException - SageMaker answered the stream with HTTP 200 but its body decoded to no events (content-type='application/vnd.amazon.eventstream', x-amzn-requestid='upstream-sm-messages-empty', 0 bytes received)"},"object":"response","output":[],"status":"failed"},"sequence_number":0}


HTTP 200
fallback

Before (3115254)

$ curl -sN localhost:24617/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty-with-fallback","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"Say hi in three words."}]}' -w '\nHTTP %{http_code}\n'
data: {"id":"chatcmpl-3da74572-6082-48f2-8e10-a7a690e4ec55","created":1795383418,"model":"sm-tgi-empty-with-fallback","object":"chat.completion.chunk","choices":[{"finish_reason":"stop","index":0,"delta":{}}]}

data: [DONE]


HTTP 200

After (8d98527)

$ curl -sN localhost:26093/v1/chat/completions -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"sm-tgi-empty-with-fallback","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"Say hi in three words."}]}' -w '\nHTTP %{http_code}\n'

The output is long, so it is in the gist under === fallback

messages-bedrock-html

Before (3115254)

$ curl -sN localhost:24617/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"bedrock-html","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"type":"error","error":{"type":"api_error","message":"Checksum mismatch: expected 0x6f64793e, calculated 0x71429e58"}}
HTTP 500

After (8d98527)

$ curl -sN localhost:26093/v1/messages -H 'Authorization: Bearer sk-repro-1234' -H 'Content-Type: application/json' -d '{"model":"bedrock-html","stream":true,"max_tokens":20,"messages":[{"role":"user","content":"say hi"}]}' -w '\nHTTP %{http_code}\n'
{"type":"error","error":{"type":"api_error","message":"Bedrock answered the stream with HTTP 200 but its body stopped decoding as an AWS event stream after 0 events (ChecksumMismatch, content-type='text/html', x-amzn-requestid='upstream-bedrock-html', 45 bytes received)"}}
HTTP 502

The JSON and zero-byte rows are in the gist (before, after)

Surprises

  • /v1/messages to agents 400s on max_tokens without drop_params, unchanged
/live-pr-risk at 8d98527, no breaking change found

Base 3115254 and head 8d98527 each ran 2 workers with their own Postgres and Redis. Live cells called real Bedrock and SageMaker through a recorder that logs each AWS request and forwards it, and broken-200 cells used a local AWS stand-in. Every table, body and recorded request is in the risk report

Breaking

None found. The 12 live cells (Bedrock converse and invoke on /v1/chat/completions, /v1/messages and /v1/responses, SageMaker and SageMaker chat, stream and non-stream) match on status, body shape, header names, and the AWS requests sent

Backward incompatible

Each change below is the fix or follows from it, and the Decisions block settles it

A 200 with no usable event stream answers 502, or 429 for agent throttling, instead of an empty 200. Same as #43213 for Bedrock chat

The router retries that 502, so the client waits about 4.5 to 6 s and AWS gets 3 calls, where base made 1 call and answered in under 0.4 s. Base already retried a 500 the same way

A multi-deployment group cools the broken deployment down, so sm-pool requests 2 to 4 went to the healthy deployment on head and to the broken one on base. A single-deployment group with no fallback answered 502 three times in a row, with no lockout

Fallbacks now run, since the error no longer looks like a success

Spend logs write a failure row with error_code 502 or 429. Base wrote no row for an empty SageMaker stream and a 0-token success row for an empty agent turn. Prometheus failure labels move from ChecksumMismatch or none to SagemakerError and BedrockError with status 502

Regression risk

Non-Claude Bedrock invoke families share the decoder, and only Claude ran live over invoke, so their streams rest on the decoder's unit tests. With LITELLM_RUST_FIRST set, a Rust gateway serves Bedrock invoke streams through the Rust decoder this PR also changes. That path was traced and not run live

Dependency graph

Dependent Status
Bedrock converse streams verified live
Bedrock invoke, Claude verified live
Bedrock invoke, other families unit tested
SageMaker verified live
SageMaker chat verified live
Bedrock agent stand-in only
Router retry, cooldown, fallback verified, stand-in
Spend logs, Prometheus verified
Rust gateway traced

Not verified

A live Bedrock agent, since the QA AWS account has no agent and refuses CreateAgent. The Rust gateway path, as above

Merged with main b21e530 (c6dcb773a6), the tree merges clean and matches head on every cell. The lts/1.108.x twin #53483 (c50d78d vs 2b4abd7) shows the same changes on the same cells and nothing else. The integration groups that reach the changed modules passed at the tip, except 2 of 633 providers tests that hit timeouts on a loaded host and passed when run alone on both tip and base

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • No live Bedrock agent run backs the agent changes
    • AWS refuses new agents on the QA account, so every agent row uses scripted frames
    • A healthy-turn smoke against an existing agent would close this gap

Low

  • The Rust bridge keeps four Bedrock frame-error mappings that nothing reaches now
  • The unused SagemakerChatHandler still builds its decoder without response headers
  • Bedrock chat's unknown-event error still quotes 200 payload bytes, unchanged
Decisions

A broken 200 answers 502 BadGatewayError, the same as #43213 for Bedrock chat. The other options were a 500, which reads as a proxy bug, or keeping the empty 200, which is the bug. A 502 lets router retries and fallbacks run. Mid-stream, the client still gets every complete chunk first and then the 502 as a stream error, so text already sent is never thrown away

A stream counts as broken when no event decodes, bytes are left over after the last complete event, or the body stops decoding as an AWS event stream. Bedrock chat also treats a stream of only unknown event types as broken, unchanged from #43213. SageMaker and agents skip that check, since any decoded event there carries real data or an AWS exception

These errors name the content-type, x-amzn-requestid and bytes received, with no sample of the body. A cut frame can hold model text, and error text is not covered by message redaction, so a sample could copy a reply into logs and alerts. This drops the 200-byte sample Bedrock chat's no-events error has carried since #43213. The other option was keeping that sample to tell an HTML error page from a broken frame, and the content-type now does that. Bedrock chat's error for a stream of only unknown event types keeps its payload sample, unchanged from #43213, because it shows an AWS rejection message litellm does not model yet. The AWS request id also goes back as a response header, which is enough to find the call in AWS

A 200 body that is not an AWS event stream at all, such as an HTML or JSON page from something in front of AWS, used to fail with a 500 Checksum mismatch that named neither the request nor the content-type. It now answers the same 502 after any complete events and names the decoder's error class. The decoder's own message is left out, since it quotes 4 bytes of the body

Bedrock agent exception events used to be dropped, which turned a throttled call into an empty 200. They now raise with the AWS status, so a throttlingException answers 429. Without this, a stream holding only an exception event would still pass the new check

An agent error frame that names no exception type used to be dropped too, so the turn ended early with 200 and cut text. It now answers 500 with its :error-code and :error-message as the text, which maps to a 503 the router retries, and a code like ThrottlingException maps to 429 through the existing message match. AWS sends client errors as typed exceptions, so an untyped frame is treated as a server fault. The other option was a 400 from the frame's missing status, which the router never retries. Bedrock chat keeps its body-only text for these frames, unchanged from main

The router retries these 502, 503 and 429 errors like any other, so a failed agent turn runs again, up to num_retries times, and its action groups can run again too. Main already does this when an agent call fails with HTTP 500 or 429 (3 calls on both legs), so agents keep one retry rule for both. The other options were no retries for bedrock/agent/, a status the router never retries, or the AWS SDK's rule of no retry once a stream started. Each makes a mid-stream failure harder to recover from than the same failure at the HTTP level, and OpenAI SDK clients retry 5xx and 429 on their own anyway. A deployment that must never repeat a turn sets DefaultRetries: 0 for that model group

These 502s also count toward allowed_fails and cool the deployment down, like any provider 502. That now covers an empty SageMaker or agent 200, which used to count as a success, and an HTML or JSON 200, which failed as APIConnectionError (a raw ChecksumMismatch on Rust /v1/messages) and skipped cooldown. A deployment that answers 200 with no usable event stream fails every request, so routing around it is the point, and Bedrock chat's empty-body 502 from #43213 already cools down. The other option was an error the cooldown skips, which keeps sending traffic to the broken deployment. A model group that should tolerate more of these before cooling down raises BadGatewayErrorAllowedFails in allowed_fails_policy

All three readers share one counter, moved out of the Bedrock chat handler, so they judge a stream the same way

## 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
Bugbot summary

[!NOTE]
Medium Risk
Changes streaming and non-stream error handling for major AWS provider paths (Bedrock, SageMaker, agents), which affects retries, fallbacks, and client-visible status codes; behavior is heavily tested but alters production failure modes.

Overview
Introduces shared EventStreamTally in litellm_core_utils/aws_event_stream.py and wires Bedrock chat streams, Bedrock Agents, and SageMaker through it so broken HTTP 200 bodies no longer look like successful empty replies.

Undecodable streams (zero events, leftover bytes after the last frame, or bodies that stop parsing as an event stream—e.g. HTML/JSON) now raise 502 messages that cite content-type, x-amzn-requestid, and bytes received, without echoing raw body samples. Decoders take response_headers end-to-end so request IDs return on the error.

Bedrock Agents additionally surface exception and error events as proper provider errors (e.g. throttling → 429) instead of silent empty turns. The Rust Bedrock stream decoder is updated to match the Python 502 / parser-error behavior.

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

…s to no events or ends mid-frame

SageMaker streaming (sagemaker and sagemaker_chat) and Bedrock invoke-agent turned an HTTP 200 whose
event-stream body decoded to no events, or ended with bytes that never formed a whole frame, into an
empty successful turn. They now raise a 502 naming the content type, the x-amzn-requestid, and the byte
count, through the same tally the Bedrock converse and invoke decoders use, so router retries and
fallbacks apply.

Invoke-agent exception frames now raise with the status the bedrock-agent-runtime model gives them
instead of being dropped, and error frames keep their error code and message.
@veria-ai

veria-ai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with the previous test-convention issue fixed and no new blocking findings.

Summary

The PR makes empty, cut-short, and malformed AWS event streams return errors instead of successful empty replies. Bedrock agent exception events now retain their AWS error status.

  • SageMaker and Bedrock streams report broken AWS event frames as errors.
  • Bedrock agent streams turn AWS exception events into request errors.

Reviews (5) · Last reviewed commit: "test(bedrock): table the Rust invoke str..." · Reviewed by Greptile

…t error frames

The no-events 502 now names the content-type, request id and byte count only, since a cut frame can hold model text that skips message redaction. Untyped error frames on Bedrock agents answer 500 so the router retries them, and Bedrock chat keeps its body-only error text for those frames, as on main
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…oding

The Rust Messages route now ends a 200 Bedrock stream whose body is not an AWS event stream, or turns corrupt after some events, with the same 502 Python's decoder gives, naming the botocore parser error class instead of a bare checksum mismatch.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@codecov

codecov Bot commented Nov 22, 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

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@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 8d98527. Configure here.

@mateo-berri mateo-berri 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.

LGTM

@mateo-berri
mateo-berri merged commit 42eeda8 into BerriAI:main Nov 22, 2026
72 checks passed
narmstrong-berri added a commit that referenced this pull request Nov 24, 2026
…our (#54223)

Main's rust-wheel job fails 10 tests in tests/test_litellm_rust/messages,
each pinned to behaviour a later PR changed on purpose. The stub check
failed first until #53922, so the pytest step never reported them.

Credential failures on Bedrock invoke and Mantle now answer a 401
AuthenticationError with the botocore error as its context (#53362). A
200 Bedrock stream whose body is JSON answers BedrockError 502 (#53482).
A cut Bedrock stream drops the message_start output placeholder and
re-counts the streamed text (#53394). Logging copies the resolved
provider into litellm_params before callbacks run (#52709)
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