{"record":{"id":"9315a408047501e3","repo":"microsoft/semantic-kernel","slug":"the-generated-image-has-no-valid-content","errorCode":null,"errorMessage":"The generated image has no valid content.","messagePattern":"The generated image has no valid content\\.","errorType":"exception","errorClass":"KernelException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs","lineNumber":59,"sourceCode":"\n        // The model is not required by the OpenAI API and defaults to the DALL-E 2 server-side - https://platform.openai.com/docs/api-reference/images/create#images-create-model.\n        // However, considering that the model is required by the OpenAI SDK and the ModelId property is optional, it defaults to gpt-image-1 in the line below.\n        targetModel = string.IsNullOrEmpty(targetModel) ? \"gpt-image-1\" : targetModel!;\n\n        ClientResult<GeneratedImage> response = await RunRequestAsync(() => this.Client!.GetImageClient(targetModel).GenerateImageAsync(prompt, imageOptions, cancellationToken)).ConfigureAwait(false);\n        var generatedImage = response.Value;\n\n        if (generatedImage.ImageUri is not null)\n        {\n            return generatedImage.ImageUri.ToString();\n        }\n\n        if (generatedImage.ImageBytes is not null)\n        {\n            return $\"data:image/png;base64,{Convert.ToBase64String(generatedImage.ImageBytes.ToArray())}\";\n        }\n\n        throw new KernelException(\"The generated image has no valid content.\");\n    }\n\n    /// <summary>\n    /// Generates an image with the provided configuration.\n    /// </summary>\n    /// <param name=\"targetModel\">Model identifier</param>\n    /// <param name=\"input\">The input text content to generate the image</param>\n    /// <param name=\"executionSettings\">Execution settings for the image generation</param>\n    /// <param name=\"kernel\">Kernel instance</param>\n    /// <param name=\"cancellationToken\">Cancellation token</param>\n    /// <returns>List of image generated contents</returns>\n    internal async Task<IReadOnlyList<ImageContent>> GetImageContentsAsync(\n        string targetModel,\n        TextContent input,\n        PromptExecutionSettings? executionSettings = null,\n        Kernel? kernel = null,\n        CancellationToken cancellationToken = default)\n    {","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs#L41-L77","documentation":"After a successful image-generation HTTP response, the connector checks for both ImageUri and ImageBytes on the returned object. If both are null, it throws because there is no content to return as an ImageContent/Blob. This is a defensive check against an empty or malformed generation result.","triggerScenarios":"The image-generation API returns HTTP 200 with a response body that contains neither a URL nor base64 image data. Occurs when the requested response format doesn't match what the model returned, the API changed its response shape, or a content-filter blocked the image but still returned 200.","commonSituations":"Requesting response format 'b64_json' from a deployment/model that only returns URLs (or vice-versa). Azure OpenAI content filtering rejecting the prompt but returning an empty image object. API version skew between the SDK and the deployed model.","solutions":["Retry the request once — transient content-filter or backend issues can produce empty results.","Check your requested response format; try switching between 'url' and 'b64_json' to match the deployment's capability.","Simplify the prompt to avoid potential content-filter triggers.","Inspect the raw API response body to confirm whether the fields are absent or present-but-empty.","Verify the model deployment supports the DALL-E / image-generation endpoint you are calling."],"exampleFix":"// before — format may not be supported by the deployment\nvar settings = new OpenAITextToImageExecutionSettings { ResponseFormat = \"b64_json\" };\n\n// after — let the API choose, or switch to url\nvar settings = new OpenAITextToImageExecutionSettings();","handlingStrategy":"retry","validationCode":"// No pre-call validation can prevent a server-side empty result.\n// Instead, validate the response format setting matches deployment capabilities.\nif (settings.ResponseFormat is string rf && rf.Equals(\"b64_json\", StringComparison.OrdinalIgnoreCase))\n{\n    // Ensure deployment supports base64 responses; otherwise use url\n}","typeGuard":null,"tryCatchPattern":"for (int attempt = 0; attempt < 3; attempt++)\n{\n    try { return await imageService.GetImageContentsAsync(prompt, settings, kernel); }\n    catch (KernelException ex) when (ex.Message.Contains(\"no valid content\") && attempt < 2)\n    {\n        await Task.Delay(TimeSpan.FromSeconds(2 * (attempt + 1)));\n    }\n}\nthrow; // exhausted retries","preventionTips":["Match the response format to the deployment's documented capability.","Keep prompts simple to avoid content-filter rejections that produce empty images.","Implement retry with backoff for image generation since empty results are often transient."],"tags":["text-to-image","response-validation","dalle","openai"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}