Codex OAuth with OpenClaw
Use your ChatGPT/Codex subscription instead of a pay-as-you-go API key
Use your ChatGPT/Codex subscription instead of a pay-as-you-go API key
OpenClaw can call OpenAI models through an API key or through OAuth tied to a ChatGPT/Codex subscription. OAuth is attractive when you already pay for Codex and do not want a separate metered key—but routing and recovery steps matter, especially after upgrades.
This tutorial focuses on the openai-codex provider path. For general OpenAI setup, see OpenAI provider guide. Exact flags live in official OpenAI provider docs.
From a terminal on the Gateway host:
openclaw models auth login --provider openai-codex
Complete the browser sign-in. Tokens are stored in your agent auth profiles (see official OAuth concepts).
Alternatively, run openclaw onboard and choose OpenAI/Codex OAuth when prompted (configuration).
Your default model should use the openai-codex/ route namespace—not a stale API-key profile. After onboarding, check ~/.openclaw/openclaw.json (or use Control UI) for the active model id.
Smoke test in WebChat or a paired channel:
openclaw gateway start
openclaw doctor
Send a short message. If you get auth errors, continue to troubleshooting below.
Some releases rewrote Codex routes when users ran openclaw doctor --fix. After upgrading, if Codex stopped working:
openclaw models auth login --provider openai-codex if tokens expired.openclaw security audit --deep—auth changes sometimes surface stale bind or auth modes.| Approach | Good for | Watch out for |
|---|---|---|
| Codex OAuth | Personal use with existing ChatGPT/Codex sub | Subscription limits; routing drift after doctor |
| API key | Teams, automation, precise billing | Pay-as-you-go; rotate keys if leaked |
| Symptom | Likely cause | Fix |
|---|---|---|
| 401 / invalid token | Expired OAuth | Re-login with models auth login |
| Wrong model family | API profile still default | Switch default to openai-codex/*; remove duplicate auth |
| Works in CLI, not in channel | Different workspace/profile | openclaw doctor; one Gateway host |
Coding-agent comparison (OpenClaw assistant vs Claude Code product): OpenClaw vs Claude Code.