BerriAI/litellm · error · BedrockError

Timeout error occurred.

Error message

Timeout error occurred.

What it means

The sync Bedrock image-edit call wraps httpx.TimeoutException into BedrockError(status_code=408, message='Timeout error occurred.'). It fires when the POST to the Bedrock runtime endpoint exceeds the httpx client's configured timeout (default or the timeout param passed to the handler) before any response arrives.

Source

Thrown at litellm/llms/bedrock/image_edit/handler.py:119

                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_edit(
        self,
        prepared_request: BedrockImageEditPreparedRequest,
        timeout: float | httpx.Timeout | None,
        model: str,
        logging_obj: LitellmLogging,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Raise the timeout for image-edit calls: pass timeout=<seconds> (e.g. 120) to litellm.image_edit / the router.
  2. Shrink images before sending (Nova Canvas accepts bounded resolutions; smaller payloads sign and upload faster).
  3. Retry transient timeouts with backoff — the request is idempotent from the client's view (no side effects besides spend).
  4. Check network path (NAT/proxy) for throttling large request bodies.

Example fix

# before
resp = litellm.image_edit(model=..., image=img, prompt=...)  # default timeout -> 408
# after
resp = litellm.image_edit(model=..., image=img, prompt=..., timeout=120)
Defensive patterns

Strategy: retry

Try / catch

from litellm.exceptions import BedrockError

for attempt in range(3):
    try:
        resp = litellm.image_edit(model=m, image=img, prompt=p, timeout=120)
        break
    except BedrockError as e:
        if e.status_code != 408 or attempt == 2:
            raise
        time.sleep(2 ** attempt)

Prevention

When it happens

Trigger: Large image payloads (multi-MB base64 in the signed body) over slow links; Bedrock image generation legitimately taking tens of seconds while the client timeout is lower; congested network or proxy stalls between client and bedrock-runtime.<region>.amazonaws.com.

Common situations: Default aggressive timeouts in serverless (e.g. 10-30s) while Nova/Stability edits take 30-60s+; uploading 4K images; VPC NAT bottleneck; retry storms amplifying latency.

Understand the failure class

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/f15508532173b03f. Report an issue: GitHub.