[PR #9205] feat(codex): bring ChatGPT support into parity with Codex CLI #13028

Closed
opened 2026-02-16 18:17:54 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/9205

State: closed
Merged: No


What does this PR do?

  • Brings OpenCode’s ChatGPT/Codex integration into parity with Codex CLI’s behavior.
  • Switches ChatGPT Codex calls to the chatgpt.com/backend-api/codex /v1 flow, including Codex-specific headers and per-turn state handling via x-codex-turn-state (capture from responses and send on subsequent turns).
  • Ensures we don’t use Responses “server-owned conversation state” by default (i.e. store: false / no required previous_response_id flow), matching Codex CLI’s approach.
  • Adds/finishes Codex remote compaction via /v1/responses/compact (includes required instructions, fixes content part types like output_text for assistant).
  • Implements Responses streaming parity:
    • SSE is the default transport (Codex CLI default).
    • WebSocket streaming is available as an opt-in (OPENCODE_CODEX_WEBSOCKET=1), with a one-time SSE bootstrap to capture x-codex-turn-state since Bun’s WebSocket API doesn’t expose handshake headers.
  • Adds request-body zstd compression as an opt-in (OPENCODE_CODEX_REQUEST_COMPRESSION=1) to match Codex CLI’s compression gating behavior.
  • Adds tests around OpenAI/Codex conversation state behavior and updates typecheck to keep CI/pre-push green.

New/used env flags:

  • OPENCODE_CODEX_WEBSOCKET=1 (opt-in WebSocket streaming; SSE remains default)
  • OPENCODE_CODEX_SSE=1 (back-compat override to force SSE)
  • OPENCODE_CODEX_REQUEST_COMPRESSION=1|true (opt-in request compression)
  • OPENCODE_CODEX_BETA_FEATURES= (sets x-codex-beta-features)

How did you verify your code works?

  • Ran typechecking: bun turbo typecheck
  • Ran unit tests: cd packages/opencode && bun test
  • Manual smoke testing:
    • Authenticated with ChatGPT/Codex and verified multi-turn chat continuity (turn-state preserved across turns).
    • Verified streaming output over default SSE and opt-in WebSocket transport.
    • Exercised remote compact (/responses/compact) end-to-end and validated it succeeds and produces usable summaries.
    • Verified request compression behavior by toggling OPENCODE_CODEX_REQUEST_COMPRESSION on/off.

Closes https://github.com/anomalyco/opencode/issues/5200 & https://github.com/anomalyco/opencode/issues/7705

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/9205 **State:** closed **Merged:** No --- ### What does this PR do? - Brings OpenCode’s ChatGPT/Codex integration into parity with Codex CLI’s behavior. - Switches ChatGPT Codex calls to the chatgpt.com/backend-api/codex /v1 flow, including Codex-specific headers and per-turn state handling via x-codex-turn-state (capture from responses and send on subsequent turns). - Ensures we don’t use Responses “server-owned conversation state” by default (i.e. store: false / no required previous_response_id flow), matching Codex CLI’s approach. - Adds/finishes Codex remote compaction via /v1/responses/compact (includes required instructions, fixes content part types like output_text for assistant). - Implements Responses streaming parity: - SSE is the default transport (Codex CLI default). - WebSocket streaming is available as an opt-in (OPENCODE_CODEX_WEBSOCKET=1), with a one-time SSE bootstrap to capture x-codex-turn-state since Bun’s WebSocket API doesn’t expose handshake headers. - Adds request-body zstd compression as an opt-in (OPENCODE_CODEX_REQUEST_COMPRESSION=1) to match Codex CLI’s compression gating behavior. - Adds tests around OpenAI/Codex conversation state behavior and updates typecheck to keep CI/pre-push green. New/used env flags: - OPENCODE_CODEX_WEBSOCKET=1 (opt-in WebSocket streaming; SSE remains default) - OPENCODE_CODEX_SSE=1 (back-compat override to force SSE) - OPENCODE_CODEX_REQUEST_COMPRESSION=1|true (opt-in request compression) - OPENCODE_CODEX_BETA_FEATURES=<csv> (sets x-codex-beta-features) ### How did you verify your code works? - Ran typechecking: bun turbo typecheck - Ran unit tests: cd packages/opencode && bun test - Manual smoke testing: - Authenticated with ChatGPT/Codex and verified multi-turn chat continuity (turn-state preserved across turns). - Verified streaming output over default SSE and opt-in WebSocket transport. - Exercised remote compact (/responses/compact) end-to-end and validated it succeeds and produces usable summaries. - Verified request compression behavior by toggling OPENCODE_CODEX_REQUEST_COMPRESSION on/off. Closes https://github.com/anomalyco/opencode/issues/5200 & https://github.com/anomalyco/opencode/issues/7705
yindo added the pull-request label 2026-02-16 18:17:54 -05:00
yindo closed this issue 2026-02-16 18:17:54 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#13028