How to Use DeepSeek V4.1 in Codex and Cut API Costs

Connect Codex to DeepSeek’s Responses API, choose v4.1 Flash or Pro, and verify billing before using it for regular repository work.

DeepSeek V4.1 Flash can run as the model provider inside Codex through DeepSeek’s native Responses API. Codex keeps its repository tools, approvals, AGENTS.md instructions, MCP servers, skills, and project settings. DeepSeek handles model inference and bills the requests to your DeepSeek API balance.

This configuration uses DeepSeek API billing for Codex model requests. DeepSeek requests do not consume a ChatGPT plan allowance. For a new setup, choose deepseek-flash. It now runs DeepSeek-V4.1-Flash and accepts both text and image input.

DeepSeek V4 Pro will retire at 12:00 Beijing Time on September 14, 2026. Your requests sent to deepseek-v4-pro after that time will be served by V4.1 Flash and billed at Flash rates.

Last updated: September 10, 2026.

Read More: How to Use DeepSeek in Claude Code With an API Key

Can I Use DeepSeek in Codex With Only a DeepSeek API Key?

Yes. DeepSeek’s Codex configuration authenticates with a DeepSeek API key and skips ChatGPT account authentication for the model provider. Model requests are charged to your DeepSeek API balance at DeepSeek’s published token rates.

Codex sessions authenticated through ChatGPT use the allowance and billing attached to that ChatGPT plan. Sessions configured with DeepSeek use DeepSeek API billing. The two accounts, balances, and usage systems are independent.

A DeepSeek configuration can reduce fixed subscription spending when you mainly want Codex for coding and prefer usage-based model billing. A paid ChatGPT plan can be worthwhile when its included Codex allowance or other ChatGPT features justify the monthly cost.

What You Need Before Setup

  • Codex CLI, the ChatGPT desktop app, or the Codex extension for VS Code.
  • Codex 0.144.0 or newer for DeepSeek’s Codex model catalog.
  • A DeepSeek Platform account and API key.
  • Available credit in the DeepSeek API account.
  • A repository approved for DeepSeek processing, with credentials and prohibited data removed.
  • Launch Codex at least once before setup. This creates the ~/.codex directory used by the integration.

Check and Update Codex

Check the installed version first. DeepSeek’s Codex model catalog requires Codex 0.144.0 or newer. If your installation is older, update Codex through npm with the second command.

codex --version
# Update when the installed version is older than 0.144.0
npm install -g @openai/codex@latest

Read More: OpenAI Codex Commands Cheat Sheet

How to Use DeepSeek V4.1 Flash in Codex

DeepSeek publishes an official installer that updates ~/.codex/config.toml, writes the required ~/.codex/models.json catalog, preserves existing MCP and project trust settings, and validates the configuration before it replaces the active files.

1. Create a DeepSeek API Key

Sign in to the DeepSeek Platform, open the API Keys page, and create a new key. DeepSeek API keys begin with sk-.

Add API credit before the first test. Copy the key when it appears and store it in a password manager or another approved credential store. Keep the key out of repositories, issues, screenshots, shared documents, and shared shell commands.

2. Run the DeepSeek Setup Script

The commands below download and execute DeepSeek’s official installer. If your security policy requires review before remote code execution, download and inspect the installer first.

Windows

Open PowerShell or Windows Terminal and run:

irm https://cdn.deepseek.com/api-docs/codex-deepseek-setup-en.ps1 | iex

macOS or Linux

Run:

