Syntax
Description
Thelogin command authenticates Codex with OpenAI. You can sign in with your ChatGPT account (recommended) or provide an API key.
We recommend signing in with ChatGPT to use Codex as part of your Plus, Pro, Team, Edu, or Enterprise plan. Learn more about ChatGPT plans.
Usage
Sign In with ChatGPT (Recommended)
Sign In with Device Code
If you can’t open a browser, use device code authentication:Sign In with API Key
Provide an API key from stdin:Check Login Status
View your current authentication status:Options
Use device code authentication instead of browser-based login. Shows a code to enter at a URL.
Read an API key from stdin instead of using ChatGPT authentication.
Advanced OAuth Options
Custom OAuth issuer base URL. Advanced use only.
This is an experimental flag for custom deployments.
Custom OAuth client ID. Advanced use only.
This is an experimental flag for custom deployments.
Examples
Standard Login Flow
Device Code Flow
API Key from Environment
Verify Authentication
CI/CD Authentication
For automation, use API keys:Authentication Methods
ChatGPT OAuth (Recommended)
Pros:- Uses your existing ChatGPT subscription
- No additional billing
- Includes plan features (Plus, Pro, Team, etc.)
- Run
codex login - Browser opens to ChatGPT
- Sign in and authorize
- Credentials stored securely
Device Code
When to use:- Remote servers without browser access
- Terminal-only environments
- Restricted network access
- Run
codex login --device-auth - Get a device code
- Visit URL in any browser
- Enter code
- Credentials stored
API Key
When to use:- CI/CD pipelines
- Automation scripts
- Separate billing requirements
- Get API key from OpenAI Platform
- Pipe to
codex login --with-api-key - Key stored securely
Credential Storage
Codex stores credentials securely using your system’s keychain:- macOS: Keychain Access
- Linux: Secret Service API (gnome-keyring, KWallet)
- Windows: Windows Credential Manager
cli_auth_credentials_store setting in config.toml.
Troubleshooting
Browser Doesn’t Open
Use device code authentication instead:“Invalid API Key” Error
Ensure your API key:- Starts with
sk-proj-orsk- - Has not expired
- Has correct permissions
- Is from OpenAI Platform
Credentials Not Persisting
Check credential storage configuration:~/.codex/config.toml:
Related Commands
codex logout- Remove stored credentials