← Home

Guide

OpenClaw Codex OAuth: Sign In With ChatGPT Instead of an API Key

OpenClaw can authenticate with OpenAI Codex using OAuth — a “Sign in with ChatGPT” device-code flow — instead of pasting an API key. That lets your agent draw on your existing ChatGPT plan rather than billing tokens to a separate API account. Here's how it works.

OAuth vs API Key for Codex

There are two ways to give OpenClaw access to OpenAI Codex models:

  • API key (BYOK) — you paste an sk-... key from the OpenAI platform and pay per token through the standard API. Covered in OpenClaw Codex.
  • OAuth (Sign in with ChatGPT) — you authenticate with your ChatGPT account through a device-code flow. No key to copy, and usage draws on your ChatGPT plan's included Codex access instead of a separate per-token API bill.

OAuth is the better fit if you already pay for ChatGPT (Plus, Pro, Team, or Business) and want your agent to use that subscription. If you specifically want to use a Codex Pro subscription, see OpenClaw + Codex Pro.

How the Device-Code OAuth Flow Works

Codex uses an OAuth device-code flow, the same pattern many CLIs use to log in without a browser redirect on the server:

  1. OpenClaw starts the login and shows a short code plus a verification URL.
  2. You open the URL in any browser, sign in to ChatGPT, and enter the code.
  3. Once you approve, OpenAI issues OAuth tokens back to OpenClaw, which stores them as an auth profile. The agent can now call Codex models without an API key.

The tokens are refreshed automatically, so you normally only do this once per account.

Codex OAuth on OpenClaw Launch (Easiest)

On OpenClaw Launch, the whole flow is handled from the dashboard — no terminal required:

  1. Open the API Keys page in your dashboard.
  2. Choose Sign in with ChatGPT for Codex and complete the device-code login in the popup.
  3. Pick a model under the openai-codex/* family in the model dropdown.
  4. Deploy or restart your instance — your agent now uses Codex over OAuth.
Note: the API Keys dashboard is the source of truth on OpenClaw Launch. The orchestrator syncs what's saved there into your instance, so manage Codex auth from /api-keys rather than editing the container config by hand — manual edits get re-synced away.

Self-Hosted: Where Codex OAuth Credentials Live

On a self-hosted OpenClaw install, the “Sign in with ChatGPT” login is run through the gateway, and the resulting OAuth profile is written under your agent's auth directory (an auth-profiles.json under agents/<agent>/agent/), not as a plaintext key in openclaw.json. Once the profile exists, point your default agent at a Codex model:

{
  "agents": {
    "defaults": {
      "model": {
        "primary": "openai-codex/gpt-5.5"
      }
    }
  }
}

Because the credential is an OAuth profile rather than an API key, you authenticate through the sign-in flow rather than setting a key in the config file. Confirm upstream behavior on the OpenClaw GitHub repository if you need exact command names for your version.

Troubleshooting Codex OAuth

“Re-authentication required” or the agent stops responding on Codex

OAuth tokens can expire or be revoked (for example, after a password change or a long idle period). Re-run the Sign in with ChatGPT flow — on OpenClaw Launch, just re-do it from the API Keys page.

Rate limits or weekly caps

OAuth usage draws on your ChatGPT plan's limits, which include a weekly cap on Codex usage. If you hit it, either wait for the window to reset, switch to a model on another provider, or add an API key as a fallback. Running OpenClaw with multiple paired accounts or a BYOK fallback avoids hard stops mid-session.

Wrong account signed in

Sign out and re-run the flow with the account whose plan you want to use. Make sure the browser you complete the device code in is logged into the correct ChatGPT account.

OAuth vs API Key: Which Should You Use?

Use OAuth if…Use an API key if…
You already pay for ChatGPT and want to use that planYou want metered, per-token billing on a separate account
You don't want to manage or rotate keysYou need high, predictable throughput without weekly caps
You want the simplest login on OpenClaw LaunchYou're scripting or want a key you can revoke independently

What's Next?

Use Codex with OpenClaw

Sign in with ChatGPT and deploy a Codex-powered AI agent in about 30 seconds.

Deploy Now