Overview

DeepSeek V4 models can be used as the backend for OpenAI’s Codex CLI (@openai/codex), giving you an agentic coding experience with DeepSeek’s fast and cheap models instead of OpenAI’s.

ModelSpeedCostBest For
deepseek-v4-flashVery fast (~5Ă—)Very cheapQuick tasks, high-volume work
deepseek-v4-proModerateCheap (still much cheaper than OpenAI)Complex coding, long-horizon agent tasks

Both models have a 1M token context window and support reasoning levels: low, high, max.

DeepSeek vs GLM

DeepSeek V4 models are much faster and cheaper than GLM, but our GLM coding plan has unlimited usage. Use DeepSeek when you need speed or when GLM is rate-limited. See Model API Setup for GLM configuration.

Prerequisites

  1. Install Codex CLI (if not already installed):

    npm install -g @openai/codex
  2. Get a DeepSeek API key:

    • Go to platform.deepseek.com
    • Create an account and generate an API key
    • Alternatively, ask the computer officer for the group’s shared DeepSeek key
  3. Launch Codex at least once so the ~/.codex directory exists:

    codex

Configuration

Option 1: Edit ~/.codex/config.toml (Manual)

Edit or create ~/.codex/config.toml:

model = "deepseek-v4-flash"
model_provider = "deepseek"
 
[model_providers.deepseek]
name = "DeepSeek"
env_key = "DEEPSEEK_API_KEY"
base_url = "https://api.deepseek.com"
wire_api = "chat"

Then set your API key:

export DEEPSEEK_API_KEY="your-deepseek-api-key"

Add this to your ~/.bashrc or ~/.zshrc to persist across sessions:

echo 'export DEEPSEEK_API_KEY="your-deepseek-api-key"' >> ~/.bashrc
source ~/.bashrc

Option 2: Use deepseek-v4-pro (Stronger Model)

For harder coding tasks, switch the model in config.toml:

model = "deepseek-v4-pro"
model_provider = "deepseek"
 
[model_providers.deepseek]
name = "DeepSeek"
env_key = "DEEPSEEK_API_KEY"
base_url = "https://api.deepseek.com"
wire_api = "chat"

Using DeepSeek via Sub2API Gateway

If you want to use DeepSeek models through our group’s Sub2API gateway instead of a personal DeepSeek API key:

model = "deepseek-v4-flash"
model_provider = "sub2api"
 
[model_providers.sub2api]
name = "Sub2API"
env_key = "SUB2API_KEY"
base_url = "https://claude.matsci.dev"
wire_api = "chat"

Set the key:

export SUB2API_KEY="your-sub2api-key"

See Model API Setup for how to get a Sub2API key.

wire_api

The wire_api = "chat" setting is critical. DeepSeek uses the Chat Completions API format, not the Responses API. If your Codex CLI version requires the Responses API only, DeepSeek V4 may not work — in that case, use Claude Code or OpenCode instead.

Running

Once configured, just run:

codex

Codex will use DeepSeek V4 as the backend model. You can switch between Flash and Pro by changing the model field in config.toml.

Reasoning Levels

DeepSeek V4 models support three reasoning levels:

LevelDescription
lowFast responses with lighter reasoning
highExtra reasoning depth (default)
maxMaximum reasoning depth for hardest problems

Set via Codex CLI flags or in the config file.

Cost Tips

  • DeepSeek cache hits make agent bills surprisingly low. Keep system prompts, repo rules, and stable context at the beginning of the prompt to maximize cache reuse.
  • Avoid injecting timestamps, random IDs, or changing logs before the stable prefix — this kills cache hits.
  • Use deepseek-v4-flash for routine work; switch to deepseek-v4-pro only for complex debugging or architecture decisions.
  • Check usage at platform.deepseek.com

Troubleshooting

Model not found / API errors:

  • Verify wire_api = "chat" is set in the provider config
  • Check that your API key is valid and has credits
  • Ensure Codex CLI version is >= 0.144.0

Slow responses:

  • Switch from deepseek-v4-pro to deepseek-v4-flash
  • Lower the reasoning level from high to low

Network issues on HPC: