BerriAI/litellm · error · BedrockError

{err.response.text}

Error message

{err.response.text}

What it means

In the async streaming invoke path, raise_for_status() converts any 4xx/5xx into BedrockError with the upstream status code and response text. Because this fires before SSE parsing begins, it means the stream was never established — the failure happened at the HTTP layer.

Source

Thrown at litellm/llms/bedrock/chat/invoke_handler.py:231

                sync_stream=False,
            )
            completion_stream = decoder.aiter_bytes(response.aiter_bytes(chunk_size=stream_chunk_size))
        else:
            decoder = AWSEventStreamDecoder(model=model, json_mode=json_mode)
            completion_stream = decoder.aiter_bytes(response.aiter_bytes(chunk_size=stream_chunk_size))

        # LOGGING
        logging_obj.post_call(
            input=messages,
            api_key="",
            original_response="first stream response received",
            additional_args={"complete_input_dict": data},
        )

        return completion_stream
    except httpx.HTTPStatusError as err:
        error_code: Final = err.response.status_code
        raise BedrockError(status_code=error_code, message=err.response.text)
    except httpx.TimeoutException:
        raise BedrockError(status_code=408, message="Timeout error occurred.")
    except Exception as e:
        raise BedrockError(status_code=500, message=str(e))


def make_sync_call(
    client: HTTPHandler | None,
    api_base: str,
    headers: dict,
    data: str,
    signed_json_body: bytes | None,
    model: str,
    messages: list,
    logging_obj: Logging,
    fake_stream: bool = False,
    json_mode: bool | None = False,
    bedrock_invoke_provider: litellm.BEDROCK_INVOKE_PROVIDERS_LITERAL | None = None,

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Inspect status_code; ensure IAM includes bedrock:InvokeModelWithResponseStream for streaming calls
  2. Double-check the model id and the region in the endpoint URL
  3. Use Router fallbacks or retries for throttling-induced 429s
  4. If the model disallows streaming, fall back to a non-streaming call
Defensive patterns

Strategy: try-catch

Try / catch

try:
    stream = await litellm.acompletion(model="bedrock/...", messages=msgs, stream=True)
except BedrockError as e:
    if e.status_code == 403:
        raise PermissionError("Add bedrock:InvokeModelWithResponseStream to IAM for streaming") from e
    if e.status_code == 429:
        await asyncio.sleep(2)
        stream = await litellm.acompletion(model="bedrock/...", messages=msgs, stream=True)
    else:
        raise

Prevention

When it happens

Trigger: 404 wrong model id on the invoke-model-with-response-stream endpoint; 403 missing bedrock:InvokeModelWithResponseStream permission; 429 throttled at connection time; 400 for streaming-unsupported configurations.

Common situations: IAM policies granting InvokeModel but not InvokeModelWithResponseStream (works non-streaming, fails streaming); typos in model ids; region mismatch between signing and endpoint.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/4bee4a08f68c1eea. Report an issue: GitHub.