Problem
The api-proxy injectStreamOptions() function in containers/api-proxy/body-transform.js is injecting stream_options: { include_usage: true } into OpenAI Responses API (/responses) requests. The OpenAI Responses API does not support this parameter and rejects the request with:
{
"error": {
"message": "Unknown parameter: 'stream_options.include_usage'.",
"type": "invalid_request_error",
"param": "stream_options.include_usage",
"code": "unknown_parameter"
}
}
This causes Codex CLI to crash immediately (exit code 1, duration=0s) on every attempt, making all Codex workflows non-functional when using the api-proxy.
Evidence
From CI run 26415291484:
Turn error: "Unknown parameter: 'stream_options.include_usage'"
[codex-harness] attempt 1: process closed exitCode=1 duration=0s stderr=227762B
All 4 retry attempts fail identically.
Root Cause
body-transform.js:148 has a guard to skip Responses API paths:
if (/^\/(?:v\d+\/)?responses(?:\/|$)/.test(pathOnly)) return null;
However, this regex requires a leading /. The Codex client (v0.133.0) appears to send requests where req.url does not match the expected pattern — either because:
- The path arrives without a leading
/ (Codex logs show api.path="responses")
- The proxy routes requests in a way that
req.url at the injection point differs from the final upstream path
Proposed Solution
-
Make the regex more permissive — handle paths with or without leading slash:
if (/^(?:\/)?(?:v\d+\/)?responses(?:\/|$)/.test(pathOnly)) return null;
-
Also check the parsed body for Responses API request shape (presence of input field, absence of messages field) as a secondary guard.
-
For token usage tracking on the Responses API: The Responses API automatically includes usage in the response.completed event during streaming and in the response body for non-streaming. The token tracker should parse usage from response.completed events rather than relying on stream_options.include_usage. This is important for billing/OTEL — we need accurate token counts for all OpenAI APIs including Responses.
Impact
Files
containers/api-proxy/body-transform.js:141-162 — injectStreamOptions() function
containers/api-proxy/proxy-request.js:690-696 — injection call site
containers/api-proxy/body-transform.test.js:13-18 — tests (need case without leading slash)
Problem
The api-proxy
injectStreamOptions()function incontainers/api-proxy/body-transform.jsis injectingstream_options: { include_usage: true }into OpenAI Responses API (/responses) requests. The OpenAI Responses API does not support this parameter and rejects the request with:{ "error": { "message": "Unknown parameter: 'stream_options.include_usage'.", "type": "invalid_request_error", "param": "stream_options.include_usage", "code": "unknown_parameter" } }This causes Codex CLI to crash immediately (exit code 1, duration=0s) on every attempt, making all Codex workflows non-functional when using the api-proxy.
Evidence
From CI run 26415291484:
All 4 retry attempts fail identically.
Root Cause
body-transform.js:148has a guard to skip Responses API paths:However, this regex requires a leading
/. The Codex client (v0.133.0) appears to send requests wherereq.urldoes not match the expected pattern — either because:/(Codex logs showapi.path="responses")req.urlat the injection point differs from the final upstream pathProposed Solution
Make the regex more permissive — handle paths with or without leading slash:
Also check the parsed body for Responses API request shape (presence of
inputfield, absence ofmessagesfield) as a secondary guard.For token usage tracking on the Responses API: The Responses API automatically includes usage in the
response.completedevent during streaming and in the response body for non-streaming. The token tracker should parse usage fromresponse.completedevents rather than relying onstream_options.include_usage. This is important for billing/OTEL — we need accurate token counts for all OpenAI APIs including Responses.Impact
--enable-api-proxyFiles
containers/api-proxy/body-transform.js:141-162—injectStreamOptions()functioncontainers/api-proxy/proxy-request.js:690-696— injection call sitecontainers/api-proxy/body-transform.test.js:13-18— tests (need case without leading slash)