Repository navigation
Description
Area
Proxy and routing
What are you trying to accomplish?
Run Codex CLI (ChatGPT auth) through OpenCodex over a metered / long-distance egress (self-hosted relay) and keep the bandwidth cost of long agent sessions under control.
Codex is stateless against the ChatGPT backend by design — the backend enforces store: false (a store: true request gets 400 ... store must be false), and OpenCodex itself strips previous_response_id and other stateful params (stripPreviousResponseId / stripStatefulResponsesParams in src/adapters/openai-responses/canonical-forward.ts). The consequence: every turn re-sends the full conversation history — including reasoning items — and that history grows to hundreds of thousands of tokens before auto-compact (model_auto_compact_token_limit defaults are large; users run up to ~950k). Today all of that JSON crosses the wire to the upstream uncompressed.
What prevents this today?
- OpenCodex already decodes compressed inbound bodies (
src/server/request-decompress.ts, added in v2.6.28: "decode zstd/gzip/deflate request bodies on /v1/responses", covering codex'senable_request_compressionzstd), but the forward/outbound path sends identity-encoded bodies. A grep ofsrc/shows the only outbound compression today is the Devin adapter (src/adapters/devin/cloud-direct/wire.ts:165,zlib.gzipSync). - Measured on a real single-user setup (codex-cli 0.162.0 behind OpenCodex): >40 GiB/day of upload, >90% of it
POST .../responsesbodies tochatgpt.com, with ~1:4 download:upload asymmetry (download is incremental streamed output; upload is the full history every turn). On a metered relay this is the dominant cost of running Codex through the proxy.
What should OpenCodex do?
Re-compress outbound request bodies on Responses-compatible destinations: when the serialized body exceeds a small threshold (e.g. 1 KiB), gzip (or zstd) it and set Content-Encoding accordingly before dispatch.
Evidence that upstreams accept compressed request bodies:
- Codex CLI itself sends
content-encoding: zstdwhen talking directly to the ChatGPT codex backend (enable_request_compression, default ON for the built-inopenaiprovider with codex auth) — so the ChatGPT backend natively accepts compressed request bodies. - Verified against
https://chatgpt.com/backend-api/codex/responseswith a ChatGPT-auth token: the same request sent identity-encoded and gzip-encoded returns the identical application-layer 400 (The '...' model is not supported when using Codex with a ChatGPT account.) — i.e. the gzipped body was transparently decoded and parsed, no HTTP-layer rejection.
Example usage or interface
Config-gated initially:
ocx config set forwarding.request_compression zstd # auto | off | gzip | zstd, default: autoOn the wire:
before: POST /backend-api/codex/responses Content-Length: 3145728 (identity)
after: POST /backend-api/codex/responses Content-Encoding: gzip (~0.4–0.6 MB)
Conversation-history JSON compresses ~5–10× (repetitive structure, code/English text), so this should cut the forward-path upload by roughly that factor for every user, not just metered-egress setups.
Implementation notes:
- The Devin adapter already has the exact pattern (
zlib.gzipSyncincloud-direct/wire.ts); the missing piece is applying it on the openai-responses forward transport. - Guard against double-compression when
Content-Encodingis already set (codex's own HTTP client makes the same check: "request compression was requested but content-encoding is already set"). - Skip bodies under threshold; only apply where the transport is a plain HTTP(S) dispatch with a full in-memory body (Responses POSTs are whole-body, not chunked, so this fits).
Alternatives or workarounds
- True incremental continuation (
previous_response_id+store: true): impossible against the ChatGPT codex backend (rejectsstore: true); againstapi.openai.comwith API keys it would work but changes the billing model, which is exactly why most users are on ChatGPT-auth routing in the first place. - Client-side mitigation only (lower
model_auto_compact_token_limit, lower reasoning effort, shorter sessions): reduces the numerator but does not remove the per-turn full re-upload. - Locally patching the forward transport: possible, but it fights the auto-updater; upstream support is the sustainable path.
Additional context
- Same gap exists in the Claude Code ecosystem and is still an open feature request: [FEATURE] Compress API request bodies with gzip by default anthropics/claude-code#90457 ("Request bodies leave Claude Code identity-encoded. The API accepts gzip request bodies right now.").
- Related decode-side work in this repo: v2.6.28 release note ("decode zstd/gzip/deflate request bodies on /v1/responses"), [Bug]: Decode content-coded responses on the pinned direct provider transport #5111 / fix(transport): decode content-coded responses on the pinned direct route #5126 (content-coded response decoding), fix(transport): match freeform streaming to its completion grammar and decode SOCKS5 content-codings #5070 (SOCKS5 content-codings) — all decode direction; this proposal is the missing encode direction on the forward path.
- Environment: opencodex 2.81.0, codex-cli 0.162.0, macOS arm64, egress via self-hosted relay where bandwidth is the scarce resource.
- I'm happy to test a PR branch on my metered setup and report before/after byte counts from the relay.
Checks
- I searched existing issues and documentation.
- This request describes a concrete OpenCodex workflow rather than merely naming a desired technology.
- I removed secrets and personal data.
Activity
feat(responses): opt-in compression of outbound ChatGPT Responses req…
lidge-jun commentedon Oct 17, 2026
Implemented on dev by #7285 (merge commit cb6a9a7): opt-in
upstreamRequestCompression(gzip or zstd) compresses native ChatGPT Responses/compact HTTP request bodies at the final send; default off.