BerriAI/litellm · error · BedrockError

err.response.text

Error message

err.response.text

What it means

Raised from BedrockImageGeneration.image_generation when the synchronous POST to the Bedrock runtime endpoint returns a non-2xx status. response.raise_for_status() throws httpx.HTTPStatusError and LiteLLM re-raises it as BedrockError carrying the upstream status code and the raw AWS response body as the message. It is a pass-through of AWS's error JSON (validation, throttling, access denied, model not found, etc.).

Solutions

  1. Read the message field: it is the raw AWS error body and names the concrete cause (validation, access, throttling)
  2. Verify the model id exists and is enabled in aws_region_name and that credentials have bedrock:InvokeModel
  3. For 429/5xx statuses retry with exponential backoff
Defensive patterns

Strategy: try-catch

Try / catch

from litellm.llms.bedrock.common_utils import BedrockError

try:
    resp = litellm.image(model=model, prompt=prompt)
except BedrockError as e:
    if e.status_code in (429, 500, 502, 503):
        backoff_and_retry()  # transient upstream conditions
    else:
        handle_permanent(e.status_code, e.message)  # e.message is the raw AWS error body

Prevention

When it happens

Trigger: litellm.image() against a Bedrock image model where AWS returns 4xx/5xx: invalid imageGenerationConfig values, model not enabled in the region, ThrottlingException (429), missing bedrock:InvokeModel permission, or a malformed model id.

Common situations: Wrong region/model-id combinations, IAM roles without Bedrock invoke permissions, throttling under load, oversized images or invalid width/height/quality values in optional_params.

Related errors


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

Appendix: source

Thrown at litellm/llms/bedrock/image_generation/image_handler.py:122

                model=model,
                logging_obj=logging_obj,
                prompt=prompt,
                model_response=model_response,
                client=(client if client is not None and isinstance(client, AsyncHTTPHandler) else None),
            )

        if client is None or not isinstance(client, HTTPHandler):
            client = _get_httpx_client()
        try:
            response: Final = client.post(
                url=prepared_request.endpoint_url,
                headers=prepared_request.prepped.headers,
                data=prepared_request.body,
            )
            response.raise_for_status()
        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.")
        ### FORMAT RESPONSE TO OPENAI FORMAT ###
        model_response = self._transform_response_dict_to_openai_response(
            model_response=model_response,
            model=model,
            logging_obj=logging_obj,
            prompt=prompt,
            response=response,
            data=prepared_request.data,
        )
        return model_response

    async def async_image_generation(
        self,
        prepared_request: BedrockImagePreparedRequest,
        timeout: float | httpx.Timeout | None,
        model: str,

View on GitHub (pinned to 77b7c6c40c)