{"record":{"id":"0cdec437ebf708f3","repo":"microsoft/semantic-kernel","slug":"no-valid-image-data-found-in-response","errorCode":null,"errorMessage":"No valid image data found in response.","messagePattern":"No valid image data found in response\\.","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":142,"sourceCode":"        response = await self._send_request(settings)\n\n        assert isinstance(response, ImagesResponse)  # nosec\n        if not response.data or not isinstance(response.data, list) or len(response.data) == 0:\n            raise ServiceResponseException(\"Failed to generate image.\")\n\n        results: list[str] = []\n        for image in response.data:\n            url: str | None = getattr(image, \"url\", None)\n            b64_json: str | None = getattr(image, \"b64_json\", None)\n            if url:\n                results.append(url)\n            elif b64_json:\n                results.append(b64_json)\n            else:\n                continue\n\n        if len(results) == 0:\n            raise ServiceResponseException(\"No valid image data found in response.\")\n        return results\n\n    async def edit_image(\n        self,\n        prompt: str,\n        image_paths: list[str] | None = None,\n        image_files: list[IO[bytes]] | None = None,\n        mask_path: str | None = None,\n        mask_file: IO[bytes] | None = None,\n        settings: PromptExecutionSettings | None = None,\n        **kwargs: Any,\n    ) -> list[str]:\n        \"\"\"Edit images using the OpenAI image edit API.\n\n        Args:\n            prompt: Instructional prompt for image editing.\n            image_paths: List of image file paths to edit.\n            image_files: List of file-like objects (opened in binary mode) to edit.","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py#L124-L160","documentation":"Raised by generate_images after it iterates response.data collecting url/b64_json values. If data items existed but none carried a usable url or b64_json, results stays empty and it throws ServiceResponseException. This means the API returned image objects but every one lacked the expected payload fields.","triggerScenarios":"response.data is a non-empty list, but each item's url and b64_json attributes are both None/empty. This can happen with an unexpected response_format, a content-filtered per-item result, or a non-conforming provider response.","commonSituations":"Requested b64_json but the endpoint returned only revised_prompt metadata; using a third-party-compatible endpoint that omits these fields; per-image filter with no fallback.","solutions":["Set response_format on settings to match the field you intend to consume ('b64_json' or 'url')","If using a compatible non-OpenAI endpoint, confirm it populates url/b64_json","Retry with a different prompt to rule out a content filter on the specific input"],"exampleFix":"# before\nsettings.response_format = \"b64_json\"\nawait service.generate_images(prompt=\"...\", settings=settings)\n# raises: No valid image data found in response.\n\n# after\nsettings.response_format = \"url\"\nawait service.generate_images(prompt=\"...\", settings=settings)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceResponseException\n\ntry:\n    images = await service.generate_images(prompt=prompt, settings=settings)\nexcept ServiceResponseException as e:\n    if \"No valid image data\" in str(e):\n        # data items lacked url/b64_json; adjust response_format and retry\n        settings.response_format = \"url\"\n        ...\n    raise","preventionTips":["Set response_format on settings to match the field you read","Confirm compatible endpoints populate url/b64_json","Retry with a different prompt to rule out filtering"],"tags":["openai","text-to-image","response","python"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}