Skip to content

Configure DeepSeek in Codex

Last updated:2026-08-12· 14 min read

🚀 Quick access

  • ChatGPT Domestic:Open entry↗
  • Mirror site:Open mirror↗
  • Official ChatGPT:chatgpt.com ↗

Configure DeepSeek in Codex

Last updated: 2026-08-12

Introduction

Codex defaults to OpenAI models; via model_providers in ~/.codex/config.toml you can switch the inference backend to the DeepSeek API—keeping Codex’s “read repo, edit files, run commands” workflow while using models such as deepseek-v4-pro and deepseek-v4-flash.

This guide covers: get a key → environment variables → config.toml → curl connectivity → common errors. Complete Codex Install & Setup first. Endpoints, model names, and Codex behavior follow DeepSeek API docs and Codex config docs.

Why connect DeepSeek to Codex?

NeedPotential benefit
CostAPI pricing often below comparable OpenAI tiers for high-frequency agent calls
Chinese and codeV4 series stable for Chinese comments and error explanations
Data pathKeys and requests via DeepSeek official or self-hosted gateway for audit

Note: Codex tooling, sandbox, and approval stay on the client—changing models does not reduce “wrong file edit” risk; keep strict permission policy.

Step 1: get a DeepSeek API key

  1. Open DeepSeek and enter the developer platform (steps per current site).
  2. Complete account, billing, and API key creation—keys usually show once; store in a password manager.
  3. Never put the key in Git, frontend code, or plain text in config.toml; use environment variables.

For full apply-first-request and production checklist, see DeepSeek API get started. For browser-only trials use the DeepSeek V4 domestic entry or AI Chat Studio mirror—web chat and API accounts/quotas are not automatically the same.

Step 2: confirm API parameters

Per DeepSeek API docs, OpenAI-compatible interface commonly uses:

ParameterValue
Base URLhttps://api.deepseek.com
AuthAuthorization: Bearer $DEEPSEEK_API_KEY
Model names (examples)deepseek-v4-pro, deepseek-v4-flash

Model strings update—copy from docs, do not reuse stale names like deepseek-chat. Try deepseek-v4-pro for coding tasks; deepseek-v4-flash when latency-sensitive.

Step 3: set environment variables

macOS / Linux (current shell):

export DEEPSEEK_API_KEY="your-key-here"

Windows PowerShell (current session):

$env:DEEPSEEK_API_KEY = "your-key-here"

Production should use system secret stores or CI secrets, not long-lived shell profile entries. DeepSeek security practices: API guide “before production” section.

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

The following belongs in user-level ~/.codex/config.toml (Windows: %USERPROFILE%\.codex\config.toml). model_provider and model_providers cannot live only in project .codex/config.toml—Codex ignores those keys in project files.

# Declare DeepSeek as custom provider
[model_providers.deepseek]
name = "deepseek"
base_url = "https://api.deepseek.com"
wire_api = "responses"
env_key = "DEEPSEEK_API_KEY"
requires_openai_auth = false

# Switch default backend
model_provider = "deepseek"
model = "deepseek-v4-pro"

# Beginners: keep ask-before-approve
approval_policy = "on-request"
sandbox_mode = "workspace-write"

Field reference

FieldPurpose
base_urlDeepSeek API root; if docs require /v1 suffix, follow docs
wire_apiNewer Codex defaults to responses; if gateway only supports Chat Completions, confirm DeepSeek or proxy exposes a compatible endpoint
env_keyRead Bearer token from this env var
requires_openai_auth = falseRequired for non-OpenAI key prefixes
modelMust match DeepSeek doc model ID exactly

DeepSeek docs note API support in Claude Code, Copilot, and similar agents; Codex connects via OpenAI-compatible model_providers—same idea as DeepSeek coding guide API calls, but configured in Codex not SDK code.

Step 5: verify API with curl first

Before changing Codex, confirm key and model with a minimal request (replace placeholders with current doc values):

curl https://api.deepseek.com/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $DEEPSEEK_API_KEY" \
  -d '{
    "model": "deepseek-v4-pro",
    "messages": [{"role": "user", "content": "Reply OK"}],
    "stream": false
  }'

If curl fails, fix key, balance, and model name before retrying in Codex. After curl succeeds, run codex in a project directory with a read-only task to verify end-to-end.

Profiles for multi-model switching

For “DeepSeek daily, OpenAI for review,” use profile overlays:

[profiles.openai-default]
model_provider = "openai"
model = "gpt-5.4"

[profiles.deepseek-coding]
model_provider = "deepseek"
model = "deepseek-v4-pro"
model_reasoning_effort = "high"

Launch with: codex --profile deepseek-coding. Profiles can also live in ~/.codex/deepseek-coding.config.toml—see official profile docs.

Troubleshooting

SymptomLikely causeFix
401 / auth failedWrong key or env not exportedRe-export; never echo keys in public
404 / model not foundStale or misspelled modelCheck model table in API docs
wire_api / responses errorCodex vs gateway protocol mismatchConfirm DeepSeek or proxy supports Codex responses
Config not appliedIn project config or overridden by profileCheck user config.toml and --profile
Slow or dropped streamNetwork or timeoutTune provider timeout; evaluate compliant gateway for regional network
Code quality dropModel vs task mismatchTry deepseek-v4-pro for complex reasoning; see DeepSeek R1 reasoning guide

Important: Codex since early 2026 tends toward wire_api = "responses". If DeepSeek only exposes /chat/completions and your Codex version requires responses, you may need official agent integration updates, DeepSeek’s recommended compatibility layer, or a compliant gateway with /v1/responses after team review—do not disable sandbox or hard-change requires_openai_auth in production to “work around” errors.

Security and compliance

  • Rotate DeepSeek and OpenAI keys separately; do not reuse the same env name.
  • Confirm data residency and vendor policy before company repos.
  • Codex may still read business logic in the repo; use read-only sandbox or excluded dirs for sensitive modules.
  • Billing is on DeepSeek console—independent from ChatGPT Codex subscription.

Frequently asked questions

Can I still sign in with ChatGPT after DeepSeek config?

Yes. model_provider sets the inference backend; ChatGPT login is for Codex product authorization. If they conflict, follow current official docs.

deepseek-v4-flash vs deepseek-v4-pro?

pro for complex refactors and multi-file reasoning; flash for quick Q&A, comments, small patches. Run five real tasks each on the same repo and compare edit lines and test pass rate—more reliable than spec sheets.

DeepSeek backend in IDE extension?

IDE extensions share user-level config.toml—same setup. Restart extension or reload window after changes.

Are domestic web DeepSeek and API the same?

Not necessarily. DeepSeek V4 domestic entry and AI Chat Studio suit chat trials; Codex agent needs API key. See DeepSeek China access guide.

vs DeepSeek web for code?

Codex wins on repo context + test execution + multi-file patches; pure chat suits single snippets. Complement: clarify architecture with DeepSeek prompt guide, then implement in Codex.

Official resources

Next reading

Action path

Today: curl-verify key and model, then one read-only Codex command in a practice repo. This week: fix a failing test with DeepSeek backend; log time and diff lines vs OpenAI default. Before production: document model_provider switching, key rotation, and rollback profile (codex --profile openai-default) for the team.

Related