litellm - ✅(Solved) Fix [Bug]: No Error Handling in /v1/messages Path [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#24609Fetched 2026-04-08 01:32:21
View on GitHub
Comments
0
Participants
1
Timeline
5
Reactions
1
Author
Participants
Timeline (top)
labeled ×3cross-referenced ×1referenced ×1

Error Message

level : "ERROR", message : "litellm.proxy.proxy_server.async_data_generator(): Exception occured - 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/proxy/common_request_processing.py", line 1375, in async_streaming_data_generator async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook( ...<33 lines>... yield serialize_chunk(chunk) File "/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py", line 2196, 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 465, 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 465, 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 465, in async_post_call_streaming_iterator_hook async for item in response: yield item [Previous line repeated 3 more times] File "/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py", line 286, in async_post_call_streaming_iterator_hook async for chunk in response: ...<9 lines>... yield chunk File "/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py", line 465, 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 465, 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 465, 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/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py", line 511, in bedrock_sse_wrapper async for chunk in handler.async_sse_wrapper(completion_stream): yield chunk File "/usr/local/lib/python3.13/site-packages/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py", line 102, in async_sse_wrapper async for chunk in completion_stream: ...<2 lines>... yield encoded_chunk File "/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py", line 1712, 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 1731, 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."}",

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

level
:
"ERROR",
message
:
"litellm.proxy.proxy_server.async_data_generator(): Exception occured - 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/proxy/common_request_processing.py\", line 1375, in async_streaming_data_generator
    async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook(
    ...<33 lines>...
        yield serialize_chunk(chunk)
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 2196, 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 465, 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 465, 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 465, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 3 more times]
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py\", line 286, in async_post_call_streaming_iterator_hook
    async for chunk in response:
    ...<9 lines>...
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 465, 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 465, 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 465, 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/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py\", line 511, in bedrock_sse_wrapper
    async for chunk in handler.async_sse_wrapper(completion_stream):
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py\", line 102, in async_sse_wrapper
    async for chunk in completion_stream:
    ...<2 lines>...
        yield encoded_chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1712, 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 1731, 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.\"}",
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?

when user calls this endpoint, the stream goes through and this function async_sse_wrapper has no try/except block. So when bedrock sends InternalServerException, the raw bedrock error just passes through to the proxy, which logs the raw message with no mapping.

Expected: BedrockError caught and mapped to a proper LiteLLM exception Actual: Raw BedrockError propagates unhandled to the client

Steps to Reproduce

  1. An AWS account experiencing transient Bedrock overload.

Relevant log output

level
:
"ERROR",
message
:
"litellm.proxy.proxy_server.async_data_generator(): Exception occured - 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/proxy/common_request_processing.py\", line 1375, in async_streaming_data_generator
    async for chunk in proxy_logging_obj.async_post_call_streaming_iterator_hook(
    ...<33 lines>...
        yield serialize_chunk(chunk)
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/utils.py\", line 2196, 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 465, 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 465, 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 465, in async_post_call_streaming_iterator_hook
    async for item in response:
        yield item
  [Previous line repeated 3 more times]
  File \"/usr/local/lib/python3.13/site-packages/litellm/proxy/hooks/responses_id_security.py\", line 286, in async_post_call_streaming_iterator_hook
    async for chunk in response:
    ...<9 lines>...
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/integrations/custom_logger.py\", line 465, 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 465, 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 465, 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/llms/bedrock/messages/invoke_transformations/anthropic_claude3_transformation.py\", line 511, in bedrock_sse_wrapper
    async for chunk in handler.async_sse_wrapper(completion_stream):
        yield chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/anthropic/experimental_pass_through/messages/streaming_iterator.py\", line 102, in async_sse_wrapper
    async for chunk in completion_stream:
    ...<2 lines>...
        yield encoded_chunk
  File \"/usr/local/lib/python3.13/site-packages/litellm/llms/bedrock/chat/invoke_handler.py\", line 1712, 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 1731, 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.\"}",

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.81.12-stable

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To fix the issue, we need to add a try/except block to the async_sse_wrapper function to catch the BedrockError exception and map it to a proper LiteLLM exception.

Step-by-Step Solution

  1. Open the streaming_iterator.py file and navigate to the async_sse_wrapper function.
  2. Add a try/except block around the async for loop to catch the BedrockError exception.
  3. In the except block, log the error and raise a proper LiteLLM exception.

Example Code

async def async_sse_wrapper(self, completion_stream):
    try:
        async for chunk in completion_stream:
            encoded_chunk = self._encode_chunk(chunk)
            yield encoded_chunk
    except BedrockError as e:
        # Log the error
        logger.error(f"BedrockError: {e}")
        # Raise a proper LiteLLM exception
        raise LiteLLMException(f"Error processing request: {e}")

Verification

To verify that the fix worked, you can test the endpoint again and check the logs to see if the BedrockError exception is being caught and mapped to a proper LiteLLM exception.

Extra Tips

  • Make sure to test the fix thoroughly to ensure that it does not introduce any new issues.
  • Consider adding additional logging or monitoring to detect similar issues in the future.
  • If you are using a version control system, make sure to commit the changes and update the version number accordingly.

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