{"record":{"id":"b21765ef6e063f0c","repo":"microsoft/semantic-kernel","slug":"failed-to-edit-image","errorCode":null,"errorMessage":"Failed to edit image.","messagePattern":"Failed to edit image\\.","errorType":"exception","errorClass":"ServiceResponseException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py","lineNumber":233,"sourceCode":"        if image_paths is not None:\n            images = [Path(p) for p in image_paths]\n        elif image_files is not None:\n            images = list(image_files)\n\n        mask: FileTypes | Omit = omit\n        if mask_path is not None:\n            mask = Path(mask_path)\n        elif mask_file is not None:\n            mask = mask_file\n\n        response: ImagesResponse = await self._send_image_edit_request(\n            image=images,\n            mask=mask,\n            settings=settings,\n        )\n\n        if not response or not response.data or not isinstance(response.data, list):\n            raise ServiceResponseException(\"Failed to edit image.\")\n\n        results: list[str] = []\n        for img in response.data:\n            b64_json: str | None = getattr(img, \"b64_json\", None)\n            url: str | None = getattr(img, \"url\", None)\n            if b64_json:\n                results.append(b64_json)\n            elif url:\n                results.append(url)\n        if not results:\n            raise ServiceResponseException(\"No valid image data found in response.\")\n        return results\n\n    def get_prompt_execution_settings_class(self) -> type[PromptExecutionSettings]:\n        \"\"\"Get the request settings class.\"\"\"\n        return OpenAITextToImageExecutionSettings\n","sourceCodeStart":215,"sourceCodeEnd":250,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py#L215-L250","documentation":"Raised by edit_image after the image-edit request returns. It validates that response is truthy, response.data exists, and response.data is a list; if any fail it throws ServiceResponseException. This catches a missing or malformed edit response before iteration.","triggerScenarios":"The edit endpoint returned None (request failure handled upstream into a falsy value), response.data is None, or response.data is not a list type. Common with proxy/compatible endpoints returning a different schema, or when the edit API returns an error-shaped 2xx.","commonSituations":"Non-OpenAI-compatible edit endpoint returning a non-standard body; the edit model isn't enabled for the deployment; a gateway returned an error envelope that still parsed.","solutions":["Confirm the model/deployment supports image edits (e.g. gpt-image-1) and is deployed","Verify the endpoint is the real OpenAI/compatible edit API","Log the raw response object to inspect the actual payload shape","Retry once to rule out a transient fault"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceResponseException\n\ntry:\n    res = await service.edit_image(prompt=p, image_paths=paths)\nexcept ServiceResponseException as e:\n    if \"Failed to edit image\" in str(e):\n        # response falsy or data not a list; inspect endpoint/deployment\n        ...\n    raise","preventionTips":["Confirm the deployment supports image edits (e.g. gpt-image-1)","Verify the endpoint is the real/compatible edit API","Log the raw response for diagnosis"],"tags":["openai","text-to-image","image-edit","response","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}