microsoft/semantic-kernel · error · ServiceResponseException
No valid image data found in response.
Error message
No valid image data found in response.
What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/open_ai/services/open_ai_text_to_image_base.py:142
response = await self._send_request(settings)
assert isinstance(response, ImagesResponse) # nosec
if not response.data or not isinstance(response.data, list) or len(response.data) == 0:
raise ServiceResponseException("Failed to generate image.")
results: list[str] = []
for image in response.data:
url: str | None = getattr(image, "url", None)
b64_json: str | None = getattr(image, "b64_json", None)
if url:
results.append(url)
elif b64_json:
results.append(b64_json)
else:
continue
if len(results) == 0:
raise ServiceResponseException("No valid image data found in response.")
return results
async def edit_image(
self,
prompt: str,
image_paths: list[str] | None = None,
image_files: list[IO[bytes]] | None = None,
mask_path: str | None = None,
mask_file: IO[bytes] | None = None,
settings: PromptExecutionSettings | None = None,
**kwargs: Any,
) -> list[str]:
"""Edit images using the OpenAI image edit API.
Args:
prompt: Instructional prompt for image editing.
image_paths: List of image file paths to edit.
image_files: List of file-like objects (opened in binary mode) to edit.View on GitHub (pinned to c028a0c7dc)
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
Example fix
# before settings.response_format = "b64_json" await service.generate_images(prompt="...", settings=settings) # raises: No valid image data found in response. # after settings.response_format = "url" await service.generate_images(prompt="...", settings=settings)
Defensive patterns
Strategy: try-catch
Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceResponseException
try:
images = await service.generate_images(prompt=prompt, settings=settings)
except ServiceResponseException as e:
if "No valid image data" in str(e):
# data items lacked url/b64_json; adjust response_format and retry
settings.response_format = "url"
...
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to generate image.
- Failed to edit image.
- The OpenAI text to image model ID is required.
- Prompt is required.
- Provide either 'image_paths' or 'image_files', and only one.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/0cdec437ebf708f3.
Report an issue: GitHub.