{"record":{"id":"91738101a84ffa9f","repo":"microsoft/autogen","slug":"unsupported-content-type-item-gettype","errorCode":null,"errorMessage":"Unsupported content type {item.GetType()}","messagePattern":"Unsupported content type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs","lineNumber":151,"sourceCode":"        {\n            Temperature = request.Temperature,\n            MaxToken = request.MaxTokens,\n            StopSequence = request.Stop,\n        };\n    }\n\n    private MultiModalMessage CreateMultiModaMessageFromOpenAIUserMultiModalMessage(OpenAIUserMultiModalMessage message)\n    {\n        if (message.Content is null)\n        {\n            throw new ArgumentNullException(nameof(message.Content));\n        }\n\n        IEnumerable<IMessage> items = message.Content.Select<OpenAIUserMessageItem, IMessage>(item => item switch\n        {\n            OpenAIUserImageContent imageContent when imageContent.Url is string url => new ImageMessage(Role.User, url, this.agent.Name),\n            OpenAIUserTextContent textContent when textContent.Content is string content => new TextMessage(Role.User, content, this.agent.Name),\n            _ => throw new ArgumentException($\"Unsupported content type {item.GetType()}\")\n        });\n\n        return new MultiModalMessage(Role.User, items, this.agent.Name);\n    }\n}\n","sourceCodeStart":133,"sourceCodeEnd":157,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs#L133-L157","documentation":"Thrown by AutoGen's OpenAI-compatible WebAPI shim when converting an incoming multimodal chat-completions request. The converter (CreateMultiModaMessageFromOpenAIUserMultiModalMessage in OpenAIChatCompletionService.cs) only maps two item shapes: image content with a non-null 'image_url' (OpenAIUserImageContent.Url is string) and text content with a non-null string payload (OpenAIUserTextContent.Content is string). Any other OpenAIUserMessageItem subtype, or an image item whose Url is null, falls to the '_' arm and throws ArgumentException.","triggerScenarios":"POSTing to the hosted OpenAI-compatible endpoint (/chat/completions) with a user message whose content array contains an item of an unsupported 'type' (e.g. audio, video, file), or an image item serialized without/with a null 'image_url' field, or a text item with null 'text'.","commonSituations":"Pointing an OpenAI SDK/client at the AutoGen WebAPI and sending newer multimodal parts the DTO layer does not model; sending base64 image data in a field the shim does not read so Url deserializes to null; version skew where the client SDK emits content types newer than the server DTOs.","solutions":["Restrict multimodal content items to {\"type\":\"text\",\"text\":...} and {\"type\":\"image\",\"image_url\":...} with a non-null URL string","Ensure every image item carries an 'image_url' value; do not send image items with only base64 fields or missing url","If you need other modalities (audio, file), extend OpenAIUserMessageItem with a new DTO and add a matching switch arm in CreateMultiModaMessageFromOpenAIUserMultiModalMessage"],"exampleFix":"// before (request body)\n{\"role\":\"user\",\"content\":[{\"type\":\"image\"},{\"type\":\"text\",\"text\":\"hi\"}]}\n// after\n{\"role\":\"user\",\"content\":[{\"type\":\"image\",\"image_url\":\"https://example.com/cat.png\"},{\"type\":\"text\",\"text\":\"hi\"}]}","handlingStrategy":"validation","validationCode":"bool IsSupportedContent(JsonElement item)\n{\n    var type = item.TryGetProperty(\"type\", out var t) ? t.GetString() : null;\n    if (type == \"text\") return item.TryGetProperty(\"text\", out var txt) && txt.ValueKind == JsonValueKind.String;\n    if (type == \"image\") return item.TryGetProperty(\"image_url\", out var url) && url.ValueKind == JsonValueKind.String && !string.IsNullOrEmpty(url.GetString());\n    return false;\n}\n// before POST: if (msg.Content.Any(c => !IsSupportedContent(c))) return BadRequest(...);","typeGuard":"static bool IsSupportedItem(OpenAIUserMessageItem item) => item switch\n{\n    OpenAIUserImageContent img when img.Url is not null => true,\n    OpenAIUserTextContent txt when txt.Content is not null => true,\n    _ => false\n};","tryCatchPattern":"catch (ArgumentException ex) when (ex.Message.StartsWith(\"Unsupported content type\")) { return Results.BadRequest(new { error = new { message = ex.Message, type = \"invalid_request_error\" } }); }","preventionTips":["Validate request content items against the supported set (text with text, image with image_url) before forwarding","Keep the client SDK's content-type surface aligned with the AutoGen.WebAPI version you host","Return OpenAI-style 400 errors from your controller so client SDKs surface a readable message"],"tags":["autogen","webapi","openai-compat","multimodal","validation","csharp"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}