Agentic AI AcademyAgentic AI Academy

Authentication, Plans & Usage

Sign in with ChatGPT or an API key, and how billing works

Beginner 13 minBuilderDecision-maker
What you'll be able to do
  • Choose between the two Codex authentication modes — Sign in with ChatGPT vs. an API key — and explain the billing and feature implications of each
  • Sign in, check status, and switch methods using codex login, codex login status, and codex logout (including headless and stdin variants)
  • Locate where Codex stores config and credentials, relocate them with CODEX_HOME, and pick a credential store backend
  • Name the ChatGPT plans that include Codex and explain why there is no separate 'Team' plan
  • Explain how usage is metered: one rolling 5-hour window shared by local and cloud, weekly limits on top, and credits when you hit the cap
  • Find the live, authoritative numbers for per-plan limits, the credit rate card, and your own remaining usage
At a glance

Before Codex can write a line of code it has to know who's paying. This lesson gets you signed in the right way — choosing between a ChatGPT account (plan-included usage) and an API key (usage-based billing), learning the login commands and where your credentials live, and understanding the plan list, the shared 5-hour usage window plus weekly limits, and the credit system. Because pricing and limits change month to month, you'll learn the model and where to read the live numbers rather than memorizing values that rot.

  1. 1Two doors into Codex: ChatGPT account or API key
  2. 2Signing in: the login commands
  3. 3Where your config and credentials live
  4. 4Which ChatGPT plans include Codex
  5. 5How usage is metered: one window, weekly caps, then credits
  6. 6Checking your usage and credits

Two doors into Codex: ChatGPT account or API key

You've installed the CLI. The first time you run codex, it stops and asks one question that shapes everything downstream: how do you want to sign in? There are exactly two doors, and they bill in completely different ways.

  • Sign in with ChatGPT — the default and recommended path. Codex opens your browser for an OAuth flow; the browser hands back an access token that Codex caches. Your usage then draws from your ChatGPT plan's included Codex allowance first, and from purchased credits once you exceed it. This is what most people want.
  • Sign in with an API key — uses your OpenAI Platform account at standard, usage-based API token prices. There's no included allowance and no subscription buffer; every call is billed. The docs note that with an API key "some functionality might not be available." It's the right choice for CI/CD and shared automation, where you don't want a personal subscription in the loop.

The mental model: ChatGPT sign-in is a subscription with an allowance; an API key is a metered utility bill. One is tied to your plan, the other to your API org's pricing, retention, and data-sharing settings.

Sign in with ChatGPTSign in with API key
BillingPlan-included allowance, then purchased creditsStandard API token prices, pay-per-use
Best forDay-to-day interactive codingCI/CD, shared/automated workflows
GovernanceChatGPT workspace RBAC, retention, residencyYour API org's retention & data-sharing settings
Feature accessFull"Some functionality might not be available"
Default?Yes (recommended)No (opt in)

Tip

Which door should I pick?

If you're a developer working interactively on your own machine, use Sign in with ChatGPT — you already pay for the plan, so let your included allowance do the work. Reserve the API key path for CI, scripts, and shared runners where a personal subscription doesn't belong.

Signing in: the login commands

On first run, codex walks you through sign-in interactively. But you can also drive auth explicitly — essential for headless boxes and automation. Here is the toolkit:

CommandWhat it does
codex loginDefault. Opens the browser for the ChatGPT OAuth sign-in.
codex login --with-api-keyReads an OpenAI API key from stdin and stores it.
codex login --with-access-tokenReads a ChatGPT/Codex access token from stdin (enterprise / automation).
codex login --device-authOAuth device-code flow for headless / no-browser environments.
codex login statusPrints the active auth mode; exits 0 when logged in (handy in scripts).
codex logoutRemoves saved credentials.

Notice the stdin-based variants — they exist so a key never has to appear in your shell history or a process list. Pipe it in instead:

bash
# API key from an environment variable, non-interactively
printenv OPENAI_API_KEY | codex login --with-api-key

# enterprise access token for trusted automation
printenv CODEX_ACCESS_TOKEN | codex login --with-access-token

There's no "switch account" command. To move between the two doors you log out and log back in with the method you want: codex logout, then codex login (ChatGPT) or codex login --with-api-key (API). When no valid session exists, Sign in with ChatGPT is the default.

Watch out

Never paste keys on the command line

Avoid codex login --with-api-key sk-... style invocations. Anything on the command line lands in shell history and is visible to other processes via the process list. Always pipe the secret in over stdin as shown above.

Tip

Headless and CI sign-in

No browser on the box? Use codex login --device-auth for the device-code flow, or seed a credentials file from a secret. codex login status returning exit 0 is the clean way for a CI step to assert it's authenticated before doing real work.

