litellm - ✅(Solved) Fix [Bug]: [Bedrock] internalServerException mid-stream error incorrectly mapped to BadRequestError (400) instead of internalServerException (500) [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#24608Fetched 2026-04-08 01:32:23
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
1
Author
Participants
Timeline (top)
cross-referenced ×3labeled ×3referenced ×2

Error Message

level : "ERROR", message : "litellm.proxy.proxy_server.async_data_generator(): Exception occured - litellm.BadRequestError: BedrockException - internalServerException {"message":"The system encountered an unexpected error during processing. Try your request again."}", stacktrace : "Traceback (most recent call last): File "/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py", line 1915, in anext async for chunk in self.completion_stream: ...<71 lines>... return processed_chunk File "/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py", line 1680, in aiter_bytes message = self._parse_message_from_event(event) File "/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py", line 1699, in _parse_message_from_event raise BedrockError( ...<6 lines>... ) litellm.llms.bedrock.common_utils.BedrockError: internalServerException {"message":"The system encountered an unexpected error during processing. Try your request again."}

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/usr/local/lib/python3.13/site-packages/litellm/proxy/proxy_server.py", line 5123, in async_data_generator async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook( ...<32 lines>... yield f"data: {str(e)}\n\n" File "/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py", line 2131, in async_post_call_streaming_iterator_hook async for chunk in current_response: yield chunk File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item [Previous line repeated 1 more time] File "/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py", line 270, in async_post_call_streaming_iterator_hook async for chunk in response: ...<7 lines>... yield chunk File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 459, in async_post_call_streaming_iterator_hook async for item in response: yield item [Previous line repeated 5 more times] File "/usr/local/lib/python3.13/site-packages/litellm/router.py", line 1563, in anext return await self._async_generator.anext() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.13/site-packages/litellm/router.py", line 1568, in stream_with_fallbacks async for item in model_response: yield item File "/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py", line 2135, in anext raise mapped_exception File "/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py", line 2099, in anext mapped_exception = exception_type( model=self.model, ...<3 lines>... extra_kwargs={}, ) File "/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2398, in exception_type raise e File "/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 1080, in exception_type raise BadRequestError( ...<4 lines>... ) litellm.exceptions.BadRequestError: litellm.BadRequestError: BedrockException - internalServerException {"message":"The system encountered an unexpected error during processing. Try your request again."}",

Root Cause

In exception_mapping_utils.py , the bedrock block checks specific error strings but internalServerException has no explicit match, so it falls to the status code check. but never hits status_code == 500 because botocore’s Eventstream Protocol always sends HTTP 400 for all mid-stream error events. Even server side errors. botocore/eventstream.py

Fix Action

Fixed

PR fix notes

PR #24617: fix: Bedrock internalServerException mapping, AuthError no-retry, xai drop_params, SSE error handling

Description (problem / solution / changelog)

Summary

Four independent but thematically related bug fixes for error handling and routing correctness.


Fix 1 — exception_mapping_utils.py: Bedrock internalServerExceptionInternalServerError (closes #24608)

botocore's eventstream sends HTTP 400 for all mid-stream errors, including server-side ones. So internalServerException was falling through to status_code == 400BadRequestError (non-retryable). The fix detects the error type by string before the status-code branch:

elif 'internalServerException' in error_str or 'InternalServerException' in error_str:
    raise litellm.InternalServerError(...)  # retryable, status 500

Fix 2 — router.py: AuthenticationError 'Missing API Key' raises immediately (closes #18395)

A missing API key is a configuration error — retrying is pointless. Previously LiteLLM retried num_retries times before surfacing the error, making users wait minutes.

if 'missing' in _auth_err_str and 'api key' in _auth_err_str:
    raise error  # immediately, no retry

Fix 3 — xai/transformation.py + model_prices*.json: drop_params=True for xai (closes #16204)

Two sub-fixes:

  • xai/grok-4-fast-reasoning had supports_reasoning=null → now true; grok-4-fast-non-reasoningfalse
  • map_openai_params() ignored drop_params=True for params absent from supported_openai_params. Now silently drops them, preventing 400 errors from the xai API.

Fix 4 — streaming_iterator.py: async_sse_wrapper catches mid-stream errors (closes #24609)

async_sse_wrapper had no try/except around the async loop. Raw Bedrock errors (internalServerException) propagated unhandled as raw strings to the proxy client. Now wrapped with try/except + exception_type() mapping.


Tests

18 new regression tests in tests/router_unit_tests/test_pr_litellm_round2_fixes.py:

  • TestBedrockInternalServerException (6) — string detection, casing variants, retryability
  • TestAuthErrorMissingKeyNotRetried (4) — single/multi-deployment, case-insensitive, transient auth ok
  • TestXaiDropParamsReasoningEffort (5) — drop_params, model cost map values
  • TestAsyncSseWrapperErrorHandling (3) — try/except exists, error caught, happy path

All 18 pass — 0 regressions. Fixes #24608, #18395, #16204, #24609.

Changed files

  • litellm/constants.py (modified, +9/-0)
  • litellm/litellm_core_utils/exception_mapping_utils.py (modified, +36/-0)
  • litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py (modified, +28/-4)
  • litellm/llms/xai/chat/transformation.py (modified, +5/-0)
  • litellm/model_prices_and_context_window_backup.json (modified, +37329/-37334)
  • litellm/router.py (modified, +11/-1)
  • litellm/router_utils/cooldown_handlers.py (modified, +12/-1)
  • model_prices_and_context_window.json (modified, +37329/-37334)
  • tests/router_unit_tests/test_pr_429_routing_fixes.py (added, +247/-0)
  • tests/router_unit_tests/test_pr_litellm_round2_fixes.py (added, +414/-0)

Code Example

model_list:
  - model_name: bedrock-claude
    litellm_params:
      model: bedrock/anthropic.claude-3-sonnet-20240229-v1:0

---

import litellm
response = litellm.completion(
    model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in response:
    pass

---

level
:
"ERROR",
message
:
"litellm.proxy.proxy_server.async_data_generator(): Exception occured - litellm.BadRequestError: BedrockException - internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}",
stacktrace
:
"Traceback (most recent call last):
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 1915, in __anext__
    async for chunk in self.completion_stream:
    ...<71 lines>...
        return processed_chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1680, in aiter_bytes
    message = self._parse_message_from_event(event)
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1699, in _parse_message_from_event
    raise BedrockError(
    ...<6 lines>...
    )
litellm.llms.bedrock.common_utils.BedrockError: internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/proxy_server.py\", line 5123, in async_data_generator
    async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook(
    ...<32 lines>...
            yield f\"data: {str(e)}\\n\\n\"
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 2131, in async_post_call_streaming_iterator_hook
    async for chunk in current_response:
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 1 more time]
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py\", line 270, in async_post_call_streaming_iterator_hook
    async for chunk in response:
    ...<7 lines>...
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 5 more times]
  File \"/usr/local/lib/python3.13/site-packages/litellm/router.py\", line 1563, in __anext__
    return await self._async_generator.__anext__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.13/site-packages/litellm/router.py\", line 1568, in stream_with_fallbacks
    async for item in model_response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 2135, in __anext__
    raise mapped_exception
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 2099, in __anext__
    mapped_exception = exception_type(
        model=self.model,
    ...<3 lines>...
        extra_kwargs={},
    )
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py\", line 2398, in exception_type
    raise e
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py\", line 1080, in exception_type
    raise BadRequestError(
    ...<4 lines>...
    )
litellm.exceptions.BadRequestError: litellm.BadRequestError: BedrockException - internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}",
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

In exception_mapping_utils.py , the bedrock block checks specific error strings but internalServerException has no explicit match, so it falls to the status code check. but never hits status_code == 500 because botocore’s Eventstream Protocol always sends HTTP 400 for all mid-stream error events. Even server side errors. botocore/eventstream.py

Expected: internalServerException (HTTP 500, retryable) Actual: litellm.BadRequestError (HTTP 400, non-retryable)

Steps to Reproduce

  1. Set up LiteLLM proxy with a Bedrock model (Claude 3+ via invoke endpoint), e.g.:
model_list:
  - model_name: bedrock-claude
    litellm_params:
      model: bedrock/anthropic.claude-3-sonnet-20240229-v1:0
  1. Send a streaming chat completion request that triggers an internalServerException mid-stream from AWS (e.g. by using an inference profile ARN under load, or waiting for AWS to return a server-side error during streaming):
import litellm
response = litellm.completion(
    model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0",
    messages=[{"role": "user", "content": "Hello"}],
    stream=True,
)
for chunk in response:
    pass
  1. When AWS returns internalServerException mid-stream, observe that LiteLLM raises litellm.BadRequestError instead of litellm.ServiceUnavailableError.

Expected: internalServerException (HTTP 500, retryable) Actual: litellm.BadRequestError (HTTP 400, non-retryable)

Relevant log output

level
:
"ERROR",
message
:
"litellm.proxy.proxy_server.async_data_generator(): Exception occured - litellm.BadRequestError: BedrockException - internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}",
stacktrace
:
"Traceback (most recent call last):
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 1915, in __anext__
    async for chunk in self.completion_stream:
    ...<71 lines>...
        return processed_chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1680, in aiter_bytes
    message = self._parse_message_from_event(event)
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1699, in _parse_message_from_event
    raise BedrockError(
    ...<6 lines>...
    )
litellm.llms.bedrock.common_utils.BedrockError: internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/proxy_server.py\", line 5123, in async_data_generator
    async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook(
    ...<32 lines>...
            yield f\"data: {str(e)}\\n\\n\"
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 2131, in async_post_call_streaming_iterator_hook
    async for chunk in current_response:
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 1 more time]
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py\", line 270, in async_post_call_streaming_iterator_hook
    async for chunk in response:
    ...<7 lines>...
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 459, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 5 more times]
  File \"/usr/local/lib/python3.13/site-packages/litellm/router.py\", line 1563, in __anext__
    return await self._async_generator.__anext__()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File \"/usr/local/lib/python3.13/site-packages/litellm/router.py\", line 1568, in stream_with_fallbacks
    async for item in model_response:
        yield item
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 2135, in __anext__
    raise mapped_exception
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/streaming_handler.py\", line 2099, in __anext__
    mapped_exception = exception_type(
        model=self.model,
    ...<3 lines>...
        extra_kwargs={},
    )
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py\", line 2398, in exception_type
    raise e
  File \"/usr/local/lib/python3.13/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py\", line 1080, in exception_type
    raise BadRequestError(
    ...<4 lines>...
    )
litellm.exceptions.BadRequestError: litellm.BadRequestError: BedrockException - internalServerException {\"message\":\"The system encountered an unexpected error during processing. Try your request again.\"}",

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.81.14-stable

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To fix the issue, we need to update the exception_mapping_utils.py file to correctly map the internalServerException to a retryable error.

Here are the steps:

  • Update the exception_type function in exception_mapping_utils.py to check for internalServerException in the error message, regardless of the status code.
  • Raise a ServiceUnavailableError instead of BadRequestError when internalServerException is encountered.

Example code:

def exception_type(e, model):
    # ... existing code ...
    if "internalServerException" in str(e):
        raise ServiceUnavailableError(model=model)
    # ... existing code ...

Additionally, consider updating the botocore version to the latest one, as the issue might be resolved in newer versions.

Verification

To verify the fix, repeat the steps to reproduce the issue and check that litellm.ServiceUnavailableError is raised instead of litellm.BadRequestError.

Extra Tips

  • Make sure to test the fix thoroughly to ensure it doesn't introduce any regressions.
  • Consider adding a retry mechanism for ServiceUnavailableError to handle temporary server-side errors.
  • Keep the botocore version up to date to ensure you have the latest fixes and features.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - ✅(Solved) Fix [Bug]: [Bedrock] internalServerException mid-stream error incorrectly mapped to BadRequestError (400) instead of internalServerException (500) [1 pull requests, 1 participants]