{"record":{"id":"9f004cf70feead7c","repo":"BerriAI/litellm","slug":"error-transforming-openrouter-image-edit-response","errorCode":null,"errorMessage":"Error transforming OpenRouter image edit response: {e}","messagePattern":"Error transforming OpenRouter image edit response: (.+?)","errorType":"http","errorClass":"OpenRouterException","httpStatus":500,"severity":"error","filePath":"litellm/llms/openrouter/image_edit/transformation.py","lineNumber":248,"sourceCode":"\n                            model_response.data.append(\n                                ImageObject(\n                                    b64_json=b64_data,\n                                    url=None,\n                                    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        except Exception as e:\n            raise OpenRouterException(\n                message=f\"Error transforming OpenRouter image edit response: {e}\",\n                status_code=500,\n                headers={},\n            )\n\n        self._set_usage_and_cost(model_response, response_json, model)\n        return model_response\n\n    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> BaseLLMException:\n        return OpenRouterException(\n            message=error_message,\n            status_code=status_code,\n            headers=headers,\n        )\n\n    # Private helper methods\n\n    def _map_size_to_aspect_ratio(self, size: str) -> str:","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openrouter/image_edit/transformation.py#L230-L266","documentation":"After the OpenRouter image-edit response parses as JSON, LiteLLM maps choices[].message.images[] entries into ImageResponse objects and extracts usage/cost. Any exception during this mapping (missing keys, unexpected nesting, None where a string is expected) is caught and re-raised as an OpenRouterException with a generic status_code=500 and empty headers. The original exception text is embedded in the message.","triggerScenarios":"OpenRouter returns a response whose choices/message/images shape differs from what the mapper expects: choices without images, image entries missing image_url, null fields where the mapper indexes into dicts, or a schema change deployed by OpenRouter for a specific image model.","commonSituations":"Schema drift between your litellm version and OpenRouter's current image-edit response format; using a chat-only model on the image-edit route so response fields are absent; A/B changes on OpenRouter's side that omit url/b64 fields.","solutions":["Enable litellm verbose logging (litellm.set_verbose=True) or log the raw response to see which field broke the mapper","Reproduce the request with curl against OpenRouter and compare the JSON against the expected choices[].message.images[] shape","Confirm the model is image-capable and served through OpenRouter's image-edit endpoint","Upgrade litellm - response-schema drift for OpenRouter is typically patched upstream quickly","If the latest version still fails, open a litellm issue with the sanitized raw JSON"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Catch OpenRouterException and test whether the message starts with 'Error transforming' - that indicates a schema/mapping defect, so retrying the same model is futile; capture verbose logs and fail over to a different image model or provider.","preventionTips":["Pin known-good image model versions instead of floating aliases","Keep litellm.set_verbose available in debug builds to capture raw payloads","Update litellm promptly when OpenRouter announces response format changes"],"tags":["openrouter","image-edit","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"}