Where your config and credentials live

Codex keeps all of its state under one home directory, and it's worth knowing exactly where — both to back it up and to keep it out of places it shouldn't be.

  • Config directory: ~/.codex/ — the root for config, auth, logs, sessions, and skills.
  • Config file: ~/.codex/config.toml (covered in depth in a later lesson).
  • Credentials (file mode): ~/.codex/auth.json — a plaintext file containing access tokens. Treat it exactly like a password: never commit it, paste it into a ticket, or share it.
  • Relocate everything by setting the CODEX_HOME environment variable. Point it elsewhere and config, auth, logs, and sessions all move with it.

Because auth.json is plaintext by default, Codex lets you choose a safer backend with the config key cli_auth_credentials_store:

toml
# in ~/.codex/config.toml
cli_auth_credentials_store = "keyring"   # file | keyring | auto
ValueBehavior
"file"Store tokens in ~/.codex/auth.json (plaintext).
"keyring"Store in the OS credential store (Keychain, etc.).
"auto"Use the OS store if available, else fall back to auth.json.

A few auth-relevant environment variables round this out: CODEX_HOME (the state root), CODEX_API_KEY (provides a key for a single non-interactive run — and is honored only by codex exec), and CODEX_ACCESS_TOKEN (an access token for trusted automation). One subtlety worth flagging: whether a plain OPENAI_API_KEY auto-authenticates the interactive CLI — and how it would rank against a stored auth.json — is not confirmed in the env-var docs. Don't rely on it; sign in explicitly.

Watch out

auth.json is a password in a file

In file mode, ~/.codex/auth.json holds plaintext access tokens. Add it to your global gitignore, never commit it, and prefer cli_auth_credentials_store = "keyring" (or "auto") on machines where an OS credential store is available.

Which ChatGPT plans include Codex

Codex is bundled into the ChatGPT subscription you already have. As of June 2026 it's included in Free, Go, Plus, Pro, Business, Edu, and Enterprise plans, plus the separate API-key path for shared/CI environments.

Three things newcomers get wrong:

  1. Free does include Codex. Some older marketing copy omitted it, but the current pricing page lists Free explicitly — at $0/month it's limited (quick exploration), but it's real.
  2. There is no separate "Team" plan. "Team" was the prior name for the business tier; the current business-tier name is Business. If a guide tells you to pick "Team," it's out of date.
  3. Higher plans buy more usage, not different features. Plus and Pro who hit their limits can buy additional credits without upgrading; Business/Edu/Enterprise on flexible pricing can buy workspace credits.

The exact plan roster and what each tier includes is volatile — confirm the live list and inclusions at the pricing page before quoting it to anyone.

Note

Plan list is volatile

Plan names, inclusions, and tiers shift over time (Team → Business is one example). Read the current roster live at https://developers.openai.com/codex/pricing rather than trusting any hard-coded list — including this one.

How usage is metered: one window, weekly caps, then credits

Here's the part that confuses people, so let's make it concrete. Under ChatGPT sign-in, your usage is governed by time windows, not a per-message counter.

  • One rolling 5-hour window. Critically, local messages (CLI/IDE on your machine) and cloud tasks share the same five-hour window — there's no separate local-only allowance. Burn through it in the terminal and your cloud tasks feel it too. The official wording: "The usage limits for local messages and cloud tasks share a five-hour window. Additional weekly limits may apply."
  • Weekly limits sit on top. The pricing page only says "additional weekly limits may apply" and publishes no weekly numbers. In practice, users report the weekly cap is the real bottleneck — the thing you hit before the 5-hour window after several heavy sessions.
  • Credits when you hit the cap. Since April 2, 2026, Codex bills on token-based pricingcredits per 1M input / cached-input / output tokens — rather than per-message. Codex, ChatGPT for Excel, and Workspace Agents all draw from one shared agentic usage limit pool. The credit-to-dollar anchor is stable enough to state: 1 credit = $0.04 (so 2,500 credits = $100).
  • What happens at the cap. Plus/Pro get an add-credits prompt and continue without upgrading (or enable Auto top-up at Codex Settings → Usage); Free/Go are prompted to upgrade to Plus. Purchased credits are valid 12 months and don't roll over.

Notice what's stable here versus what rots. The structure — shared 5-hour window, weekly caps on top, credits at the cap, $0.04/credit, 12-month expiry — is durable. The exact numbers — per-plan 5-hour limits, the weekly caps, the per-model credit rate card — are volatile and will be wrong next month. Teach yourself the structure; look up the numbers live.

Key insight

Local and cloud share one bucket

The single most counterintuitive rule: your local CLI/IDE messages and your background cloud tasks draw from the same 5-hour window and the same agentic-usage pool. There is no separate local allowance to fall back on when cloud runs out, or vice versa.

