---
title: "Codex config.toml for AGI Plan: Setup Example and 4-Step Check"
description: "Point Codex at AGI Plan by editing the base URL and an env var in config.toml. Includes a provider example, key setup, a 4-step check and where to look on errors."
url: https://cdnping.org/en/blog/agiplan-codex-setup
language: en
published: 2026-11-29
category: "Relays & gateways"
tags: ["Codex","AGI Plan","config.toml","base URL","environment variables"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# Codex config.toml for AGI Plan: Setup Example and 4-Step Check

To make Codex use AGI Plan, do three things: declare a custom provider in `~/.codex/config.toml`, put your AGI Plan API key in an environment variable, and run one simple command to confirm requests go through. Once Codex is configured this way, you don't need a ChatGPT account. AGI Plan is a commercial partner of cdnping, which is why this article uses it as the example; for any other service that is compatible with the OpenAI API, the approach is the same.

In the example below, the base URL and some fields are placeholders. For the actual address and the fields that are available, follow AGI Plan's official Codex tutorial and the official Codex documentation, and don't copy the example verbatim.

## What do you need before you start?

- Codex CLI installed, so that `codex` runs in your terminal.
- An AGI Plan account and an API key. Signup uses an emailed verification code; for choosing a plan and creating a key, see [How to use AGI Plan: sign up, create a key, change one setting](/en/blog/agiplan-getting-started).
- The base URL shown in the console or on the tutorial page.

AGI Plan is compatible with both the OpenAI and Anthropic API formats, and Codex uses the OpenAI one. The service states plainly that it is not an officially authorized channel; [Is AGI Plan an official Claude channel?](/en/blog/is-agiplan-official-claude-channel) covers this candidly.

## How do you write config.toml?

Codex reads its configuration from `~/.codex/config.toml` by default. A custom provider looks roughly like this:

```toml
model_provider = "agiplan"
model = "<model name, as shown in the AGI Plan console>"

[model_providers.agiplan]
name = "AGI Plan"
base_url = "<base URL provided by AGI Plan>"
env_key = "AGIPLAN_API_KEY"
wire_api = "responses"
```

What the fields mean:

| Field | Purpose |
| --- | --- |
| `model_provider` | Which provider is active. The value must match the name in `[model_providers.xxx]` below |
| `base_url` | Where requests are sent. This is the one setting you are changing |
| `env_key` | Which environment variable the API key is read from. Note that this is the variable's name, not the key itself |
| `wire_api` | The protocol used for requests. Accepted values and support depend on AGI Plan's tutorial and the Codex docs |

The model name is deliberately left blank because the model list changes. Check AGI Plan's models page at `https://agiplan.dev/models`. For a fuller explanation of each field, see the [Codex config.toml field reference](/en/blog/codex-cli-config-toml-reference).

## How do you set the environment variable?

Keep the key in an environment variable. Don't write it into config.toml, and don't commit it to a repository.

```bash
# bash / zsh, temporary
export AGIPLAN_API_KEY="your key"

# To make it permanent, add the line above to ~/.bashrc or ~/.zshrc, then
source ~/.zshrc
```

The variable name must match `env_key` exactly, including case. On Windows, use the system environment variable settings, or set it temporarily in PowerShell with `$env:AGIPLAN_API_KEY="..."`. Reopen the terminal window after changing it.

## How do you confirm the configuration works?

Run through these four checks and stop at the first one that fails:

1. Check the variable: run `echo $AGIPLAN_API_KEY` and confirm it is not empty. Don't paste the output into chats or screenshots.
2. Check the file: make sure config.toml is valid TOML, the provider name is consistent throughout, and there are no stray quotation marks.
3. Send the simplest possible request, for example `codex exec "reply with the two letters ok"`, and see whether you get a reply (the subcommand and arguments depend on your installed version; check `codex --help`).
4. Go back to your AGI Plan account page and see whether the request was counted toward usage (the exact location depends on the service's pages). The unit of measure is the CU; for how to convert it, see [What is a CU in AGI Plan?](/en/blog/agiplan-cu-explained).

## Where should you look first when something fails?

- 401 or an authentication failure: first check that the environment variable is in effect in the current terminal, then check that the key was copied in full and has no extra spaces.
- Model not found or 404: most likely the model name or base_url is wrong. Compare against the console and the models page. A few models are labeled "overseas only"; see [How to read AGI Plan's service regions and "overseas only" labels](/en/blog/agiplan-service-regions-model-labels).
- Timeouts or slow responses: first check [cdnping's AGI Plan status page](/en/status/agiplan) for problems on the API, then use the [speed test on the home page](/en) to measure your current network's first-connection and round-trip time to the AGI Plan API.
- To tell whether the problem is Codex itself or your configuration, look at the [Is Codex down? page](/en/down/codex) and see whether other people are reporting problems too.

## Who is this approach for?

It suits developers who don't have a ChatGPT account, or who have no overseas credit card and want to pay monthly in RMB (Chinese yuan). AGI Plan is a multi-provider LLM aggregation gateway. One subscription includes four capability groups: frontier reasoning, balanced general-purpose, Chinese flagship, and fast lightweight. You can share one quota across tools such as Claude Code, Codex and OpenCode. To work out which tier is enough, see [How to choose among AGI Plan's four tiers](/en/blog/agiplan-plans-lite-plus-pro-max).

If you also use Claude Code, the setup is similar, except that you edit settings.json instead; see [Connecting Claude Code to AGI Plan: a settings.json example](/en/blog/agiplan-claude-code-setup).

The full setup guide and plans for AGI Plan are at [agiplan.dev/startup](https://agiplan.dev/startup). To repeat: AGI Plan is a commercial partner of cdnping, so compare it against your own needs, pricing and the service's terms before you decide.

## Next step

Create an API key at AGI Plan, write config.toml following the example above, and get the minimal request in step 3 working. Once that works, move on to tuning the model name and profiles. If it doesn't, work through "Where should you look first when something fails?" one item at a time, changing only one thing per attempt.
