Codex CLI is OpenAI’s coding agent for the terminal. It talks to the OpenAI Responses API, which
Yunshu Router serves. Add us as a model provider in config.toml and Codex runs on the model you
choose, billed per token to your prepaid balance.
What you need
- Codex CLI installed, a recent release.
- A Yunshu Router account with credit on the balance.
- An API key from the console. Use a separate key for Codex.
Set it up
-
Create a key in the console (API keys → Create key) and copy it.
-
Put the key in your shell, not in the config file. Add this line to
~/.zshrcor~/.bashrc, then open a new terminal:export YUNSHU_API_KEY="YOUR_YUNSHU_KEY"PowerShell (persists for new sessions):
setx YUNSHU_API_KEY "YOUR_YUNSHU_KEY" -
Edit
~/.codex/config.tomland add:model = "deepseek-v4-pro" model_provider = "yunshu" model_context_window = 131072 [model_providers.yunshu] name = "Yunshu Router" base_url = "https://api.yunshurouter.com/v1" env_key = "YUNSHU_API_KEY" wire_api = "responses"Key Value Why modela model ID The model Codex uses. model_provider yunshuSelects the provider block below. Don’t use a reserved id such as openai.model_context_ window the model’s context window Codex doesn’t know our models’ limits, so tell it. base_url https:// api.yunshurouter.com/ v1 With /: Codex addsv1 /.responses env_key YUNSHU_API_ KEY The variable Codex reads the key from. wire_api responsesCurrent Codex releases accept only responses. -
Use the global config file. A project’s
.codex/config.tomlcan’t setmodel_providerormodel_providers, so put this in~/.codex/config.toml. -
Start Codex in your project:
codex. To try another model once:codex --model kimi-k3.
Check it works
-
Confirm the key outside Codex:
curl https://api.yunshurouter.com/v1/models -H "Authorization: Bearer $YUNSHU_API_KEY" -
Run
codex, ask it to list the files in the project, and approve the shell command. A reply that uses the command output means requests and tool calls work. -
Open Usage in the console: the requests appear under the Codex key with model and cost.
Recommended models
| Model ID | Use it for |
|---|---|
deepseek-v4-pro |
Everyday agent work at a low price |
kimi-k3 |
Long tasks with many tool calls |
glm-5.3 |
Quick edits and small tasks |
Codex works best with models that are strong at tool calling.
Set a budget on the key
Codex can run many steps without you. In the console, open API keys, pick the Codex key and
set a monthly budget, a model allow-list, and a budget alert. A request that would
pass the budget is refused with 402 budget_exceeded and Codex stops with an error.
Known limitations
- No server-side conversation state. We serve
/v1/responseswithout storing anything, andprevious_response_idis refused. Codex sends the whole conversation each turn, so it doesn’t need it. - Function tools only. The shell tool and MCP server tools reach the model. Hosted tools such as OpenAI’s web search are not passed on.
- ChatGPT sign-in features (cloud tasks, your ChatGPT plan limits) don’t apply while Codex uses our provider.
Troubleshooting
| What you see | Likely cause | Fix |
|---|---|---|
Codex won’t start, naming wire_ |
— | Set wire_. |
401 |
YUNSHU_ not set in this shell, or wrong key |
Run echo $YUNSHU_; open a new terminal after editing your profile. |
404 on every request |
base_ without /, or ending in / |
Use exactly https:/. |
404 naming the model |
Model ID not in the catalogue | Copy the ID from the models page. |
400 naming previous_ |
Something asked us to continue a stored response | We don’t store responses. Update Codex; report it to us if it repeats. |
403 naming the model |
Not on the key’s allow-list | Add the model to the key. |
402 |
Budget or balance used up | Raise the budget or top up. |
| Codex uses OpenAI instead of us | model_ missing, or set in a project config |
Put model_ in ~/. |
| Context runs out early or late | model_ doesn’t match the model |
Set it to the value on the model page. |