{"record":{"id":"0fbb40ea19205ff7","repo":"BerriAI/litellm","slug":"error-transforming-openrouter-image-generation-res","errorCode":null,"errorMessage":"Error transforming OpenRouter image generation response: {e}","messagePattern":"Error transforming OpenRouter image generation response: (.+?)","errorType":"http","errorClass":"OpenRouterException","httpStatus":500,"severity":"error","filePath":"litellm/llms/openrouter/image_generation/transformation.py","lineNumber":396,"sourceCode":"                                    revised_prompt=None,\n                                )\n                            )\n                        else:\n                            model_response.data.append(\n                                ImageObject(\n                                    b64_json=None,\n                                    url=image_url,\n                                    revised_prompt=None,\n                                )\n                            )\n\n            # Extract and set usage and cost information\n            self._set_usage_and_cost(model_response, response_json, model)\n\n            return model_response\n\n        except Exception as e:\n            raise OpenRouterException(\n                message=f\"Error transforming OpenRouter image generation response: {e}\",\n                status_code=500,\n                headers={},\n            )\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        \"\"\"Get the appropriate error class for OpenRouter errors.\"\"\"\n        return OpenRouterException(\n            message=error_message,\n            status_code=status_code,\n            headers=headers,\n        )\n","sourceCodeStart":378,"sourceCodeEnd":409,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openrouter/image_generation/transformation.py#L378-L409","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"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.","preventionTips":["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"],"tags":["openrouter","image-generation","response-mapping","schema-drift","litellm"],"backgroundTag":"response-schema-mismatch","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}