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.
| Model | Speed | Cost | Best For |
|---|---|---|---|
deepseek-v4-flash | Very fast (~5Ă—) | Very cheap | Quick tasks, high-volume work |
deepseek-v4-pro | Moderate | Cheap (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
-
Install Codex CLI (if not already installed):
npm install -g @openai/codex -
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
-
Launch Codex at least once so the
~/.codexdirectory 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 ~/.bashrcOption 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:
codexCodex 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:
| Level | Description |
|---|---|
low | Fast responses with lighter reasoning |
high | Extra reasoning depth (default) |
max | Maximum 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-flashfor routine work; switch todeepseek-v4-proonly 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-protodeepseek-v4-flash - Lower the reasoning level from
hightolow
Network issues on HPC:
- If on Fornax or other restricted servers, set up an SSH reverse proxy tunnel as described in Model API Setup → Network Issues
Related Pages
- Model API Setup (Sub2API) — Group gateway for GLM and DeepSeek models
- Claude Code — Alternative AI coding assistant (GLM via Sub2API)
- ZCode for GLM — Z.AI’s agentic dev environment
- DeepSeek API Docs
- DeepSeek Agent Integrations