apiprice Download 中文

Guides › Codex CLI

Use DeepSeek in Codex CLI

Bottom line: Codex only supports the Responses API, which DeepSeek supports natively, so you add one custom provider with wire_api = "responses" (base_url https://api.deepseek.com, model deepseek-flash or deepseek-v4-pro) to ~/.codex/config.toml and supply the key via DEEPSEEK_API_KEY. On 2026-10-17 we confirmed on codex-cli 0.163.0 that this config parses and reaches DeepSeek's /responses endpoint.

✓ Docs checkedCodex config reference & DeepSeek Codex docs checked 2026-10-17
✓ Config parsescodex-cli 0.163.0: without a key → "Missing environment variable: DEEPSEEK_API_KEY"; fake key → 401 from DeepSeek; no parse error
✓ Key auth & model IDs checkedReal key, GET /models → 200: deepseek-flash (DeepSeek-V4.1-Flash), deepseek-v4-pro (2026-10-17)
✓ Text call passes2026-10-17, codex-cli 0.163.0 + deepseek-flash: codex exec returned OK (exit 0)
✓ Tool call passes (Linux/macOS)Linux local + macOS CI: Codex created and read back proof.txt under -s workspace-write (sandbox on). Windows Codex tool calls with sandbox on are not verified; the deep test is skipped there.

Scope

Codex versioncodex-cli 0.163.0 (npm @openai/codex, latest as of 2026-10-17)
Key typeDeepSeek Platform API key (sk-…), pay-as-you-go · source
ProtocolResponses API (Codex only supports wire_api = "responses"; DeepSeek supports POST /responses, stateless) · Codex config reference · DeepSeek Responses API
Base URLhttps://api.deepseek.com
Model IDdeepseek-flash (DeepSeek-V4.1-Flash) · deepseek-v4-pro (DeepSeek-V4-Pro-0813) · pricing · DeepSeek price hub
OSTested: Linux x86_64, macOS ARM64 (CI), Windows x64 PS5.1/pwsh7 (CI; Codex tool calls with sandbox on not verified). Not tested: ARM Windows, Intel Mac. See one-line install below.

One-line install (optional)

The script installs Claude Code / Codex (your choice), writes DeepSeek into settings.json / config.toml, and runs one short live request with your key. The key is never a CLI argument (stays out of shell history); type it hidden, or set APIPRICE_API_KEY.

macOS / Linux:

curl -fsSL https://apiprice.app/install.sh | bash -s -- --tool codex

Windows (PowerShell 5.1 or 7):

& ([scriptblock]::Create((irm https://apiprice.app/install.ps1))) -Tool codex

Undo: curl -fsSL https://apiprice.app/install.sh | bash -s -- --uninstall --tool codex · & ([scriptblock]::Create((irm https://apiprice.app/install.ps1))) -Uninstall -Tool codex

Assets: install.sh · install.ps1 · codex-models.json

Tested

Uncovered / unverified

Step 1: install Codex manually and set the key

npm install -g @openai/codex
codex --version          # this page uses codex-cli 0.163.0
export DEEPSEEK_API_KEY="sk-..."   # add to ~/.bashrc / ~/.zshrc to persist

Step 2: edit ~/.codex/config.toml

Back up first: cp ~/.codex/config.toml ~/.codex/config.toml.bak 2>/dev/null

# ~/.codex/config.toml (user-level; model_provider in project .codex/config.toml is ignored)
model = "deepseek-flash"            # or "deepseek-v4-pro"
model_provider = "deepseek"
model_reasoning_effort = "high"
web_search = "disabled"             # built-in web search only works with deepseek-v4-pro
model_catalog_json = "~/.codex/models.json"   # optional: model metadata file from DeepSeek docs

[model_providers.deepseek]
name = "DeepSeek"
base_url = "https://api.deepseek.com"
wire_api = "responses"              # Codex only supports responses
env_key = "DEEPSEEK_API_KEY"

models.json (optional; removes the metadata warning): copy it from the "Edit the Configuration File Manually" section of the DeepSeek docs to ~/.codex/models.json, or delete the model_catalog_json line. DeepSeek Codex docs

Manual setup above. You can also use this site’s one-line installer (see above) or the setup script in DeepSeek’s docs.

Step 3: check it works

codex exec --skip-git-repo-check "reply with OK"

Restore defaults

mv ~/.codex/config.toml.bak ~/.codex/config.toml   # or delete the lines above and the [model_providers.deepseek] section
rm -f ~/.codex/models.json                         # if you did not have it before
unset DEEPSEEK_API_KEY

To be verified

FAQ

Can Codex use the Chat Completions API with DeepSeek?

No. The Codex config reference says wire_api only supports "responses"; on codex-cli 0.163.0, wire_api = "chat" fails with "wire_api = "chat" is no longer supported". DeepSeek supports the Responses API (POST https://api.deepseek.com/responses).

Which model ID?

deepseek-flash (DeepSeek-V4.1-Flash, image input) or deepseek-v4-pro (DeepSeek-V4-Pro-0813). The legacy deepseek-v4-flash name still works but is served by V4.1 Flash.

What key do I need?

A DeepSeek Platform API key (starts with sk-), pay-as-you-go; no OpenAI/ChatGPT account needed.

env_key vs experimental_bearer_token in the official example?

DeepSeek’s example writes the key into experimental_bearer_token; the Codex reference marks it "discouraged; use env_key". We use env_key so the key stays out of the file. Both are documented fields.

Warning "Model metadata for deepseek-flash not found"?

Tested: without model_catalog_json, codex-cli 0.163.0 warns and uses fallback metadata; with ~/.codex/models.json from the DeepSeek docs and model_catalog_json set, the warning disappears.

How do I restore Codex defaults?

Copy your backup config.toml back (or delete the model / model_provider / model_catalog_json lines and the [model_providers.deepseek] section), then unset DEEPSEEK_API_KEY. If you used DeepSeek’s setup script, choose menu option 9.

Sources: Codex config reference · Codex advanced config · DeepSeek × Codex · DeepSeek Responses API guide · POST /responses · checked 2026-10-17

Current Codex deals