BerriAI/litellm · error · BedrockError
Timeout error occurred.
Error message
Timeout error occurred.
What it means
The synchronous Bedrock image-generation request exceeded the configured httpx timeout and httpx.TimeoutException was raised; litellm maps it to BedrockError with status_code=408 and the fixed message 'Timeout error occurred.'. Image generation on Bedrock commonly takes tens of seconds, so the default timeout is frequently too short.
Source
Thrown at litellm/llms/bedrock/image_generation/image_handler.py:124
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,
logging_obj: LitellmLogging,
prompt: str,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Pass a larger timeout explicitly: litellm.image_generation(..., timeout=300).
- Reduce output cost: fewer images (numberOfImages=1), smaller width/height, fewer inference steps.
- Retry once on timeout — the request is idempotent from the client's perspective.
- If persistent, check network egress/proxy latency to the bedrock-runtime endpoint.
Example fix
# before resp = litellm.image_generation(model="bedrock/stability.stable-image-core-1:0", prompt=p) # after resp = litellm.image_generation(model="bedrock/stability.stable-image-core-1:0", prompt=p, timeout=300)
Defensive patterns
Strategy: retry
Try / catch
try:
resp = litellm.image_generation(model=model, prompt=p, timeout=300)
except BedrockError as e:
if e.status_code == 408:
resp = litellm.image_generation(model=model, prompt=p, timeout=600) # one timed retry
else:
raise Prevention
- Always pass an explicit generous timeout for image generation (60-300s).
- Treat 408 BedrockError as retryable with backoff.
- Scale requested image count/resolution to your latency budget.
When it happens
Trigger: litellm.image_generation(..., timeout=N) or the default client timeout being smaller than the actual generation time; slow models (e.g. stability.stable-diffusion-xl with many steps) on loaded endpoints.
Common situations: Using the default timeout for high-resolution/multi-image jobs, network bottlenecks, oversized prompts, or proxy-side latency.
Understand the failure class
- Timeouts: ETIMEDOUT, deadlines, and hung requests — what actually expires when a request times out.
Related errors
- Model needs to be set for bedrock
- BedrockException: Timeout Error - {error_str}
- completion_response must be of type ImageResponse for bedroc
- Timeout error occurred.
- Timeout error occurred.
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/eba596ec28b840ec.
Report an issue: GitHub.