OAuth Setup Guide
This guide explains how to set up OAuth authentication for various AI providers in llxprt-code.
Overview
llxprt-code supports OAuth 2.0 authentication for multiple providers:
- Gemini (Google AI) - Browser-based OAuth flow
- Anthropic - Authorization code via dialog
- OpenAI (Codex) - Browser-based OAuth flow for ChatGPT Plus/Pro subscribers
- Qwen (Alibaba Cloud) - Device code flow
OAuth provides secure authentication without requiring API keys, offering better security and user experience.
Important: All OAuth authentication is lazy - the authentication flow only starts when you make your first API request to the provider, not when you enable OAuth.
Authentication Precedence
The system uses the following authentication precedence (highest to lowest):
- Command line API key (
--key/--keyfileflags or--set auth-key=...) - Profiles / settings files (values saved via
/profile saveorsettings.json) - Environment variables (
OPENAI_API_KEY,GEMINI_API_KEY, etc.) - OAuth tokens (stored securely in
~/.llxprt/oauth/)
Setting Up OAuth
Using the Auth Command
The /auth command manages OAuth authentication for all providers:
# Show OAuth authentication menu/status
/auth
# Enable OAuth for a provider (authentication happens on first use)
/auth gemini enable
/auth anthropic enable
/auth codex enable
/auth qwen enable
# Disable OAuth for a provider
/auth gemini disable
/auth anthropic disable
/auth codex disable
/auth qwen disable
# Log out from a provider (clears stored tokens)
/auth gemini logout
/auth anthropic logout
/auth codex logout
/auth qwen logout
Gemini OAuth Setup
-
Enable OAuth for Gemini:
/auth gemini enable -
Make your first request to Gemini (e.g., send a message)
-
Browser will open automatically for authentication
-
Grant permissions to llxprt-code
-
Authentication complete!
Anthropic OAuth Setup
-
Enable OAuth for Anthropic:
/auth anthropic enable -
Make your first request to Anthropic
-
A dialog will appear asking for your authorization code
-
Go to https://console.anthropic.com/settings/oauth to get your code
-
Paste the code into the dialog
-
Authentication complete!
OpenAI Codex OAuth Setup (ChatGPT Plus/Pro)
If you have a ChatGPT Plus or Pro subscription, you can authenticate using OAuth:
-
Enable OAuth for OpenAI:
/auth codex enable -
Make your first request to OpenAI
-
Browser will open to ChatGPT login page
-
Sign in with your ChatGPT Plus/Pro account
-
Authorize llxprt-code to access your account
-
Authentication complete!
Note: This requires an active ChatGPT Plus ($20/month) or Pro subscription. For pay-per-token API access, use API keys instead.
Qwen OAuth Setup
-
Enable OAuth for Qwen:
/auth qwen enable -
Make your first request to Qwen
-
You'll see a device code and URL (device code flow):
Device code: ABC-DEF-123 Visit: https://oauth.qwen.alibaba.com/device Enter code: ABC-DEF-123 -
Open the URL in your browser
-
Enter the device code when prompted
-
Grant permissions to llxprt-code
-
Authentication completes automatically
Multi-Provider Authentication
You can enable OAuth for multiple providers simultaneously:
/auth gemini enable # Enable Gemini OAuth
/auth anthropic enable # Enable Anthropic OAuth
/auth codex enable # Enable OpenAI Codex OAuth
/auth qwen enable # Enable Qwen OAuth
Each provider:
- Stores tokens separately and securely
- Authenticates lazily on first use
- Maintains independent authentication state
Authentication Status
Check your current authentication status:
/auth
This shows:
- ✓ Authenticated providers with expiry time
- ✗ Unauthenticated providers
- Auth method (oauth, api-key, etc.)
Token Management
Token Storage
OAuth tokens are stored as plain JSON files:
- Location:
~/.llxprt/oauth/ - Files:
gemini.json- Gemini OAuth tokensanthropic.json- Anthropic OAuth tokenscodex.json- OpenAI Codex OAuth tokensqwen.json- Qwen OAuth tokens
- Permissions:
0600(user read/write only) - Note: Tokens are stored as plain text JSON files. For enhanced security in production environments, consider using system keychains or encrypted storage.
Automatic Refresh
Tokens are automatically refreshed when:
- They expire within 30 seconds
- An API call is made with an expired token
- The system detects token expiration
Manual Token Removal
To remove a provider's OAuth token:
rm ~/.llxprt/oauth/{provider}.json
Troubleshooting
Authentication Timeout
Different providers have different timeout behaviors:
- Gemini: No timeout - browser flow waits for user
- Anthropic: Dialog waits indefinitely for code input
- OpenAI: No timeout - browser flow waits for user
- Qwen: Device flow has polling timeout (typically 5-15 minutes)
- Solution: Complete authentication promptly after initiating
Token Refresh Issues
If token refresh fails:
- Re-authenticate: Run
/auth {provider}again - Check: Provider service status
- Verify: Network connectivity
Permission Errors
If you see file permission errors:
# Fix OAuth directory permissions
chmod 700 ~/.llxprt/oauth/
chmod 600 ~/.llxprt/oauth/*.json
Browser Issues
For browser-related problems:
- Manual URL: Copy the OAuth URL and open manually
- Different Browser: Try a different browser
- Private Mode: Use incognito/private browsing mode
Security Considerations
Token Security
- Tokens are stored with
0600permissions (user-only access) - No tokens are logged or displayed in plain text
- Automatic refresh minimizes token exposure time
OAuth vs API Keys
OAuth provides better security than API keys:
- Scoped Access: Limited to specific operations
- Revocable: Can be revoked from provider console
- Temporary: Automatic expiration and refresh
- No Secrets: No long-lived credentials in files
Best Practices
- Regular Cleanup: Remove unused provider tokens
- Secure Storage: Keep
~/.llxprt/directory secure - Monitor Access: Review OAuth grants in provider consoles
- Use OAuth: Prefer OAuth over API keys when available
Migration Guide
From API Keys to OAuth
If you're currently using API keys:
- Current Setup: API keys continue to work
- Add OAuth: Run
/auth {provider}for OAuth setup - Precedence: API keys take precedence over OAuth
- Remove API Keys: Unset environment variables to use OAuth
- Test: Verify functionality with OAuth
Example migration:
# Before: Using API key
export OPENAI_API_KEY="sk-..."
# Add OAuth (optional)
/auth qwen
# Remove API key to use OAuth
unset OPENAI_API_KEY
# Verify OAuth is working
/auth # Should show qwen as authenticated
Existing Gemini Users
If you already have Gemini OAuth:
- No Changes: Existing Gemini OAuth continues working
- Add Qwen: Run
/auth qwento add Qwen support - Multi-Provider: Both providers work simultaneously
- Cross-Compatible: Use Qwen content with Gemini tools
Command Reference
| Command | Description |
|---|---|
/auth |
Show OAuth authentication menu/status |
/auth <provider> enable |
Enable OAuth for provider |
/auth <provider> disable |
Disable OAuth for provider |
/auth <provider> logout |
Clear OAuth tokens for provider |
Supported providers: gemini, anthropic, codex, qwen
File Locations
| File/Directory | Purpose |
|---|---|
~/.llxprt/oauth/ |
OAuth token storage directory |
~/.llxprt/oauth/gemini.json |
Gemini OAuth tokens |
~/.llxprt/oauth/anthropic.json |
Anthropic OAuth tokens |
~/.llxprt/oauth/codex.json |
OpenAI Codex OAuth tokens |
~/.llxprt/oauth/qwen.json |
Qwen OAuth tokens |
Support
For additional help:
- Documentation: Check
/docscommand in llxprt-code - Issues: Report problems on GitHub
- Provider Support: Contact provider for OAuth service issues