xAI: a GIF image gets 400 invalid_image and breaks the session (v2) · Issue #53786 · anomalyco/opencode · GitHub
Skip to content

xAI: a GIF image gets 400 invalid_image and breaks the session (v2) #53786

Closed

Description

@Jaaneek

Description

xAI only accepts JPEG, PNG and WebP images. When a GIF is sent to an xAI model, either attached by the user or returned by the read tool, the request fails with 400 invalid_image. The GIF stays in the session, so every later turn fails the same way and the session is stuck.

The API returns the same error for a plain request, while the same request with a PNG works:

curl https://api.x.ai/v1/chat/completions -H "Authorization: Bearer $XAI_API_KEY" -H "Content-Type: application/json" \
  -d '{"model":"grok-4.7","messages":[{"role":"user","content":[{"type":"text","text":"What is in this image?"},{"type":"image_url","image_url":{"url":"data:image/gif;base64,'"$(base64 < shapes.gif | tr -d '\n')"'"}}]}]}'
# 400 {"code":"invalid_image","error":"... Downloaded response does not contain a valid JPG, PNG, WebP, or ICO image."}

Plugins

none

OpenCode version

v2 branch (5183ea4)

Steps to reproduce

  1. Put a GIF at assets/shapes.gif
  2. opencode run -m xai/grok-4.7 -f assets/shapes.gif "What shapes are in this image?" fails with 400 invalid_image
  3. opencode run -m xai/grok-4.7 --continue "Just reply OK." fails the same way, because the GIF is sent again

Reading the GIF with the read tool fails the same way.

Screenshot and/or share link

Test GIF: Test GIF: a red square and a blue circle

Operating System

macOS 26

Activity

  1. opencode-agent commented on Oct 7, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I reproduced this on v2.0.24 using a local stand-in for the xAI endpoint that returns xAI's invalid_image 400 for GIFs:

    1. opencode run -m xai/grok-4.7 -f assets/shapes.gif "What shapes are in this image?": the GIF is sent as data:image/gif;base64,... and the request fails with Image could not be processed: Downloaded response does not contain a valid JPG, PNG, WebP, or ICO image.
    2. opencode run -m xai/grok-4.7 --continue "Just reply OK.": the stored GIF is sent again and the turn fails the same way, so the session stays stuck.

    OpenCode only checks whether a model accepts images at all, not which image formats a provider accepts, so a GIF goes to xAI unchanged. Your PR #53787 targets this, and #53014 proposes a more general way to recover from rejected attachments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions