kimi-code icon indicating copy to clipboard operation
kimi-code copied to clipboard

400 "unknown variant `image_url`, expected `text`" from text-only OpenAI-compatible providers when history contains images — poisons every subsequent turn

Open arimaze opened this issue 3 months ago • 1 comments

Environment

  • Kimi Code CLI 0.33.0, Linux (WSL2, Ubuntu 24.04)
  • Custom OpenAI-compatible provider in config.toml: type = "openai", base_url = "https://api.deepseek.com/v1", model declared with capabilities = [ "thinking", "tool_use" ] (no vision), used as [secondary_model]

Steps to reproduce

  1. Work in a session whose history contains image blocks (e.g. results of the built-in media-read tool, or pasted images).
  2. Switch the session model to the text-only model (/model), or route a turn to it as the configured secondary model.
  3. Send any message.

Actual behavior

Every request fails with:

[provider.api_error] 400 Failed to deserialize the JSON body into the target type:
messages[119]: unknown variant `image_url`, expected `text`

Kimi Code replays the history verbatim, so the provider (whose chat-completions schema only accepts text content parts for this model) rejects the whole payload. Because the image block stays in history, every subsequent turn fails the same way — the session is effectively bricked until the wire file is hand-patched.

Expected behavior

When the resolved model has no vision capability (Kimi Code already knows the capability set from the model declaration / catalog), image (and other non-text) content parts should be stripped or converted to a text placeholder before the request is sent, instead of being forwarded verbatim.

Notes

  • Same failure class as #1082 (failed image re-sent every turn deadlocks the session) and related to #905 (pasted images on text-only models) — but here the trigger is history replay to a custom OpenAI-compatible text-only provider via /model switch or secondary-model routing, and the error surfaces as a provider-side deserialization 400.
  • Current workarounds on our side: only run text-only models in fresh sessions without images, and a maintenance script that rewrites image blocks to text in wire.jsonl to unbrick affected sessions.

arimaze avatar Aug 05 '26 21:08 arimaze

Same failure class here, with an additional entry point and a worse symptom — Kimi Code CLI 0.34.0, Windows 11.

Entry point: MCP tool results, not paste/ReadMediaFile. The image entered history because the agent itself called the computer-use plugin's get_app_state with mode: "image" while debugging a GUI app; the screenshot was appended as an image_url (blobref) part of the tool result. The active model was a text-only DeepSeek model served by a custom openai-type gateway (the gateway echoes a legacy model ID, so the error reads 400 qwen3.5-397b is not a multimodal model). capabilities had no image_in, but that only gates CLI-side image ingestion — nothing filters images coming back from MCP tool results.

Worse symptom: compaction cannot recover. Every later request — including the automatic full_compaction request — re-sends the image and gets the same 400, so the session is a permanent dead-end with no in-product recovery. The only fix was hand-editing the session's wire.jsonl to replace the image part with a text placeholder.

From the changelog, 0.23.5 added drop-and-retry recovery for unsupported image formats and 0.23.4 for HTTP 413, but a provider rejecting images because the model is text-only still bricks the session. Extending that recovery so image parts are stripped/replaced with a text marker whenever the resolved model lacks image_in — for all image sources including MCP tool results — would close this whole class. Related: #1082.

Happy to provide the full session log and the wire.jsonl excerpt around the failure if useful.

TheoDZzz avatar Aug 07 '26 12:08 TheoDZzz