-
Notifications
You must be signed in to change notification settings - Fork 72
fix: support json_schema response_format for chat completions#9
fix: support json_schema response_format for chat completions #9cheulyop wants to merge 1 commit into
Conversation
adambreen
commented
Apr 25, 2026
Thanks for putting this together. I independently hit the same compatibility gap from the OpenAI Python SDK chat.completions.parse(...) path.
Concrete downstream symptom:
- client sends
/v1/chat/completions - request includes
response_format: { "type": "json_schema", "json_schema": { ... "strict": true } } - Codex generates completion tokens
- the OpenAI-compatible response has empty/null
choices[0].message.content - clients relying on parsed structured output fail with "no parsed content"
I verified current HEAD (aa526920af322568968a30fe820b2b9d55545f8a) does not read or translate response_format in chat-completions.ts.
Your PR's generateObject(...) approach is the cleaner upstream-sized fix if it works consistently with the Codex provider. In a local self-hosted deployment I used a lower-level variant that translates chat response_format to Responses API text.format and returns the resulting JSON string as chat message.content. That path was needed for Honcho's deriver because the Python OpenAI SDK only needs valid JSON content back; client-side .parse() then populates .message.parsed.
I also have a working Vitest regression for the chat-to-Responses translation path: a structured chat completion maps to Codex Responses text format and returns populated chat content. I would be happy to contribute that test to this branch if useful.
One thing to consider before merge: the OpenAI SDK can send both:
response_format.type = "json_schema"response_format.type = "json_object"
If json_object remains unsupported, it would be useful to reject it explicitly or add a small pass-through test so callers do not get silent unstructured output.
The skeptical-maintainer question I would ask is: "Does this promise OpenAI-grade schema enforcement even if Codex does not support the exact same semantics?" I do not think it has to. The compatibility contract that matters for many clients is narrower: honor the structured-output request well enough to return JSON in message.content, or fail clearly rather than ignoring response_format.
Summary
Add
json_schemastructured output support to the/v1/chat/completionscompatibility path.Today the proxy supports
/v1/chat/completions, but it does not correctly honorresponse_format: { type: "json_schema", json_schema: ... }. That makes it hardto use the proxy with clients that expect OpenAI-style structured output on the
Chat Completions endpoint.
This change keeps the scope intentionally narrow:
json_schemaresponse_format handlingWhat changes
response_formattyping for chat completion requestsresponse_format.type === "json_schema"in the chat completions handlergenerateObject(...)response remains OpenAI-compatible on the
/v1/chat/completionssurfacejson_schemaresponse_format handlingFiles in scope
packages/openai-oauth/src/chat-completions.tspackages/openai-oauth/src/types.tspackages/openai-oauth/test/server.test.tsWhy this PR is separate
There was a related local change around SSE completed-response reconstruction,
but that is intentionally excluded from this PR so the review stays focused on
one compatibility gap: Chat Completions structured output.
Test plan
bun run test