microsoft/semantic-kernel · error · NotSupportedException

Invalid message content, only text, image url and document u

Error message

Invalid message content, only text, image url and document url are supported.

What it means

Thrown as a NotSupportedException when a chat message item is not recognized as TextContent, ImageContent, or BinaryContent (document). The Mistral connector only supports text, image URLs, and document URLs in message content; any other content type triggers this error during request serialization.

Source

Thrown at dotnet/src/Connectors/Connectors.MistralAI/Client/MistralClient.cs:811

                {
                    content.Add(new ImageUrlChunk(imageContent.Uri.ToString()));
                    continue;
                }

                if (imageContent.DataUri is not null)
                {
                    content.Add(new ImageUrlChunk(imageContent.DataUri));
                    continue;
                }
            }

            if (item is BinaryContent binaryContent && binaryContent.Uri is not null)
            {
                content.Add(new DocumentUrlChunk(binaryContent.Uri.ToString()));
                continue;
            }

            throw new NotSupportedException("Invalid message content, only text, image url and document url are supported.");
        }

        return [new MistralChatMessage(chatMessage.Role.ToString(), content)];
    }

    private HttpRequestMessage CreatePost(object requestData, Uri endpoint, string apiKey, bool stream)
    {
        var httpRequestMessage = HttpRequest.CreatePostRequest(endpoint, requestData);
        this.SetRequestHeaders(httpRequestMessage, apiKey, stream);

        return httpRequestMessage;
    }

    private void SetRequestHeaders(HttpRequestMessage request, string apiKey, bool stream)
    {
        request.Headers.Add("User-Agent", HttpHeaderConstant.Values.UserAgent);
        request.Headers.Add(HttpHeaderConstant.Names.SemanticKernelVersion, HttpHeaderConstant.Values.GetAssemblyVersion(this.GetType()));
        request.Headers.Add("Accept", stream ? "text/event-stream" : "application/json");

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Filter or convert unsupported content types to text before sending to Mistral.
  2. Check each item's type: only include TextContent, ImageContent (with DataUri), or BinaryContent (with a Uri).
  3. If sending audio/video, transcribe or convert to text first, or use a connector that supports that modality.

Example fix

// before
var msg = new ChatMessageContent(AuthorRole.User, contents: new List<KernelContent>
{
    new TextContent("describe this"),
    new AudioContent(audioBytes, mimeType: "audio/wav") // unsupported by Mistral
});

// after
var msg = new ChatMessageContent(AuthorRole.User, contents: new List<KernelContent>
{
    new TextContent("describe this"),
    new ImageContent(dataUri) // supported
});
Defensive patterns

Strategy: validation

Validate before calling

var supported = msg.Items.All(i =>
    i is TextContent or ImageContent or BinaryContent);
if (!supported)
    throw new InvalidOperationException("Unsupported content type for Mistral.");

Type guard

static bool HasOnlySupportedContent(IEnumerable<KernelContent> items) =>
    items.All(i => i is TextContent or ImageContent or BinaryContent);

Prevention

When it happens

Trigger: Adding an unsupported content type (e.g., AudioContent, VideoContent, or a custom Content subclass) to a ChatMessageContent.Items collection that gets sent to Mistral.

Common situations: Sharing content-building code across connectors where another connector supports richer content types; upgrading the Semantic Kernel version and new content types became available but Mistral does not support them yet.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/cdf6152ad7a000c8. Report an issue: GitHub.