Codex
Codex를 DeepSeek API에 연결하기
Connect Codex to the DeepSeek API through an OpenAI-compatible endpoint. Add your API key, pick a model via Moon Bridge, and run Codex with free or low-cost DeepSeek credits. Codex uses the OpenAI Responses API, so this guide uses Moon Bridge as the forwarding layer.
1. Install Requirements
npm install -g @openai/codex
Verify the installation:
codex --version
go version
2. Get a DeepSeek API Key
Go to the DeepSeek Platform, create an API key, and copy it.
3. Configure Moon Bridge
Clone Moon Bridge and create a local config file:
git clone https://github.com/ZhiYi-R/moon-bridge.git
cd moon-bridge
Create config.yml and set your DeepSeek API key:
mode: "Transform"
server:
addr: "127.0.0.1:38440"
models:
deepseek-v4-pro:
context_window: 1000000
max_output_tokens: 384000
default_reasoning_level: "high"
supported_reasoning_levels:
- effort: "high"
description: "High reasoning effort"
- effort: "xhigh"
description: "Extra high reasoning effort"
supports_reasoning_summaries: true
default_reasoning_summary: "auto"
extensions:
deepseek_v4:
enabled: true
deepseek-v4-flash:
context_window: 1000000
max_output_tokens: 384000
default_reasoning_level: "high"
supported_reasoning_levels:
- effort: "high"
description: "High reasoning effort"
- effort: "xhigh"
description: "Extra high reasoning effort"
supports_reasoning_summaries: true
default_reasoning_summary: "auto"
extensions:
deepseek_v4:
enabled: true
providers:
deepseek:
base_url: "https://api.deepseek.com/anthropic"
api_key: "sk-your-deepseek-api-key"
offers:
- model: deepseek-v4-pro
- model: deepseek-v4-flash
routes:
moonbridge:
model: deepseek-v4-pro
provider: deepseek
defaults:
model: moonbridge
max_tokens: 65536
This minimal config uses the current Moon Bridge configuration structure and enables DeepSeek V4 Pro / Flash, Codex model metadata, and the DeepSeek V4 compatibility extension. For image input, Web Search, or multi-provider routing, extend it with the options from Moon Bridge's config.example.yml.
4. Start Moon Bridge
go run ./cmd/moonbridge --config config.yml
Keep this terminal open. By default Moon Bridge listens on 127.0.0.1:38440 and exposes an OpenAI Responses-compatible endpoint at:
http://127.0.0.1:38440/v1/responses
5. Generate Codex Configuration
In another terminal, run the following commands from the Moon Bridge directory to write Codex's config.toml and models_catalog.json into CODEX_HOME_DIR.
If you already have a Codex config, back up your current config.toml first:
macOS / Linux:
CODEX_HOME_DIR="${CODEX_HOME:-$HOME/.codex}"
mkdir -p "$CODEX_HOME_DIR"
# Back up the current config.toml
cp "$CODEX_HOME_DIR/config.toml" "$CODEX_HOME_DIR/config.toml.bak" 2>/dev/null || true
# Create config.toml and models_catalog.json
MODEL="$(go run ./cmd/moonbridge --config config.yml --print-codex-model)"
go run ./cmd/moonbridge \
--config config.yml \
--print-codex-config "$MODEL" \
--codex-base-url "http://127.0.0.1:38440/v1" \
--codex-home "$CODEX_HOME_DIR" \
> "$CODEX_HOME_DIR/config.toml"
Windows PowerShell:
$CODEX_HOME_DIR = if ($env:CODEX_HOME) { $env:CODEX_HOME } else { "$HOME\.codex" }
New-Item -ItemType Directory -Force -Path $CODEX_HOME_DIR | Out-Null
# Back up the current config.toml
if (Test-Path "$CODEX_HOME_DIR\config.toml") {
Copy-Item "$CODEX_HOME_DIR\config.toml" "$CODEX_HOME_DIR\config.toml.bak" -Force
}
# Create config.toml and models_catalog.json
$MODEL = go run ./cmd/moonbridge --config config.yml --print-codex-model
go run ./cmd/moonbridge `
--config config.yml `
--print-codex-config "$MODEL" `
--codex-base-url "http://127.0.0.1:38440/v1" `
--codex-home "$CODEX_HOME_DIR" `
| Set-Content -Path "$CODEX_HOME_DIR\config.toml"
This creates:
config.toml: Codex provider configuration usingwire_api = "responses".models_catalog.json: model capability metadata for Codex, including context window, reasoning levels, and tool support.
Before generating the files, you can check the default Codex model read by Moon Bridge:
go run ./cmd/moonbridge --config config.yml --print-codex-model
# moonbridge
6. Start Codex
Enter the project you want to work on and launch Codex:
cd /path/to/my-project
codex
Codex now sends OpenAI Responses requests to Moon Bridge, and Moon Bridge routes them to DeepSeek V4.
Codex App can use the same generated Codex configuration.
One-Command Launcher
Moon Bridge provides a helper script for Codex CLI that can build and start the proxy, generate the Codex config, and launch Codex in one command:
./scripts/start_codex_with_moonbridge.sh --project-directory /path/to/my-project
Windows PowerShell users can use:
.\scripts\start_codex_with_moonbridge.ps1 -ProjectDirectory C:\path\to\my-project
Verify
Check the available models:
curl http://127.0.0.1:38440/v1/models
Send a direct Responses test request:
curl http://127.0.0.1:38440/v1/responses \
-H "Content-Type: application/json" \
-d '{
"model": "moonbridge",
"input": "Say hello in one short sentence.",
"max_output_tokens": 1024
}'
After Codex sends a message, the Moon Bridge terminal should show a POST /v1/responses log line.
You can also verify that the reasoning level is passed through:
curl http://127.0.0.1:38440/v1/responses \
-H "Content-Type: application/json" \
-d '{
"model": "moonbridge",
"input": "Explain what Moon Bridge does in one sentence.",
"reasoning": {"effort": "high"},
"max_output_tokens": 1024
}'
DeepSeek V4 Flash Responses API for Codex
Codex does not call OpenAI Chat Completions. It sends OpenAI Responses requests to POST /v1/responses. DeepSeek natively exposes Chat Completions and Anthropic Messages, but not Responses, so pointing Codex directly at https://api.deepseek.com/v1 returns a 404 or an incompatible response.
Moon Bridge fixes that protocol mismatch:
Codex
→ OpenAI Responses (/v1/responses)
→ Moon Bridge
→ Anthropic Messages
→ DeepSeek V4 Flash or Pro
Use this Codex provider configuration:
model = "moonbridge"
model_provider = "moonbridge"
[model_providers.moonbridge]
name = "Moon Bridge"
base_url = "http://127.0.0.1:38440/v1"
wire_api = "responses"
The important field is wire_api = "responses". Do not replace it with chat, and do not set base_url to the upstream DeepSeek URL. Codex talks to the local bridge; the bridge talks to DeepSeek.
Codex with DeepSeek multi-agent support
Multi-agent behavior belongs to Codex, not to the model API. Using DeepSeek does not automatically disable subagents, but the bridge must preserve Responses tool calls and the generated model catalog must advertise tool support.
Current Codex releases enable multi-agent tools by default. To make the setting explicit, add this to ~/.codex/config.toml:
[agents]
enabled = true
max_concurrent_threads_per_session = 3
default_subagent_model = "moonbridge"
default_subagent_reasoning_effort = "high"
Restart Codex, then verify:
- Run
/statusand confirm the active provider is Moon Bridge. - Ask Codex to delegate two independent read-only investigations.
- Use
/agentor/subagentsto inspect spawned threads.
If Codex works but cannot create subagents:
- Upgrade Codex; old builds may not include stable multi-agent tools.
- Regenerate
models_catalog.jsonafter changing the Moon Bridge model configuration. - Check that
agents.enabledis not set tofalsein a project-level config. - Reduce concurrency if the upstream API rate limit rejects parallel requests.
Multi-agent runs multiply token use because each subagent has its own context. Use V4 Flash for explorers and repetitive checks, then keep V4 Pro for the primary agent or difficult review steps.
Codex DeepSeek Thinking Max
Codex names its highest commonly exposed reasoning level xhigh; DeepSeek product copy may describe the equivalent high-budget mode as Max. In Codex configuration, use xhigh, not the literal string max.
Moon Bridge must list xhigh for the model:
models:
deepseek-v4-pro:
default_reasoning_level: "xhigh"
supported_reasoning_levels:
- effort: "high"
description: "High reasoning effort"
- effort: "xhigh"
description: "Maximum reasoning effort"
extensions:
deepseek_v4:
enabled: true
You can also set the Codex default:
model_reasoning_effort = "xhigh"
Use xhigh for hard debugging, architecture, or long-horizon tasks. Keep high for routine work: maximum reasoning increases latency and output-token usage, and it cannot compensate for an underspecified prompt.
Codex DeepSeek FAQ
Why does Codex return 404 when connected directly to DeepSeek?
Codex sends requests to /v1/responses, while DeepSeek does not provide a native OpenAI Responses endpoint. Point Codex at Moon Bridge and let the bridge translate Responses into DeepSeek's Anthropic-compatible format.
Can Codex use multiple agents with DeepSeek?
Yes, provided you use a current Codex release and a bridge that preserves Responses tool calls. Enable [agents], regenerate the model catalog, and ensure the upstream API can accept parallel requests.
How do I enable DeepSeek Thinking Max in Codex?
Use model_reasoning_effort = "xhigh" in Codex and advertise xhigh in the Moon Bridge model configuration. Codex uses the name xhigh; entering max directly may not be recognized.
Should Codex subagents use V4 Flash or V4 Pro?
Use V4 Flash for parallel exploration, search, and repetitive checks. Use V4 Pro for the main planning thread, difficult implementation, or final review. This keeps multi-agent costs under control.
Troubleshooting
connection refused: Moon Bridge is not running, orserver.addrinconfig.ymluses a different port.- Codex cannot see the model: rerun step 5; Codex needs
models_catalog.jsoninCODEX_HOME. - Config loading fails with
field provider not found: you are using the oldprovider.providersformat. The current format uses top-levelproviders,models,routes, anddefaults. 401or authentication errors: check the DeepSeek API key inconfig.yml.402or payment errors: check your DeepSeek Platform balance.- Image input fails: if you enabled the Visual extension, configure a separate visual provider (e.g., Kimi) with its API key. You can configure that provider, or remove
visual.enabled: trueto disable the Visual extension.