bash <(curl -fsSL https://cdn.deepseek.com/api-docs/codex-deepseek-setup-en.sh)

Choose the DeepSeek Model

Enter your DeepSeek API key when prompted. The installer backs up the active config.toml under ~/.codex/backup-deepseek/, writes models.json, configures the DeepSeek Responses API provider, and validates the JSON and TOML syntax. Use option 1 for a new setup. Option 2 remains available only during the V4 Pro retirement transition:

  • Option 1: deepseek-flash runs DeepSeek-V4.1-Flash for text, image input, coding, repository analysis, tests, and other agentic work.
  • Option 2: deepseek-v4-pro remains available until 12:00 Beijing Time on September 14, 2026. Requests use V4.1 Flash at Flash rates after retirement.
  • Option 9: restores the Codex configuration saved before DeepSeek was installed.

3. Restart Codex

Close active Codex windows and terminal sessions. Start Codex again from your project directory. The CLI startup banner should show the DeepSeek model you selected, such as model: deepseek-flash.

cd /path/to/your-project
codex

4. Verify the DeepSeek Connection

Begin with a read-only repository task whose answer is easy to check. Confirm that Codex returns real file paths and project commands. After that test, request one small edit on a disposable branch, inspect the diff, and run the project’s normal checks.

Use one branch per provider when comparing DeepSeek with another model on an identical task. Open the DeepSeek Platform usage page and confirm that the request and token charge appear under the expected account.

Read this repository without editing files. Identify the test command, the main entry point, and three likely maintenance risks. Cite the relevant file paths.

5. Switch Back to OpenAI

Run the DeepSeek setup script again and select option 9 to restore the configuration saved before DeepSeek was installed. Restart all Codex clients after the restoration.

Codex stores ChatGPT-authenticated sessions and third-party API sessions in different history groups. After a provider switch, the client displays the group for the active authentication method. Restoring the earlier authentication method displays its session group again.

DeepSeek V4.1 Flash in Codex

deepseek-flash is the canonical DeepSeek model ID for Codex. It runs DeepSeek-V4.1-Flash with a 1 million-token context window, up to 384,000 output tokens, tool calls, JSON output, thinking and non-thinking modes, image input, and a 2,500-request account-level concurrency limit.

The legacy IDs deepseek-v4-flash and deepseek-v4-flash-vision-exp are valid aliases for V4.1 Flash and use Flash pricing. Rerunning DeepSeek’s Codex installer removes those legacy entries from models.json.

V4 Pro is available until 12:00 Beijing Time on September 14, 2026. After that time, DeepSeek serves deepseek-v4-pro requests with V4.1 Flash and bills them at Flash rates.

DeepSeek V4.1 Flash API Pricing in Codex

DeepSeek bills V4.1 Flash requests by token usage with peak and off-peak rates. Peak hours are 01:00 to 04:00 UTC and 06:00 to 10:00 UTC from Monday through Friday. All other hours use the off-peak rate. V4 Pro keeps its existing rates until retirement on September 14; after that, requests sent to the Pro model name use V4.1 Flash pricing.

Context caching is enabled automatically. A request receives the cache-hit rate only when its reusable prefix matches content already persisted in DeepSeek’s cache. Cache matching works on a best-effort basis.

Token typeV4.1 Flash off-peakV4.1 Flash peak
Cached input / 1M$0.003$0.006
Uncached input / 1M$0.15$0.30
Output / 1M$0.60$1.20

Example API Cost

The example below uses 10 million uncached input tokens and 2 million output tokens. It excludes cache hits, image-token input, taxes, and future price changes.

ModelOff-peak costPeak cost
DeepSeek V4.1 Flash$2.70$5.40

DeepSeek can change API prices. Check the DeepSeek API pricing reference before funding a large recurring workload.

Why Codex Usage Can Consume Many Input Tokens

Codex requests can include project instructions, file contents, tool definitions, command output, diffs, conversation history, and other working context in addition to the text visible in the prompt box. Repository-wide analysis, dependency migrations, repeated test runs, and long debugging sessions can process large amounts of input.

DeepSeek’s automatic context cache can reduce the price of repeated prefixes that produce cache hits. New or frequently changing context is billed at the uncached input rate. Review the DeepSeek usage dashboard during the first week and base your budget on real repository tasks.

Manual Configuration and API Key Storage

The official installer stores the DeepSeek API key in ~/.codex/config.toml through the experimental_bearer_token field. Codex also reads model metadata from the matching ~/.codex/models.json catalog.

For a manual configuration, create the matching models.json catalog from the DeepSeek Codex integration and use deepseek-flash as the active model.

model = "deepseek-flash"
model_provider = "deepseek"
preferred_auth_method = "apikey"
forced_login_method = "api"
model_reasoning_effort = "high"
model_catalog_json = "~/.codex/models.json"
[model_providers.deepseek]
name = "deepseek"
base_url = "https://api.deepseek.com/"
wire_api = "responses"
experimental_bearer_token = "<your DeepSeek API key>"

Handle config.toml as a credential file. Keep the .codex directory out of repositories, remove the token before sharing the file, and revoke the key through the DeepSeek Platform after suspected exposure.

Troubleshooting DeepSeek in Codex

Codex Returns a 404, 405, or Responses API Error

Update Codex and rerun DeepSeek’s official installer. Old configurations can contain wire_api = "chat", /chat/completions, translation proxies, or retired model settings that do not match the Responses API integration.

Confirm these values in config.toml:

model_provider = "deepseek"
base_url = "https://api.deepseek.com/"
wire_api = "responses"

DeepSeek-Flash Is Missing from the Model Menu

Check the Codex version first. DeepSeek’s Codex model catalog requires Codex 0.144.0 or newer. Update Codex when needed, rerun the official setup script to refresh models.json, choose option 1, and restart every Codex client. Rerunning the installer also removes retired deepseek-v4-flash and deepseek-v4-flash-vision-exp catalog entries.

codex --version

Codex Reports an Authentication or Balance Error

Confirm that the DeepSeek API key is active and the account has API credit. API requests draw from DeepSeek API credit; DeepSeek chat access uses a different service. Rerun the setup script after replacing the key and revoke any key whose storage location is uncertain.

Codex Rejects the Models

Update Codex, rerun the installer, and restart all clients. A manually edited models.json file can fail when it contains invalid JSON or omits metadata required by the installed Codex client.

The Desktop App Shows Custom

The ChatGPT desktop app can display a configured third-party provider as Custom. On Windows it can also display the selected DeepSeek model name. Check the session model details and DeepSeek usage activity when you need to confirm which provider handled the request.

Old Codex Sessions Are Missing

Restore the previous authentication configuration and restart Codex. The client displays session history for the active authentication method, and the earlier session group reappears after its authentication method is restored.

A Long Task Costs More Than Expected

Long sessions can repeatedly send conversation state, repository context, generated files, command output, and test logs. Start a new session when the task changes, exclude irrelevant generated directories, avoid repeated large logs, and use /compact when the active session becomes too large.

Screenshots or Image Prompts Do Not Work

deepseek-flash accepts both text and image input. Rerun DeepSeek’s installer if Codex is using an older model catalog, then confirm that the active model is deepseek-flash. The retired deepseek-v4-flash-vision-exp ID is no longer required for image input.

Security and Repository Data

Repository content sent to the model is processed by DeepSeek under its API service and privacy terms. Remove private keys, production credentials, customer records, confidential source code, and regulated information unless your organization has approved that data transfer.

DeepSeek uses personal data to improve and train its technology and directly collects, processes, and stores personal data in the People’s Republic of China. You can opt out of the use of personal data for model training or technology optimization.

Do Different DeepSeek API Keys Increase the Concurrency Limit?

No. DeepSeek calculates concurrency at the account level, independent of the API key used for a request. All keys under one account share its concurrency limit. Additional keys can help with device management, key rotation, and revocation.

Related Resources

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the latest & top AI tools sent directly to your email.

Subscribe now to explore the latest & top AI tools and resources, all in one convenient newsletter. No spam, we promise!