Relaying Claude Code (or Codex via Responses) to a Chat Completions upstream that checks the tool exchange strictly — Kimi answers 400 "tool_call_id is not found" — got stuck once a history tripped it, since every retry resent it. buildChat now puts a turn's tool results ahead of its own text and images, and pairToolMessages mends the built messages for every Chat upstream (Zed's xAI path included; Chat→Chat passthrough never reaches it): an assistant's tool messages go in its calls' order; a second answer to a call is dropped, the first standing; a result answering no pending call (already answered and closed, compacted away, never sent, or an empty id) becomes user text — joined to the user message just before it — as orphanedToolOutputs does on the Responses path, so no call is made up and no id is used twice; an unanswered call gets a synthetic "unavailable: the turn was interrupted" result; an assistant message with nothing in it is dropped only inside a pending exchange, and passes through outside one. A well-formed exchange is built byte-identical to before. chat_tool_pairing_test.go (order, gathering across user messages, orphan, late result, duplicate, empty id, unanswered call, thinking-only inside and outside an exchange, a session-shaped fixture, a clean exchange; checked for Kimi's adjacency and for ids used once) is new — 9 of its 11 tests fail without the change; TestTextOnlyModelOmitsToolImages' responses-to-chat case now expects the orphaned output as user text without its id. go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME and go test -race ./internal/gateway pass. (#554)
A model's image input is taken from models.dev and the provider's own list, and a group's from its members: only a model known to be text-only is refused an image — one whose support is unknown still gets it, and Codex, OpenCode and Pi are told which models take images. An image the user attaches for a text-only model answers 400 in the client's own format before the upstream is asked; an image earlier in the chat, or one a tool returned (Claude Code's Read, Codex's view_image, a Chat tool message), becomes a short text note, so a chat that met a picture carries on after a switch to a text-only model. Thanks @herrkaefer.