BerriAI/litellm · error · BedrockError
err.response.text
Error message
err.response.text
What it means
The synchronous Bedrock image-generation HTTP call returned a non-2xx status; response.raise_for_status() raised httpx.HTTPStatusError and litellm re-raised it as BedrockError with the upstream status code and raw response body (err.response.text). The body is Bedrock's own error JSON (e.g. validation errors, throttling, model access denied).
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 6c2dcb801b)
Solutions
- Read the message body: it contains the AWS error code and message (e.g. 'ModelStreamErrorException', 'ValidationException').
- Verify the model ID exists and your account has access in the target region (Bedrock console > Model access).
- Check IAM permissions include bedrock:InvokeModel and that credentials/region env vars are set.
- For 429, retry with exponential backoff or reduce request rate.
- Sync system clock if you suspect SigV4 'Signature expired' errors.
Defensive patterns
Strategy: retry
Try / catch
from litellm.exceptions import BedrockError
for attempt in range(5):
try:
return litellm.image_generation(model=model, prompt=p)
except BedrockError as e:
if e.status_code == 429 and attempt < 4:
time.sleep(2 ** attempt + random.random())
continue
raise Prevention
- Enable Bedrock model access and verify IAM bedrock:InvokeModel before shipping.
- Log err.response.text verbatim — it contains the exact AWS error code for triage.
- Implement retry-with-backoff for 429/5xx only, never for 400/403.
When it happens
Trigger: POST to bedrock-runtime/model/invoke with invalid payload (400), missing model access (403/404 AccessDeniedException), throttling (429 TooManyRequestsException), or wrong region/endpoint (403).
Common situations: Model ID typos (stability.stable-image-core vs ...:0), no model subscription in the AWS account, IAM credentials lacking bedrock:InvokeModel, expired SigV4 signature due to clock skew, hitting account TPS limits.
Related errors
- Model needs to be set for bedrock
- err.response.text
- {err.response.text}
- BedrockException: Context Window Error - {error_str}
- BedrockException Invalid Authentication - {error_str}
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/9ca71f70bcff932a.
Report an issue: GitHub.