BerriAI/litellm · error · OpenRouterException
Error transforming OpenRouter image generation response: {e}
Error message
Error transforming OpenRouter image generation response: {e} What it means
After JSON parsing succeeds, the OpenRouter image-generation handler maps choices[].message.images[] into ImageResponse objects and attaches usage/cost. Any exception during this transformation is re-raised as an OpenRouterException with a generic status_code=500 and empty headers; the message embeds the original exception.
Source
Thrown at litellm/llms/openrouter/image_generation/transformation.py:396
revised_prompt=None,
)
)
else:
model_response.data.append(
ImageObject(
b64_json=None,
url=image_url,
revised_prompt=None,
)
)
# Extract and set usage and cost information
self._set_usage_and_cost(model_response, response_json, model)
return model_response
except Exception as e:
raise OpenRouterException(
message=f"Error transforming OpenRouter image generation response: {e}",
status_code=500,
headers={},
)
def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:
"""Get the appropriate error class for OpenRouter errors."""
return OpenRouterException(
message=error_message,
status_code=status_code,
headers=headers,
)
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Turn on litellm verbose logging to capture the raw JSON that failed the mapper
- Reproduce with curl and compare against the expected choices[].message.images[] shape
- Upgrade litellm to pick up schema fixes
- Report to litellm with the sanitized response if the latest version still fails
Defensive patterns
Strategy: try-catch
Try / catch
Catch OpenRouterException; a message starting with 'Error transforming' means the JSON parsed but the schema was unexpected. Keep the raw payload from logs, switch to an alternate image model/provider for the request, and report the schema change upstream.
Prevention
- Maintain a fallback image model list so schema drift degrades instead of failing
- Capture verbose logs in staging to catch schema changes before production
- Track litellm release notes for OpenRouter image-generation fixes
When it happens
Trigger: The parsed JSON lacks or changes the expected structure: missing choices, image entries without url fields, nulls where the mapper expects strings, or OpenRouter shipping a modified image-generation response schema for the requested model.
Common situations: Version drift between litellm and OpenRouter's response format; new models returning extra/renamed fields that the mapper cannot index; intermittent partial payloads under load.
Related errors
- Error transforming OpenRouter image edit response: {e}
- Error parsing OpenRouter response: {e}
- image generation config is not supported for {custom_llm_pro
- Model needs to be set for black_forest_labs
- Model needs to be set for bedrock
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/0fbb40ea19205ff7.
Report an issue: GitHub.