Watch out

Don't hard-code the limit numbers

Per-plan 5-hour limits, weekly caps, and the credit rate card change frequently and aren't always fully published. Cite the live pricing page and your own usage page; treat any specific number in a tutorial (including older ones) as a snapshot, not gospel.

Checking your usage and credits

Because the numbers move, the skill that actually matters is knowing where to look for your current state:

  • /status in the CLI — type it mid-session for a quick read of your active model and remaining usage. It's intentionally minimal; a 2026 snapshot looks like gpt-5.4 high · 100% left · ~. A richer progress-bar view (separate 5-hour and weekly bars with reset times) has been proposed but isn't the default — treat fancy examples from blog posts as aspirational.
  • The web usage page — the authoritative live view of your 5-hour and weekly limits, plus credits and Auto top-up, lives at https://chatgpt.com/codex/settings/usage (Codex Settings → Usage). Buy credits at Codex Settings → Usage → Credits.
  • Enterprise/admin analytics — workspace admins can query the Analytics API at https://api.chatgpt.com/v1/analytics/codex (endpoints like /usage, /code_reviews) with a Platform API key.

For the canonical, current numbers — the per-plan 5-hour limits, the credit rate card (credits per 1M tokens by model), and the API USD token prices — the live sources are https://developers.openai.com/codex/pricing, the help-center rate card, and https://developers.openai.com/api/docs/pricing. Bookmark those three; they're the ground truth.

Example

A quick self-check loop

Mid-task and worried you're close to a cap? Run /status for the at-a-glance read, then open https://chatgpt.com/codex/settings/usage in a browser for the authoritative 5-hour and weekly picture before you decide whether to add credits or switch to a cheaper model.

Try it: Sign in, inspect your auth, and find your live limits

Goal: get authenticated the right way and learn to read your own current numbers instead of trusting a tutorial. 1) Sign in. Run codex (or codex login) and complete the Sign in with ChatGPT browser flow. 2) Verify it. Run codex login status and confirm it reports your auth mode and exits 0 (echo $? right after on macOS/Linux). 3) Inspect where state lives. Look at your ~/.codex/ directory and note that config.toml and auth.json are there — but do not print or share the contents of auth.json; it holds plaintext tokens. 4) (Optional) Harden it. Add cli_auth_credentials_store = "keyring" (or "auto") to ~/.codex/config.toml if your OS has a credential store. 5) Check your usage. Inside a codex session, run /status and read your model + remaining usage. Then open https://chatgpt.com/codex/settings/usage in a browser and compare — note the 5-hour window and any weekly limit. 6) Find the live rate card. Open https://developers.openai.com/codex/pricing, locate your plan's 5-hour limits and the per-model credit rate, and write down today's numbers with the date — proving to yourself they're a snapshot, not a constant. 7) Reflect (3 sentences): which auth door did you pick and why, what does your 5-hour vs. weekly limit look like right now, and where will you look next month when these numbers have changed?

Key takeaways

  1. 1Codex has two sign-in doors: ChatGPT account (default; plan-included allowance then credits) and API key (usage-based, best for CI). With an API key, 'some functionality might not be available.'
  2. 2Drive auth with codex login (--with-api-key / --with-access-token via stdin, --device-auth for headless), codex login status (exits 0 when logged in), and codex logout; switch methods by logging out and back in.
  3. 3Config and credentials live under ~/.codex/ (config.toml, auth.json); relocate with CODEX_HOME, and choose a credential store via cli_auth_credentials_store = file | keyring | auto. auth.json is plaintext — treat it like a password.
  4. 4Codex is included in Free, Go, Plus, Pro, Business, Edu, and Enterprise plans — there is no separate 'Team' plan, and Free is limited but real.
  5. 5Usage is metered by a rolling 5-hour window shared by local messages AND cloud tasks, with weekly limits on top; at the cap you buy credits (1 credit = $0.04, valid 12 months, no roll-over) — Plus/Pro add credits, Free/Go upgrade.
  6. 6Per-plan limits, the credit rate card, and weekly caps are volatile — read them live at developers.openai.com/codex/pricing and your own usage page (chatgpt.com/codex/settings/usage); use /status for a quick in-CLI check.

Quiz

Lock in what you learned

Check your understanding

0 / 4 answered

1.You're setting up Codex on a shared CI runner that builds pull requests automatically. Which authentication path fits best, and why?

2.A teammate wants to store an API key without it appearing in their shell history or process list. What's the correct way to sign in?

3.Which statement about how Codex meters ChatGPT-plan usage is correct?

4.You need the authoritative, current per-plan 5-hour limits and your own remaining usage right now. Where do you look?

Go deeper

Hand-picked sources to keep learning