Blog

Connect DeepSeek V4 Pro to Codex: config.toml Setup | Moyi API

Quick Answer

Codex speaks the OpenAI protocol, but it does not read OPENAI_BASE_URL; the endpoint goes in ~/.codex/config.toml:

toml
# ~/.codex/config.toml (Codex does not read OPENAI_BASE_URL; the endpoint goes here)
model_provider = "moyiapi"
model = "deepseek-v4-pro"

[model_providers.moyiapi]
name = "Moyi API"
base_url = "https://api.moyi-api.com/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
bash
export OPENAI_API_KEY="sk-your-key"

The model ID is deepseek-v4-pro (DeepSeek V4 Pro, paid). Below, the default config and the profile approach.

New accounts start with a $0 balance — top up before your first request. Top up from $5. If a request returns 402 (400 on the OpenAI format) with "wallet balance is insufficient", your balance is empty — your base URL and key are fine. Top up and retry.

config.toml: The Simplest Path

Codex only takes a custom endpoint from model_providers in config.toml (as above); the key comes from the variable named by env_key. Put export OPENAI_API_KEY=... in your shell profile (~/.zshrc / ~/.bashrc) and every Codex request goes to Moyi API. Then specify the model:

bash
codex --model deepseek-v4-pro "Introduce yourself in one sentence"

Note base_url includes /v1 — Codex calls the OpenAI Responses API, which needs it.

Profiles: Route by Task

If you don't want all of Codex on DeepSeek, use a profile for precise control. Since Codex CLI 0.166, each profile is its own file, ~/.codex/<profile-name>.config.toml; if config.toml still has a [profiles.xxx] table, --profile fails with an error.

Keep only the [model_providers.moyiapi] block from above in ~/.codex/config.toml, without the top-level model_provider and model, so Codex still defaults to its native models. Then create ~/.codex/moyiapi-pro.config.toml:

toml
# ~/.codex/moyiapi-pro.config.toml
model_provider = "moyiapi"
model = "deepseek-v4-pro"

Then:

bash
codex --profile moyiapi-pro "Refactor src/services/reporting.py to remove duplicate branches"

We tested both setups with Codex CLI 0.166.0 on November 2, 2026: Codex sent the deepseek-v4-pro requests to /v1/responses (the Responses API), and they reached the Moyi API gateway.

This keeps native GPT as the Codex default and uses DeepSeek only when you pass --profile moyiapi-pro, so you can route by task: heavy work on native Codex GPT, daily high-frequency work on cheap DeepSeek V4.

Price

DeepSeek's official price for V4 Pro is $1.32 per million input tokens and $3.96 per million output tokens at peak, half that off-peak (DeepSeek pricing, November 2, 2026). Moyi API's current prices are on the pricing page.

Common Pitfalls

Codex returns 404 / can't connect?

Either base_url is missing /v1, or only OPENAI_BASE_URL was set without config.toml (Codex ignores that variable). The endpoint must be https://api.moyi-api.com/v1, set in ~/.codex/config.toml.

401 auth error?

OPENAI_API_KEY isn't applied or the key was copied incompletely. echo $OPENAI_API_KEY to confirm it starts with sk- and has no whitespace.

Can't switch models in Codex?

Confirm the model is all lowercase with - separators (deepseek-v4-pro). You can curl .../v1/models for the live list.

I get "Model 'deepseek-v4-pro-free' is not available"?

Moyi API has no deepseek-v4-pro-free model. Change model in config.toml (or in moyiapi-pro.config.toml, if you use the profile) to deepseek-v4-pro; nothing else changes.

Do profiles conflict with env vars?

Explicit base_url / api_key in a profile win over env vars — ideal for "default GPT, specific tasks on DeepSeek" routing.

Does V4 Pro's reasoning work in Codex?

Yes. V4 Pro runs over the OpenAI-compatible protocol and reasoning passes through; no extra Codex config.

Get a key at Moyi API and two env vars put DeepSeek V4 Pro into Codex.

Ready to connect?Log in · top up · create an API key — three steps to start.