Skip to content

[Feature]: Compress outbound (forwarded) Responses request bodies — stop re-uploading full session history uncompressed #7247

Closed

Description

@Hylouis233

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's enable_request_compression zstd), but the forward/outbound path sends identity-encoded bodies. A grep of src/ 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 .../responses bodies to chatgpt.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:

  1. Codex CLI itself sends content-encoding: zstd when talking directly to the ChatGPT codex backend (enable_request_compression, default ON for the built-in openai provider with codex auth) — so the ChatGPT backend natively accepts compressed request bodies.
  2. Verified against https://chatgpt.com/backend-api/codex/responses with 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: auto

On 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.gzipSync in cloud-direct/wire.ts); the missing piece is applying it on the openai-responses forward transport.
  • Guard against double-compression when Content-Encoding is 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 (rejects store: true); against api.openai.com with 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

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

  1. added
    enhancement
    account-pool
    proxy
    on Oct 16, 2026
  2. lidge-jun commented on Oct 17, 2026

    @lidge-jun
    Owner

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    account-poolenhancementproxy

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions