Disclosure: I run HaryAI, one of the providers used below.
Codex, OpenAI's coding agent, talks to models through the Responses API. DeepSeek supports that API natively, so DeepSeek can be Codex's model instead of an OpenAI one. One config file covers the Codex CLI, the Codex extension for VS Code, and the Codex panel in the ChatGPT desktop app.
Below is the setup against a gateway I run, HaryAI, which resells DeepSeek at a discount, the reason for each line in the config, and at the end the same setup pointed straight at DeepSeek's own API.
The models
DeepSeek serves two current models behind this endpoint:
| Model | Model ID | Context | Max output | Image input |
|---|---|---|---|---|
| DeepSeek V4.1 Flash | deepseek-flash | 1,048,576 tokens | 384,000 tokens | Yes |
| DeepSeek V4 Pro | deepseek-v4-pro | 1,048,576 tokens | 384,000 tokens | No |
deepseek-flash and deepseek-v4-pro are DeepSeek's own published model IDs for this API, not a label a wrapper invented. Flash is the default: it reads images and is built for everyday text and code work. Pro is for harder reasoning and review, text only.
Edit the config
Codex's CLI, VS Code extension, and the ChatGPT desktop app all read ~/.codex/config.toml. Add this block, replacing the placeholder with your key:
model = "deepseek-flash" model_provider = "haryai" forced_login_method = "api" model_reasoning_effort = "high" [model_providers.haryai] name = "HaryAI" base_url = "https://api.haryai.com/v1" wire_api = "responses" experimental_bearer_token = "<your HaryAI key>" model_catalog_url = "https://api.haryai.com/v1/models" What each line does:
-
modelis the model Codex sends on every request. -
model_providerpoints at the block below it, instead of OpenAI's own provider. -
forced_login_method = "api"tells Codex to sign in with the key in this file rather than a ChatGPT login. -
model_reasoning_effortsets how hard it reasons before answering. -
base_urlandwire_api = "responses"send Codex's Responses API calls to this gateway instead of OpenAI. -
experimental_bearer_tokenis your key for this gateway. -
model_catalog_urlpoints the Codex desktop app at this gateway's own model list. Without it, the desktop app's model picker shows OpenAI's models and sends their names when you pick one, which this gateway doesn't serve. The CLI doesn't need it to run; the desktop app's picker does.
If you'd rather not hand-edit TOML, CC Switch is a free app that manages Codex and Claude Code settings: install it, then on your HaryAI account page press Import for Codex. It writes only the settings above and leaves the rest of your config alone, and you can switch back whenever you want.
Old sessions aren't gone
After switching providers, your earlier Codex sessions can look like they vanished. They aren't deleted: Codex keeps sessions started under a ChatGPT login and sessions started under an API key in separate lists, and only shows the list that matches your current config.
Switching to V4 Pro
Change model = "deepseek-flash" to model = "deepseek-v4-pro". Everything else in the config stays the same. Pro reads text only, so a screenshot you paste in gets skipped rather than read.
FAQ
Do I need a ChatGPT login for Codex?
No. forced_login_method = "api" tells Codex to sign in with the key in the config instead.
Can DeepSeek read screenshots in Codex?
DeepSeek V4.1 Flash takes image input. DeepSeek V4 Pro doesn't.
Is this only for programmers?
No. Codex can also write documents, edit spreadsheets, and make slides, and DeepSeek does the same work there.
It works in Claude Code too
The same key and the same gateway also run Claude Code, through its Anthropic-compatible endpoint rather than the Responses API: add an env block to ~/.claude/settings.json pointing at this gateway, your key and the model id, and it runs deepseek-flash or deepseek-v4-pro the same way.
Running it against DeepSeek's own API
The CLI config above also works against DeepSeek's own endpoint instead of a gateway. Swap the provider block for this one, and use your own DeepSeek API key:
model = "deepseek-flash" model_provider = "deepseek" forced_login_method = "api" model_reasoning_effort = "high" [model_providers.deepseek] name = "DeepSeek" base_url = "https://api.deepseek.com" wire_api = "responses" experimental_bearer_token = "<your DeepSeek API key>" Leave out model_catalog_url: that line points at a gateway's own model list, and this config talks to DeepSeek directly. The CLI reads model from the config either way, so it runs deepseek-flash here too. The desktop app's model picker needs some way to learn about a model it doesn't ship with, and this article doesn't confirm that for DeepSeek's own endpoint.
The reason to use a gateway like HaryAI instead is price: it bills DeepSeek at 45% of DeepSeek's own peak list price around the clock, so it comes out to 55% off during DeepSeek's peak hours and less off-peak, when DeepSeek's own price is already lower.
Sources: DeepSeek API Docs: Integrate with Codex, DeepSeek API Docs: Models & Pricing.
More on this setup: https://haryai.com/en/deepseek-codex
