{"record":{"id":"69b2a3902f2d5b58","repo":"microsoft/semantic-kernel","slug":"the-provided-response-format-formatstring-is-n","errorCode":null,"errorMessage":"The provided response format '{formatString}' is not supported.","messagePattern":"The provided response format '(.+?)' is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs","lineNumber":165,"sourceCode":"    private static GeneratedImageFormat? GetResponseFormat(object? responseFormat)\n    {\n        if (responseFormat is null)\n        {\n            return null;\n        }\n\n        if (responseFormat is GeneratedImageFormat format)\n        {\n            return format;\n        }\n\n        if (responseFormat is string formatString)\n        {\n            return formatString.ToUpperInvariant() switch\n            {\n                \"URI\" or \"URL\" => GeneratedImageFormat.Uri,\n                \"BYTES\" or \"B64_JSON\" => GeneratedImageFormat.Bytes,\n                _ => throw new NotSupportedException($\"The provided response format '{formatString}' is not supported.\")\n            };\n        }\n\n        throw new NotSupportedException($\"The provided response format type '{responseFormat.GetType()}' is not supported.\");\n    }\n}\n","sourceCodeStart":147,"sourceCodeEnd":172,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Connectors/Connectors.OpenAI/Core/ClientCore.TextToImage.cs#L147-L172","documentation":"When the response format is provided as a string, it is matched case-insensitively against URI/URL (for URL output) and BYTES/B64_JSON (for base64 output). Any other string value throws NotSupportedException. This check runs before the HTTP request is sent.","triggerScenarios":"Passing OpenAITextToImageExecutionSettings.ResponseFormat a string like 'json', 'base64', 'image', or a MIME type that does not match the four accepted tokens.","commonSituations":"Using OpenAI API docs shorthand ('b64' without '_json'). Passing a response-format string valid for a different endpoint (chat completions vs image generation). Confusing the format token with the output file format.","solutions":["Use 'url' (or 'uri') for URL responses, or 'b64_json' (or 'bytes') for base64 responses.","Pass a GeneratedImageFormat enum value directly to avoid string-matching errors."],"exampleFix":"// before\nvar settings = new OpenAITextToImageExecutionSettings { ResponseFormat = \"base64\" };\n\n// after\nvar settings = new OpenAITextToImageExecutionSettings { ResponseFormat = \"b64_json\" };","handlingStrategy":"validation","validationCode":"static readonly HashSet<string> SupportedResponseFormats = new(StringComparer.OrdinalIgnoreCase)\n{\n    \"uri\", \"url\", \"bytes\", \"b64_json\"\n};\n\nvoid ValidateResponseFormat(string? format)\n{\n    if (format is not null && !SupportedResponseFormats.Contains(format.Trim()))\n        throw new ArgumentOutOfRangeException(nameof(format),\n            $\"ResponseFormat string must be one of: {string.Join(\", \", SupportedResponseFormats)}\");\n}","typeGuard":null,"tryCatchPattern":"try { await imageService.GetTextToImageAsync(prompt, settings); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"response format\"))\n{\n    settings.ResponseFormat = null; // or GeneratedImageFormat.Url\n    await imageService.GetTextToImageAsync(prompt, settings);\n}","preventionTips":["Prefer passing GeneratedImageFormat enum values instead of strings to avoid typo errors.","Validate string settings loaded from configuration at startup."],"tags":["text-to-image","response-format","validation","dalle"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}