Authentication Methods
| Method | Description | When to Use |
|---|---|---|
| API Key | Environment variable in .env (e.g., OPENAI_API_KEY) | Programmatic access, CI/CD, platform API keys |
| OAuth (interactive login) | /auth login command in the terminal | ChatGPT Plus/Codex plans, Claude Pro, no key management |
Both methods can coexist. ChatCLI prioritizes OAuth credentials when both are available.
/auth Commands
All authentication commands have auto-completion — just type /auth and press Tab.
View Status
Login via OAuth
Authorize access
OpenAI: a local HTTP server captures the callback automatically (port 1455).Anthropic: after authorizing, copy the code displayed on the page and paste it in the terminal.GitHub Copilot: enter the device code displayed in the terminal on the GitHub page.
Supported Providers
| Provider | Command | Compatible Plans |
|---|---|---|
| OpenAI | /auth login openai-codex | ChatGPT Plus, Codex, Team, Enterprise |
| Anthropic | /auth login anthropic | Claude Pro, Team |
| GitHub Copilot | /auth login github-copilot | Copilot Individual, Business, Enterprise |
Logout
Complete Flow: From Zero to First Prompt
If you are starting without any configured credentials, follow these steps:Automatic Endpoint Routing (OpenAI)
ChatCLI automatically detects the credential type and routes requests to the correct endpoint:| Credential | Endpoint | API Format |
|---|---|---|
OPENAI_API_KEY | api.openai.com/v1/responses | Responses API (default) |
OPENAI_API_KEY | api.openai.com/v1/chat/completions | Chat Completions (legacy models) |
OAuth (/auth login) | chatgpt.com/backend-api/codex/responses | Responses API (streaming SSE) |
Credential Storage
OAuth credentials are saved with AES-256-GCM encryption at:~/.chatcli/.auth-key (permission 0600). Unencrypted data from previous versions is transparently migrated on first read.
The file contains access tokens, refresh tokens, and metadata for each provider. Tokens are automatically renewed when they expire.
To customize the storage directory, set the environment variable:
Advanced Configuration
| Variable | Description |
|---|---|
CHATCLI_OPENAI_CLIENT_ID | Allows overriding the OpenAI OAuth client ID |
CHATCLI_COPILOT_CLIENT_ID | Allows overriding the GitHub Copilot Device Flow client ID (default: Ov23lifEydOk2Non90tJ) |
COPILOT_API_BASE_URL | Copilot API base URL for enterprise environments (default: https://api.githubcopilot.com) |
Troubleshooting
Authentication error when clicking the OAuth link (OpenAI)
Authentication error when clicking the OAuth link (OpenAI)
Check that the callback port is not in use by another application. The OpenAI callback server needs port 1455 to capture the return.
Code does not appear after authorizing (Anthropic)
Code does not appear after authorizing (Anthropic)
Provider does not appear in /switch after login
Provider does not appear in /switch after login
Run
/auth status to verify that the token was saved correctly. If needed, try /auth logout <provider> followed by /auth login <provider>.GitHub Copilot: authorization denied by user
GitHub Copilot: authorization denied by user
Expired token
Expired token
OAuth tokens are automatically renewed using the refresh token. If the refresh fails, log in again with
/auth login.GitHub Copilot tokens (Device Flow) do not expire and do not have a refresh token — they are persistent until manually revoked.Next Steps
Command Reference
Complete list of all available commands.
Configuration (.env)
All available environment variables.
Basic Usage
Learn the fundamentals of ChatCLI.