Codex CLI is fast and pleasant to use, and it doesn’t have to run on OpenAI’s models. DeepSeek’s API is OpenAI-compatible, so Codex can use it as a backend at a fraction of the cost — once you set the provider up correctly. The one trap is that a base-URL swap alone won’t do it; Codex needs a real provider definition with the right wire protocol.
This is the complete, working config plus the gotcha that wastes everyone an hour. For the general approach across providers, see Codex CLI custom provider setup.
Step 1: Install Codex CLI and get a key
Install Codex CLI per its docs, then create a DeepSeek account, add a little credit, and generate an API key. On Windows the env-var handling is cleaner in WSL — see Codex CLI on Windows with WSL.
Step 2: Add DeepSeek to config.toml
Codex reads ~/.codex/config.toml (on Windows, C:\Users\YourName\.codex\config.toml). Add a DeepSeek provider and point Codex at it:
model = "deepseek-chat"
model_provider = "deepseek"
[model_providers.deepseek]
name = "DeepSeek"
base_url = "https://api.deepseek.com/v1"
env_key = "DEEPSEEK_API_KEY"
wire_api = "chat"
Export the key and run Codex:
export DEEPSEEK_API_KEY="sk-your-key"
codex
Step 3: Use the OpenAI endpoint, not the Anthropic one
DeepSeek publishes two endpoints. Codex speaks OpenAI’s format, so use the OpenAI-compatible URL:
DeepSeek endpoints — pick the right one
| https://api.deepseek.com/v1 | OpenAI-compatible — use this for Codex |
|---|---|
| https://api.deepseek.com/anthropic | Anthropic-compatible — for Claude Code only |
If you came from a Claude Code guide, this is the difference: Claude Code wants /anthropic; Codex wants /v1.
Step 4: Pick the model
deepseek-chat— general coding, fastest and cheapest. Good default.deepseek-reasoner— thinking mode for harder problems.
Change the model key to switch, or keep two profiles. To verify, start Codex and give it a small task; if it edits files and runs commands normally, DeepSeek is serving it.
Pricing
DeepSeek is pay-per-token with no flat coding plan, plus cache-hit discounts and off-peak windows that lower the rate during set hours. It’s one of the cheapest serious options for an agent like Codex. Numbers shift with promotions and versions, so confirm on the official pricing page — see DeepSeek V4 pricing explained.
Troubleshooting
- Format/streaming errors — almost always missing
wire_api = "chat". - 401 / auth errors —
DEEPSEEK_API_KEYisn’t set in the shell running Codex. - “Model not found” — the
modelvalue doesn’t match DeepSeek’s current IDs. - Changes ignored — restart Codex;
config.tomlloads at startup only.
DeepSeek + Codex checklist
- Codex CLI installed; DeepSeek key created
- [model_providers.deepseek] block with /v1 base_url
- wire_api = "chat" set
- model and model_provider point to DeepSeek
- DEEPSEEK_API_KEY exported; Codex restarted
Wrapping up
Using DeepSeek with Codex CLI is a clean config.toml edit: a [model_providers.deepseek] block pointing at https://api.deepseek.com/v1, an env_key for the secret, and the all-important wire_api = "chat". Set model and model_provider to match, export the key, restart Codex.
To run DeepSeek with other agents, see run DeepSeek with Claude Code or DeepSeek + OpenCode.