Responses API ↔ Chat Completions translation bridge for Codex CLI
Project description
codex-relay
A lightweight Rust proxy that translates the OpenAI Responses API (used by Codex CLI) into the Chat Completions API, letting Codex work with any OpenAI-compatible provider — DeepSeek, Kimi, Qwen, Mistral, Groq, xAI, OpenRouter, and more.
Why
Codex CLI speaks the OpenAI Responses API, which is an OpenAI-proprietary stateful protocol. Every other provider exposes the standard Chat Completions API. codex-relay sits between Codex and your chosen provider, translating on the fly — no code changes to Codex required.
Install
# From PyPI — prebuilt binary for your platform
pip install codex-relay
# From crates.io
cargo install codex-relay
Quick start
1. Start the relay
CODEX_RELAY_UPSTREAM=https://api.deepseek.com/v1 \
CODEX_RELAY_API_KEY=$DEEPSEEK_API_KEY \
CODEX_RELAY_PORT=4446 \
codex-relay
2. Configure Codex (~/.codex/config.toml)
model = "deepseek-chat"
model_provider = "deepseek-relay"
[model_providers.deepseek-relay]
name = "DeepSeek"
api_base_url = "http://127.0.0.1:4446/v1"
env_key = "DEEPSEEK_API_KEY"
3. Use Codex normally — it routes through the relay transparently.
Supported providers
| Provider | Base URL | Suggested port |
|---|---|---|
| DeepSeek | https://api.deepseek.com/v1 |
4446 |
| Kimi (Moonshot) | https://api.moonshot.cn/v1 |
4447 |
| Qwen | https://dashscope.aliyuncs.com/compatible-mode/v1 |
4448 |
| Mistral | https://api.mistral.ai/v1 |
4449 |
| Groq | https://api.groq.com/openai/v1 |
4450 |
| xAI | https://api.x.ai/v1 |
4451 |
| OpenRouter | https://openrouter.ai/api/v1 |
4452 |
Any OpenAI-compatible endpoint works.
Features
- Streaming — full SSE streaming with correct event sequencing
- Tool calls — accumulates streaming deltas and emits structured function_call items
- Parallel tool calls — consecutive function_call input items merged into one assistant message
- Reasoning models — preserves
reasoning_contentacross turns (Kimi k2.6, DeepSeek-R1) - Model catalog — proxies
/v1/modelsfrom the upstream provider
Configuration
| Variable | Default | Description |
|---|---|---|
CODEX_RELAY_PORT |
4444 |
Port to listen on |
CODEX_RELAY_UPSTREAM |
https://openrouter.ai/api/v1 |
Upstream Chat Completions base URL |
CODEX_RELAY_API_KEY |
(empty) | API key forwarded to upstream |
RUST_LOG |
codex_relay=info |
Log verbosity |
Python API
from codex_relay import start
proc = start(port=4446, upstream="https://api.deepseek.com/v1", api_key="sk-...")
# ... use Codex ...
proc.terminate()
Testing
Two layers — offline tests pin behavior against captured Codex wire-shape; live tests pin behavior against real provider APIs.
Offline (always green, default cargo test)
Replays Codex CLI fixtures through the translation layer and asserts
role/tool/reasoning behavior. Each fixture pins a Codex CLI version under
tests/fixtures/codex_<major>_<minor>_<patch>/.
cargo test
Live (gated on provider API key, #[ignore] by default)
Spawns the relay binary on a random port, points it at the real provider, and
exercises /v1/models, blocking + streaming, tool calls, and (for thinking
models) the reasoning_content round-trip via an in-process recording proxy.
DEEPSEEK_API_KEY=sk-... cargo test --test compat_deepseek_live -- --ignored --test-threads=1
Regenerating fixtures after a Codex upgrade
- Add a debug dump to the relay (write
bodybytes fromhandle_responsesto a file before parsing). - Run a real
codex execagainst it; copyinbound_*.jsonto a newtests/fixtures/codex_<major>_<minor>_<patch>/folder. - Trim each payload down to the smallest one that exercises the feature you want to lock in.
- Add a row to
tests/fixtures/VERSIONS.mdand a test pointing at the new directory.
The old fixture directory stays as a regression net so the relay keeps working with the previous Codex CLI release.
Disclaimer
This project is not affiliated with, endorsed by, or sponsored by OpenAI. "Codex" refers to OpenAI Codex CLI, an open-source project licensed under Apache-2.0. codex-relay is an independent, community-built translation proxy.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codex_relay-0.1.6-py3-none-win_amd64.whl.
File metadata
- Download URL: codex_relay-0.1.6-py3-none-win_amd64.whl
- Upload date:
- Size: 2.6 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92a0d0ef5a255d3ec1565be123956f98a95d8431a0276f00d5db26a2e773aefb
|
|
| MD5 |
e1be1b205d976f732b157906fcce6639
|
|
| BLAKE2b-256 |
e290d25dda22d8d00f194ce634da1c5fecf0a5681d09ff622a9e91d3f0274438
|
Provenance
The following attestation bundles were made for codex_relay-0.1.6-py3-none-win_amd64.whl:
Publisher:
publish.yml on MetaFARS/codex-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_relay-0.1.6-py3-none-win_amd64.whl -
Subject digest:
92a0d0ef5a255d3ec1565be123956f98a95d8431a0276f00d5db26a2e773aefb - Sigstore transparency entry: 1461923964
- Sigstore integration time:
-
Permalink:
MetaFARS/codex-relay@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/MetaFARS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_relay-0.1.6-py3-none-manylinux_2_28_x86_64.whl.
File metadata
- Download URL: codex_relay-0.1.6-py3-none-manylinux_2_28_x86_64.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eadac59064ecdf65456c4b3f34e68332c2e93ac21ebb77b4479523db982c4462
|
|
| MD5 |
2395e6e3af135706c7ce23909c971412
|
|
| BLAKE2b-256 |
80f987d1e46b11471863c7dc0e0d75072067c85619e1f0e563991aa8d75c7252
|
Provenance
The following attestation bundles were made for codex_relay-0.1.6-py3-none-manylinux_2_28_x86_64.whl:
Publisher:
publish.yml on MetaFARS/codex-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_relay-0.1.6-py3-none-manylinux_2_28_x86_64.whl -
Subject digest:
eadac59064ecdf65456c4b3f34e68332c2e93ac21ebb77b4479523db982c4462 - Sigstore transparency entry: 1461923919
- Sigstore integration time:
-
Permalink:
MetaFARS/codex-relay@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/MetaFARS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_relay-0.1.6-py3-none-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: codex_relay-0.1.6-py3-none-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.0 MB
- Tags: Python 3, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6e4495f2a553ba5c563d47e02a0c7d3656bdfc8776ebdf4ebc774314a78aec2d
|
|
| MD5 |
7949328c8cc5c8ea92e99effbed4561d
|
|
| BLAKE2b-256 |
cdcfc4ab2cdad22ee966ae15577fb835bf02cf4e8076902e045b1c26af6ac878
|
Provenance
The following attestation bundles were made for codex_relay-0.1.6-py3-none-manylinux_2_28_aarch64.whl:
Publisher:
publish.yml on MetaFARS/codex-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_relay-0.1.6-py3-none-manylinux_2_28_aarch64.whl -
Subject digest:
6e4495f2a553ba5c563d47e02a0c7d3656bdfc8776ebdf4ebc774314a78aec2d - Sigstore transparency entry: 1461924040
- Sigstore integration time:
-
Permalink:
MetaFARS/codex-relay@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/MetaFARS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_relay-0.1.6-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: codex_relay-0.1.6-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.8 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2470caff570620972b4a670b1677a7f220abf899fa5c33ef3386ade4e087049
|
|
| MD5 |
ef2522ed384a3b5dcc313f24bbfd1c76
|
|
| BLAKE2b-256 |
5ba36e2b2ef281c94cc8f34a317bbd269a67ffff2b34f252f0feef48e205fe98
|
Provenance
The following attestation bundles were made for codex_relay-0.1.6-py3-none-macosx_11_0_arm64.whl:
Publisher:
publish.yml on MetaFARS/codex-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_relay-0.1.6-py3-none-macosx_11_0_arm64.whl -
Subject digest:
f2470caff570620972b4a670b1677a7f220abf899fa5c33ef3386ade4e087049 - Sigstore transparency entry: 1461923870
- Sigstore integration time:
-
Permalink:
MetaFARS/codex-relay@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/MetaFARS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file codex_relay-0.1.6-py3-none-macosx_10_12_x86_64.whl.
File metadata
- Download URL: codex_relay-0.1.6-py3-none-macosx_10_12_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: Python 3, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
294931111fc27cec175b5add1fc749451172f524b068aa9cd83b7acb7f9e95cb
|
|
| MD5 |
7dfee6bf47c077c4b903d8b50108182e
|
|
| BLAKE2b-256 |
28e24961bb2de234f8a8ac830245fbcde677cd656cc0829f4a64ebf145e2d2f9
|
Provenance
The following attestation bundles were made for codex_relay-0.1.6-py3-none-macosx_10_12_x86_64.whl:
Publisher:
publish.yml on MetaFARS/codex-relay
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
codex_relay-0.1.6-py3-none-macosx_10_12_x86_64.whl -
Subject digest:
294931111fc27cec175b5add1fc749451172f524b068aa9cd83b7acb7f9e95cb - Sigstore transparency entry: 1461924000
- Sigstore integration time:
-
Permalink:
MetaFARS/codex-relay@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/MetaFARS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e98d797633cd078b88f3ecf8d980bb0cb498ede8 -
Trigger Event:
push
-
Statement type: