Skip to content

Integrations / Codex CLI

Use Codex CLI with any model

Add Yunshu Router as a model provider in OpenAI's Codex CLI. Exact config.toml, environment variable, checks, limits of the Responses API, and fixes.

Get an API key

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

  1. Create a key in the console (API keys → Create key) and copy it.

  2. Put the key in your shell, not in the config file. Add this line to ~/.zshrc or ~/.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"
  3. Edit ~/.codex/config.toml and 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
    model a model ID The model Codex uses.
    model_provider yunshu Selects 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 /v1: Codex adds /responses.
    env_key YUNSHU_API_KEY The variable Codex reads the key from.
    wire_api responses Current Codex releases accept only responses.
  4. Use the global config file. A project’s .codex/config.toml can’t set model_provider or model_providers, so put this in ~/.codex/config.toml.

  5. Start Codex in your project: codex. To try another model once: codex --model kimi-k3.

Check it works

  1. Confirm the key outside Codex:

    curl https://api.yunshurouter.com/v1/models -H "Authorization: Bearer $YUNSHU_API_KEY"
  2. 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.

  3. Open Usage in the console: the requests appear under the Codex key with model and cost.

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/responses without storing anything, and previous_response_id is 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_api — Set wire_api = "responses".
401 YUNSHU_API_KEY not set in this shell, or wrong key Run echo $YUNSHU_API_KEY; open a new terminal after editing your profile.
404 on every request base_url without /v1, or ending in /v1/responses Use exactly https://api.yunshurouter.com/v1.
404 naming the model Model ID not in the catalogue Copy the ID from the models page.
400 naming previous_response_id 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_provider missing, or set in a project config Put model_provider = "yunshu" in ~/.codex/config.toml.
Context runs out early or late model_context_window doesn’t match the model Set it to the value on the model page.

Questions

Can I use non-OpenAI models in Codex?

Yes. We serve every catalogue model on the Responses API. Set model to the model ID.

Does Codex web search work?

No. Web search is a hosted OpenAI tool and we pass on function tools only.

Can I keep my ChatGPT sign-in for some projects?

Yes. Remove or comment out the model_provider line to go back to OpenAI.

Where do I see what a Codex session cost?

In the console under Usage, filtered by the Codex key. You can export it as CSV.