---
title: "Use Codex Without a ChatGPT Account: API Key and Custom Provider"
description: "Yes. Codex can run on an API key or a custom provider instead of a ChatGPT login. Compare billing, copy a config.toml example, and verify the setup step by step."
url: https://cdnping.org/en/blog/codex-without-chatgpt-account
language: en
published: 2026-11-11
category: "Developer tools"
tags: ["Codex","API key","config.toml","custom provider","getting started"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# Use Codex Without a ChatGPT Account: API Key and Custom Provider

Yes. The Codex command-line tool is not limited to ChatGPT sign-in: it also supports an API key, and `config.toml` can point it at other compatible endpoints. So "no ChatGPT account" does not mean you can't use Codex. You just need a different authentication and billing route.

Below we cover the difference between the two modes first, then give a configuration you can follow. Field names and login commands may change between versions, so check the official Codex documentation and `codex --help` before you start.

## What is the difference between the two Codex login modes?

| | ChatGPT sign-in | API key |
|---|---|---|
| Identity | A ChatGPT account | An API key |
| Billing | Uses the allowance included in a ChatGPT subscription; the exact scope is whatever the official docs say | Billed by API usage, or by the rules of whichever service you use |
| Can you change the endpoint? | Usually not | Yes, through provider configuration |
| Best for | People who already have a subscription and want to use it directly | People without an account, who want pay-as-you-go, or who need to use another endpoint |

The key point: a ChatGPT subscription and the OpenAI API are two separate account systems, and their quotas are not shared. This is covered in more detail in [ChatGPT Plus vs. the OpenAI API: accounts, billing and quotas are separate](/en/blog/chatgpt-plus-vs-openai-api-difference). To find out whether your subscription includes Codex, see [Does ChatGPT Plus include Codex? How to check what your subscription covers](/en/blog/chatgpt-plus-includes-codex).

## What are your options without an account?

1. **Use an OpenAI API key directly.** Create a key on the OpenAI developer platform and let Codex read it. You pay by API usage. Whether you can sign up and how you can pay depends on your region and the platform's rules; please follow the terms of service and local regulations.
2. **Use a third-party service that is OpenAI-compatible.** As long as the provider gives you an endpoint URL and an API key, you can register it as a provider in `config.toml`.
3. **Still try the official sign-in first.** If you are only unsure about your account status, read [Which plan to use with Codex](/en/blog/codex-which-plan-to-use) before deciding whether to switch routes.

Whichever you pick, the rule is the same: never commit the key to a repository, and never paste a screenshot of your config into a group chat.

## How do you sign in to Codex with an API key?

The simplest approach is to put the key in an environment variable and let Codex read it.

```bash
export OPENAI_API_KEY="sk-your-key"
codex
```

Some versions also provide a dedicated login subcommand, such as the API key option of `codex login`. Check `codex login --help` and the official docs for the exact arguments; this article does not assume your version has it.

If Codex still pops up the ChatGPT sign-in, it either did not pick up the key or the config specifies a different auth method. First check that the environment variable is set in the current terminal (`echo $OPENAI_API_KEY`).

## How do you write a custom provider in config.toml?

The config file is usually at `~/.codex/config.toml`. Here is a structural example; for what each field means, see the [Codex config.toml field reference](/en/blog/codex-cli-config-toml-reference):

```toml
model = "your-model-name"
model_provider = "myprovider"

[model_providers.myprovider]
name = "My Provider"
base_url = "https://example.com/v1"
env_key = "MY_PROVIDER_API_KEY"
wire_api = "fill in per the official docs"
```

What the fields do:

- `model_provider`: selects which provider is active; it must match the table name below.
- `base_url`: the endpoint URL. Whether it ends in `/v1` depends on the provider's docs.
- `env_key`: the name of the environment variable that holds the key. The key itself never goes in the file.
- `wire_api`: the request protocol. The allowed values and the default change between versions, so follow the current official docs; a wrong value makes requests fail.
- `model`: use a model name the provider actually supports. Do not copy the example.

After saving, set the environment variable:

```bash
export MY_PROVIDER_API_KEY="your-key"
```

Claude Code, Codex and OpenCode have a lot in common in how they take an endpoint URL; compare them in [Custom API endpoints for Claude Code, Codex and OpenCode](/en/blog/configure-custom-api-endpoint-claude-code-codex).

## How do you verify the setup?

Check in order and stop at the first step that fails:

1. `echo $MY_PROVIDER_API_KEY` prints something, so the environment variable is active in the current terminal.
2. Use curl to hit the provider's model list or send one minimal chat request, to confirm that the URL and key work on their own.
3. Start `codex` and send a very short message to see whether it replies.
4. A 401 usually means a wrong key or a variable that did not take effect. A 404 usually means a wrong `base_url` path or `wire_api`. A timeout: look at the network and service status first.

If you suspect a problem on OpenAI's side, see cdnping's [/en/status/openai](/en/status/openai) and [/en/down/codex](/en/down/codex), which compare the official status page, API probes every 5 minutes and user reports. For a way to think about network quality, see [/en/learn/ai-api-latency-china](/en/learn/ai-api-latency-china).

## How do the two billing models compare?

A subscription is a fixed monthly fee, which suits people who use it steadily every day and don't want to do the math. API billing is by usage: cheap when you use little, but it can swing widely if you use a lot or run long tasks. If you're unsure how much you'll use per month, try pay-as-you-go for a week or two and judge from the real bill. See [How to estimate Claude Code token usage](/en/blog/ai-coding-agent-token-cost-estimate) for the method; the same approach works for Codex.

## What if you don't have an overseas payment method?

AGI Plan is a multi-provider LLM aggregation gateway: monthly subscription, paid in RMB, no overseas credit card needed. In Codex you only change one endpoint URL, and no ChatGPT account is required. One subscription can switch between multiple capability groups. Some models are marked "outside China only"; check [agiplan.dev/models](https://agiplan.dev/models) for specifics. It is not an officially authorized channel, and AGI Plan is a commercial partner of cdnping, so please treat this section as one option rather than the only answer.

The steps are: sign up with an email verification code, pick a plan and create a key, then replace the `base_url` and the key behind `env_key` above with the values it gives you. For the API format and what `wire_api` should be, follow its setup guide, available at [agiplan.dev/startup](https://agiplan.dev/startup). You can also view its public availability data at [/en/status/agiplan](/en/status/agiplan).

## What should you do next?

- If you already have an API key: configure it with the `config.toml` example above and run through all 4 verification steps.
- If you have neither a key nor an overseas payment method: read the guide at [agiplan.dev/startup](https://agiplan.dev/startup), judge whether it suits you, then decide.
- If you can't decide between a subscription and pay-as-you-go: read [Which plan to use with Codex](/en/blog/codex-which-plan-to-use) first.
