microsoft/autogen · error · ArgumentException
Unsupported content type {item.GetType()}
Error message
Unsupported content type {item.GetType()} What it means
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.
Source
Thrown at dotnet/src/AutoGen.WebAPI/OpenAI/Service/OpenAIChatCompletionService.cs:151
{
Temperature = request.Temperature,
MaxToken = request.MaxTokens,
StopSequence = request.Stop,
};
}
private MultiModalMessage CreateMultiModaMessageFromOpenAIUserMultiModalMessage(OpenAIUserMultiModalMessage message)
{
if (message.Content is null)
{
throw new ArgumentNullException(nameof(message.Content));
}
IEnumerable<IMessage> items = message.Content.Select<OpenAIUserMessageItem, IMessage>(item => item switch
{
OpenAIUserImageContent imageContent when imageContent.Url is string url => new ImageMessage(Role.User, url, this.agent.Name),
OpenAIUserTextContent textContent when textContent.Content is string content => new TextMessage(Role.User, content, this.agent.Name),
_ => throw new ArgumentException($"Unsupported content type {item.GetType()}")
});
return new MultiModalMessage(Role.User, items, this.agent.Name);
}
}
View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before (request body)
{"role":"user","content":[{"type":"image"},{"type":"text","text":"hi"}]}
// after
{"role":"user","content":[{"type":"image","image_url":"https://example.com/cat.png"},{"type":"text","text":"hi"}]} Defensive patterns
Strategy: validation
Validate before calling
bool IsSupportedContent(JsonElement item)
{
var type = item.TryGetProperty("type", out var t) ? t.GetString() : null;
if (type == "text") return item.TryGetProperty("text", out var txt) && txt.ValueKind == JsonValueKind.String;
if (type == "image") return item.TryGetProperty("image_url", out var url) && url.ValueKind == JsonValueKind.String && !string.IsNullOrEmpty(url.GetString());
return false;
}
// before POST: if (msg.Content.Any(c => !IsSupportedContent(c))) return BadRequest(...); Type guard
static bool IsSupportedItem(OpenAIUserMessageItem item) => item switch
{
OpenAIUserImageContent img when img.Url is not null => true,
OpenAIUserTextContent txt when txt.Content is not null => true,
_ => false
}; Try / catch
catch (ArgumentException ex) when (ex.Message.StartsWith("Unsupported content type")) { return Results.BadRequest(new { error = new { message = ex.Message, type = "invalid_request_error" } }); } Prevention
- 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
When it happens
Trigger: 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'.
Common situations: 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.
Related errors
- Only TextContent and ImageContent are allowed in MultiModalM
- Invalid aggregate message {reason}
- The method or operation is not implemented.
- ImageMessage must have Url or DataUri
- MultiModalMessage is not supported in the semantic kernel if
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/91738101a84ffa9f.
Report an issue: GitHub.