Skip to content

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

@LifetimeVip

Description

@LifetimeVip

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions