Commit Graph
2 Commits
Author SHA1 Message Date
yetone 3ec45e7155 gateway: a json_schema an upstream turns away is asked for as a JSON object, the schema in the system prompt, before the format is told in words alone (#2126)
klarkxy's Codex on Xiaomi MiMo's Token Plan got back "text.format type
'json_schema' is not supported, only 'text' and 'json_object' are
supported" and the turn ended there. Codex's /responses reaches the
upstream by passthrough when the protocols match, and passthrough never
looked at a format refusal; the translated path did, but only by moving
the whole format into the system prompt, which drops the object
requirement the vendor would have kept.

Now, on either path, a json_schema the upstream turns away is asked
again as {"type":"json_object"} with the schema appended to the system
prompt (Responses instructions, Chat's first system/developer message,
Anthropic system). If json_object is turned away too, the format field
goes and only the words stay. Each step is remembered per provider,
model and protocol once a request with it is taken, so later turns go
out already rewritten. Anthropic's output_config.format has no object
mode, so it goes straight to words. DeepSeek, which takes json_object
only, gains the same middle step on the translated path.

Run:
- format_refused_test.go, new:
  - TestPassthroughSchemaRefusedAskedAsObject replays the reporter's
    exact error and probe body through /backend-api/codex/responses.
    It covers object taken (2 asks, then json_object) and object refused
    too (3 asks, then no format). Turn 2 is checked to take 1 ask, the
    instructions to keep "You are Codex." first, and the input to be
    unchanged.
  - TestPassthroughFormatRefusedChatAndAnthropic.
- TestRefusedFormatToldInWords was rewritten for both outcomes on the
  translated path.
- Break check: with the old gateway.go, the passthrough test gets back
  the reporter's exact error.
- gofmt -l is clean. go vet passes for darwin, GOOS=linux -tags nogui
  and GOOS=windows. go test ./internal/gateway/ -count=1 is ok (1017s).

Not tried: a real Xiaomi MiMo key (none here; the error envelope is
assumed to be OpenAI's), and Gemini passthrough, which has no rewrite.
2026-10-14 16:42:56 +08:00
yetone 40c5b92a93 gateway: structured output crosses every translation: a Responses text.format or a Chat response_format reaches a Chat, Responses, Messages or Gemini upstream in its own words (frostming on Discord: responses.parse through magpie to OpenRouter came back as plain text)
The IR held a schema only from Anthropic's output_config.format, and only
Messages (and Claude Code's --json-schema) were asked for one. A Responses
request to a provider magpie speaks Chat or Messages to (OpenRouter has no
Responses URL) lost text.format; a Chat request translated to Responses or
Messages lost response_format; an Anthropic schema translated to Chat or
Responses was lost too.

Format (format.go) now carries json_schema (name, description, schema,
strict) or json_object from Responses, Chat, Anthropic and Gemini, and each
builder asks for it in its upstream's field. Where a target can't say it
(json_object on Messages or Claude Code; the vendor bridges Cursor, Devin,
Kiro, Qoder, Command Code, Zed) it is told in the system prompt. An upstream
answering 400/422 naming the field (DeepSeek's "This response_format type is
unavailable now") is asked again with it told in words, and so from then on.
Relayed requests are unchanged.
2026-10-08 10:37:02 +08:00