APIMaster.ai

Use DeepSeek in Codex CLI: V4 Flash / Pro Setup Guide

Configure DeepSeek V4 Flash and Pro in Codex CLI through APIMaster's Responses endpoint. Includes API key setup, model switching, tool tests and troubleshooting.

Can Codex CLI use DeepSeek? Our tests with Codex CLI 0.153.4 successfully used deepseek-v4-flash and deepseek-v4-pro through APIMaster's Responses endpoint. Configure a custom provider with base URL https://apimaster.ai/v1 and wire_api = "responses". OpenAI-compatible Chat Completions alone is not sufficient for this configuration.

Last tested: 2026-09-07, Codex CLI 0.153.4, Linux. Both models returned the expected text, invoked a shell tool to read a local test file, and answered with its contents. All runs exited with code 0. Metadata and streaming-event warnings occurred; see troubleshooting. Windows / macOS commands are provided for setup, but this test was run on Linux. Long sessions, image input and complex coding workflows were not tested.

1. Prepare Codex and your API key

Install Codex following the environment guide and Codex setup guide, then check:

codex --version

Create an APIMaster API key with access to the selected DeepSeek model and sufficient quota. For this tutorial, use the dedicated configuration below; you do not need to replace an existing auth.json or sign out of another account.

2. Set the key in your terminal

macOS / Linux:

export APIMASTER_API_KEY='YOUR_APIMASTER_API_KEY'

Windows PowerShell:

$env:APIMASTER_API_KEY = 'YOUR_APIMASTER_API_KEY'

The variable exists only in this terminal session. The configuration stores the variable's name, not the secret itself.

3. Create a separate provider configuration

In a directory you use for this tutorial, create deepseek.toml with this content. Keep your existing Codex configuration unchanged.

model = "deepseek-v4-flash"
model_provider = "apimaster_deepseek"

[model_providers.apimaster_deepseek]
name = "APIMaster DeepSeek"
base_url = "https://apimaster.ai/v1"
env_key = "APIMASTER_API_KEY"
wire_api = "responses"

For a copyable, isolated first test, pass the same settings as command-line overrides. --ignore-user-config prevents another provider in your normal config from taking precedence. --ephemeral avoids saving this test session.

codex exec --ignore-user-config --ephemeral --skip-git-repo-check --sandbox read-only --model deepseek-v4-flash -c 'model_provider="apimaster_deepseek"' -c 'model_providers.apimaster_deepseek.name="APIMaster DeepSeek"' -c 'model_providers.apimaster_deepseek.base_url="https://apimaster.ai/v1"' -c 'model_providers.apimaster_deepseek.env_key="APIMASTER_API_KEY"' -c 'model_providers.apimaster_deepseek.wire_api="responses"' "Reply with exactly: DEEPSEEK_TEST_OK"

Run the command from the terminal where you set the key. Expected final answer: DEEPSEEK_TEST_OK. In older Windows PowerShell versions, native argument quoting can differ; use PowerShell 7 or the profile method below if TOML arguments are rejected.

4. Save the configuration as a reusable profile

For the tested CLI version, place deepseek.toml at ~/.codex/deepseek.config.toml (Windows: %USERPROFILE%\.codex\deepseek.config.toml). If CODEX_HOME is customized, use that directory instead. This named profile keeps the DeepSeek settings separate from your normal config.toml.

macOS / Linux, from the directory containing deepseek.toml:

mkdir -p ~/.codex
cp deepseek.toml ~/.codex/deepseek.config.toml
codex --profile deepseek --model deepseek-v4-flash

Windows PowerShell:

New-Item -ItemType Directory -Force "$env:USERPROFILE\.codex" | Out-Null
Copy-Item .\deepseek.toml "$env:USERPROFILE\.codex\deepseek.config.toml"
codex --profile deepseek --model deepseek-v4-flash

Back up a profile file first if that filename already exists. Profile syntax is version-dependent: these commands target 0.153.4. Check codex --help on your installed version; older releases may use profiles inside config.toml instead.

To use Pro:

codex --profile deepseek --model deepseek-v4-pro

A profile layers over your normal configuration, so existing MCP servers or other settings may still apply. The isolated command in step 3 is useful when diagnosing configuration conflicts.

5. Verify a tool call

Create a local file named probe.txt containing:

TOOL_PROBE_739182

From the same directory, run:

codex exec --profile deepseek --skip-git-repo-check --sandbox read-only --model deepseek-v4-flash "Use your file reading or shell tool to read probe.txt in the current directory. Reply with only the exact content. Do not guess."

Expected: a file-reading command executes successfully, followed by TOOL_PROBE_739182. Repeat with --model deepseek-v4-pro. This checks a tool-request / tool-result round trip, beyond a simple text response. Keep normal permission prompts enabled for actual project work.

Troubleshooting

Symptom Explanation or next step
Model metadata ... not found The tested CLI did not have built-in metadata for these model IDs and used fallback metadata. Our text and tool tests completed, but context limits and other defaults should not be treated as verified model capabilities.
Model-list parsing error The gateway's model list may differ from Codex's metadata catalog. Specify the model explicitly and check whether the actual request finishes.
OutputTextDelta without active item Seen in our streaming test. The final response and tool round trip still completed. If output is missing or interrupted, preserve the CLI version, timestamp and error for support.
401 or request goes to another provider Check APIMASTER_API_KEY, provider selection and inherited settings. Retry the isolated command in step 3.
404 or unsupported protocol The base URL ends in /v1, not /chat/completions; set wire_api = "responses".
Unknown command-line option Check the installed CLI version. The documented options were tested with 0.153.4.

Frequently asked questions

Does this mean every DeepSeek endpoint works in Codex?

No. These results apply to APIMaster's gateway configuration. A provider must support the protocol and tool behavior that Codex expects; accepting /chat/completions does not establish Responses compatibility.

Do I need a ChatGPT subscription for this setup?

This custom provider uses your APIMaster API key and account quota. It does not use ChatGPT subscription quota. Check the model marketplace for current API rates.

Can I claim full Codex compatibility from these tests?

The verified scope is short text output and a local file-reading tool round trip. The warnings above remain relevant; long-context behavior, every tool and every future CLI release are not covered.

Continue with DeepSeek