Skip to content

OpenAI-compatible providers: image_url content type fails deserialization when sending images #26106

Closed as not planned

Description

Description

When using DeepSeek V4 Flash (or other OpenAI-compatible providers) via a custom provider configuration with modalities: { input: ["text", "image"] }, attempting to paste/send an image attachment causes OpenCode to crash with a JSON deserialization error.

Error message

Failed to deserialize the JSON body into the target type: messages[196]: unknown variant `image_url`, expected `text` at line 1 column 764958

Root cause analysis

OpenCode's internal message content schema (used for validating request bodies) only recognizes text, image, and audio as valid type variants in message content parts. However, when building the actual HTTP API request for OpenAI-compatible providers, image file parts are correctly converted to the OpenAI image_url format (e.g. { type: "image_url", image_url: { url: "data:..." } }). This converted format then fails schema validation because image_url is not a recognized variant in the internal schema.

The conversion from file parts to image_url happens correctly in the provider layer, but the request body is subsequently validated against a schema that was designed for the MCP-style { type: "image", data: ..., mimeType: ... } format.

Steps to reproduce

  1. Configure an OpenAI-compatible provider (e.g., DeepSeek) with image modality enabled:
    {
      "provider": {
        "deepseek": {
          "models": {
            "deepseek-v4-flash": {
              "modalities": {
                "input": ["text", "image"],
                "output": ["text"]
              }
            }
          }
        }
      }
    }
  2. Start a new chat session with this model
  3. Paste an image (Ctrl+V) or attach an image file to the message
  4. The application crashes with the deserialization error shown above

Expected behavior

OpenCode should properly handle image attachments by either:
a) Supporting image_url as a valid content variant alongside text, image, and audio in the request validation schema, OR
b) Converting image content to the MCP-compatible image format before validation

Environment

  • OpenCode version: 1.14.39
  • Provider: DeepSeek V4 Flash (OpenAI-compatible API)
  • OS: Windows 11
  • Modalities configured: text + image

Related issues

Activity

  1. rekram1-node commented on Jun 22, 2026

    @rekram1-node
    Collaborator

    STOP SPAMMING ISSUES.

  2. VL4DST3R commented on Jun 22, 2026

    @VL4DST3R

    I was following this issue as well, is this effectively a duplicate of #30071 ? In the sense that i should follow it there instead?

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions