anomalyco / anomalyco/opencode
Grok CLI + opencode.ai Gateway 400 Error
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
When using Grok CLI to call the DeepSeek V4 Flash model through the opencode.ai gateway (https://opencode.ai/zen/go/v1), requests return a 400 Bad Request error when the conversation history contains image content.
Error Message
API error (status 400 Bad Request): invalid_request_error: Error from provider (Console Go):
Upstream request failed: [invalid_request_error] Failed to deserialize the JSON body into
the target type: messages[132]: unknown variant image_url, expected text at line 1 column 568961
Environment Configuration
Grok Configuration (~/.grok/config.toml)
[models]
default = "og-deepseek-flash"
[model.og-deepseek-flash]
model = "deepseek-v4-flash"
base_url = "https://opencode.ai/zen/go/v1"
name = "DeepSeek V4 Flash (opencode go)"
env_key = "OPENCODE_GO_API_KEY"
api_backend = "chat_completions"
context_window = 1000000
MCP Plugins
[mcp_servers.qwen-mm-plugins-core]
command = "uvx"
args = [
"--from",
"qwen-mm-plugins[core] @ git+https://github.com/QwenLM/Qwen-MM-Plugins.git@main",
"qwen-mm-plugins-core",
]
enabled = true
Root Cause Analysis
Format Transformation Flow
┌─────────────────────────────────────────────────────────────────────────┐
│ Current Flow (Causing Error) │
├─────────────────────────────────────────────────────────────────────────┤
│ 1. Grok Internal Storage: │
│ {"type": "image", "url": "data:image/jpeg;base64,..."} │
│ │
│ 2. Grok Builds API Request → Converts to OpenAI Standard Format: │
│ {"type": "image_url", "image_url": {"url": "data:..."}} │
│ │
│ 3. Sends to opencode.ai/zen/go/v1 (chat_completions backend) │
│ │
│ 4. DeepSeek API Deserialization Fails ❌ │
│ Error: unknown variant `image_url', expected 'text' │
└─────────────────────────────────────────────────────────────────────────┘
Root Cause
- opencode.ai gateway's
chat_completionsbackend is not fully compatible with OpenAI's multimodal format
- OpenAI standard uses
{"type": "image_url", "image_url": {...}} - DeepSeek API's deserializer only accepts
{"type": "text"}
- Images in conversation history are accumulated
- Error occurs at
messages[132], indicating a long conversation history - Images from historical messages are sent together with new requests
- MCP plugins cannot solve this issue
- qwen-mm-plugins-core provides MCP tools but does not intercept API requests
- Images are directly included in chat_history and sent to the API
Log Evidence
unified.jsonl Log
{
"ts": "2026-08-11T02:50:57.715Z",
"src": "shell",
"lvl": "error",
"msg": "shell.turn.inference_failed",
"ctx": {
"kind": "api",
"status_code": 400,
"is_retryable": false,
"message": "API error (status 400 Bad Request): invalid_request_error: Error from provider (Console Go): Upstream request failed: [invalid_request_error] Failed to deserialize the JSON body into the target type: messages[132]: unknown variant `image_url`, expected `text` at line 1 column 568961"
}
}
Image Budget Log
{
"msg": "shell.image_budget",
"ctx": {
"inline_images": 5,
"body_bytes": 731237
}
}
Steps to Reproduce
- Use
og-deepseek-flashmodel in Grok CLI - Upload an image or use a tool that produces image results
- Continue the conversation to build up message history
- Send a new request when history contains images
- Receive 400 error
Expected Behavior
Option A: Gateway-level transformation
The opencode.ai gateway should convert OpenAI-formatted image_url to a format accepted by DeepSeek API before forwarding (e.g., convert images to text via OCR, or use a DeepSeek-supported image format).
Option B: Clear documentation
Clearly document in the documentation that the chat_completions backend of opencode.ai gateway does not support OpenAI's multimodal format, and clients should avoid sending image content.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the request with image content in conversation history through the chat_completions backend, then trace where OpenAI image_url parts are transformed before forwarding to the gateway. Done means the request is accepted with supported image handling, or the documentation clearly states that this multimodal format is unsupported and how clients should avoid it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100