Skip to content

GrokChatClient fails to send images (DataContent) #72

Closed

Description

@macsux

Describe the Bug

Adding DataContent (such as image) to chat message does not actually get appended to Grok request

Steps to Reproduce

    [SecretsFact("XAI_API_KEY")]
    public async Task GrokImage()
    {
        var messages = new List<ChatMessage>();
        var image = new DataContent(File.ReadAllBytes(@"C:\temp\xai.png"), "image/png");
        var chatMessage = new ChatMessage(ChatRole.User, [new TextContent("Tell me what you see in the image"),image]);
        messages.Add(chatMessage);

        var chat = new GrokClient(Configuration["XAI_API_KEY"]!).AsIChatClient("grok-4")
            .AsBuilder()
            .UseLogging(output.AsLoggerFactory())
            .Build();

        var options = new GrokChatOptions
        {
            ModelId = "grok-4-fast-non-reasoning",
            AdditionalProperties = new()
            {
            }
        };

        var response = await chat.GetResponseAsync(messages, options);
        output.WriteLine(response.Messages.Select(x => x.Text).Last());
    }

Expected Behavior

Grok detects the image

Exception with Stack Trace

Put the exception with stack trace here.

Version Info

Latest source code / v1.0 on nuget both affected

Additional Info

Adding something like this to GrokChatClient seems to fix it, though this is probably more to it.

                if (content is DataContent dataContent)
                {
                    gmsg.Content.Add(new Content { ImageUrl = new ImageUrlContent() { ImageUrl = $"data:{dataContent.MediaType};base64,{dataContent.Base64Data}" }});
                }

Back this issue
Back this issue

Activity

  1. added
    bug
    on Feb 15, 2026
  2. locked and limited conversation to collaborators on Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions