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
- Configure an OpenAI-compatible provider (e.g., DeepSeek) with image modality enabled:
{
"provider": {
"deepseek": {
"models": {
"deepseek-v4-flash": {
"modalities": {
"input": ["text", "image"],
"output": ["text"]
}
}
}
}
}
}
- Start a new chat session with this model
- Paste an image (Ctrl+V) or attach an image file to the message
- 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
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
Root cause analysis
OpenCode's internal message content schema (used for validating request bodies) only recognizes
text,image, andaudioas validtypevariants in message content parts. However, when building the actual HTTP API request for OpenAI-compatible providers, image file parts are correctly converted to the OpenAIimage_urlformat (e.g.{ type: "image_url", image_url: { url: "data:..." } }). This converted format then fails schema validation becauseimage_urlis not a recognized variant in the internal schema.The conversion from
fileparts toimage_urlhappens 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
{ "provider": { "deepseek": { "models": { "deepseek-v4-flash": { "modalities": { "input": ["text", "image"], "output": ["text"] } } } } } }Expected behavior
OpenCode should properly handle image attachments by either:
a) Supporting
image_urlas a valid content variant alongsidetext,image, andaudioin the request validation schema, ORb) Converting image content to the MCP-compatible
imageformat before validationEnvironment
Related issues