feat: re-add Chat Completions API support for non-OpenAI providers

Resolved 💬 1 comment Opened Jul 4, 2026 by moclaw-dev Closed Jul 4, 2026

Problem

Codex CLI currently only supports the OpenAI Responses API (/v1/responses). The Chat Completions API (/v1/chat/completions) support was removed in commit d2394a249 (Feb 2026, #10157).

This means Codex cannot be used with LLM providers that only support the Chat Completions API format (e.g., many self-hosted models, older proxy servers, and non-OpenAI providers).

Proposed Solution

Re-add Chat Completions API support with an isolation-first approach:

  1. Add WireApi::Chat variant back to the WireApi enum
  2. Gate behind a feature flag (#[cfg(feature = "chat-completions")]) so existing code paths are untouched when not enabled
  3. Restore deleted modules from git history:
  • codex-rs/codex-api/src/sse/chat.rs (717 lines — SSE streaming parser)
  • codex-rs/codex-api/src/requests/chat.rs (494 lines — request builder)
  • codex-rs/codex-api/src/endpoint/chat.rs (282 lines — ChatClient endpoint)
  • Test files (~800 lines)
  1. Adapt restored code to handle new ResponseItem variants added since removal (ToolSearchCall, AgentMessage, etc.)

Configuration

# ~/.codex/config.toml
model_provider = "my-provider"

[model_providers.my-provider]
name = "My LLM"
base_url = "https://api.example.com/v1"
env_key = "MY_API_KEY"
wire_api = "chat"  # Use Chat Completions API

Scope of Changes

Minimal modifications to existing files (~20 lines):

  • model-provider-info/src/lib.rs — Add Chat variant to WireApi enum
  • core/src/client.rs — Add WireApi::Chat match arm with #[cfg] gate
  • config/src/thread_config/remote.rs — Proto mapping for Chat
  • core/config.schema.json — Allow "chat" value

New/restored files (~2000 lines):

  • SSE parser, request builder, ChatClient endpoint, tests

References

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