Authentication Methods
Codex-LB supports two OAuth 2.0 flows:Browser Flow (PKCE)
The browser flow uses OAuth 2.0 with PKCE (Proof Key for Code Exchange) and is recommended for most users. This method opens a browser window where you complete the sign-in process. Best for:- Desktop environments
- Interactive setups
- Users with browser access
Device Code Flow
The device code flow is designed for headless or remote environments where opening a browser isn’t feasible. You’ll receive a code to enter on another device. Best for:- Headless servers
- SSH sessions
- Containerized deployments
- Remote access scenarios
Adding an Account via OAuth
1
Open the OAuth Dialog
In the Codex-LB dashboard, navigate to the Accounts section and click “Add Account” to open the OAuth dialog.
2
Select Authentication Method
Choose your preferred authentication method:
- Browser (PKCE): Opens a browser window for sign-in. Recommended for most users.
- Device code: Use a code on another device. Useful for headless environments.
3
Complete Authorization
Browser Flow
- Click “Start sign-in” to initiate the OAuth flow
- A browser window will open with the authorization URL
- Sign in with your ChatGPT credentials
- Grant the requested permissions
- You’ll be redirected to the callback URL
- The dashboard will automatically detect the successful authorization
http://127.0.0.1:1455/auth/callback by default. Ensure this port is available.Device Code Flow
- Click “Start sign-in” to initiate the device flow
-
Copy the user code displayed in the dialog (e.g.,
ABCD-EFGH) - Open the verification URL on any device with a browser
- Enter the user code when prompted
- Complete sign-in with your ChatGPT credentials
- The dashboard will automatically poll for completion
4
Verify Account Status
Once authorization is complete, the account will appear in your accounts list with status
active. You can verify:- Account email
- Plan type (free, plus, team, enterprise)
- Last refresh timestamp
- Current usage statistics
Account Information
When you add an account via OAuth, Codex-LB stores:- Account ID: A unique identifier generated from your ChatGPT account ID and email
- Email: Your ChatGPT account email
- Plan Type: Your subscription tier (free, plus, team, enterprise)
- Tokens: Encrypted access, refresh, and ID tokens
- Status: Account status (active, rate_limited, quota_exceeded, paused, deactivated)
Importing via auth.json
Alternatively, you can import accounts using anauth.json file:
1
Obtain auth.json
Export your ChatGPT authentication tokens to an
auth.json file. This file should contain:2
Upload to Dashboard
- Navigate to the Accounts section
- Click “Import Account”
- Select your
auth.jsonfile - Click “Upload”
3
Verify Import
The account will be added with status
active if the import succeeds. Check for any error messages if the import fails.Account Status Transitions
After adding an account, it can transition between different states:
See Troubleshooting for handling status issues.
Automatic Token Refresh
Codex-LB automatically refreshes access tokens when they expire. The refresh process:- Detects expired or near-expired access tokens
- Uses the refresh token to obtain new credentials
- Updates stored tokens with encryption
- Continues serving requests without interruption
- The refresh token has expired
- Account credentials have been revoked
- Network connectivity issues
deactivated.
Security Considerations
- Tokens are stored encrypted in the database
- OAuth flows use PKCE for additional security
- Callback URLs are validated to prevent CSRF attacks
- Device codes expire after a short time window
Troubleshooting
OAuth flow fails with “OAuth error: access_denied”
Cause: User denied authorization or session expired. Solution: Restart the OAuth flow and grant the required permissions.Browser flow shows “Invalid OAuth callback state”
Cause: State token mismatch, possibly due to session timeout or CSRF attack attempt. Solution:- Close the OAuth dialog
- Start a new OAuth flow
- Complete authorization within the time window
- Ensure cookies are enabled
Device code expired before completion
Cause: The device code has a limited validity period (typically 10-15 minutes). Solution: Start a new device code flow and complete authorization faster.Account shows as deactivated after adding
Cause: Token validation failed or account credentials were revoked. Solution:- Remove the account from the dashboard
- Add it again via OAuth with fresh credentials
- Verify your ChatGPT account is in good standing
Duplicate identity conflict error
Cause: An account with the same ChatGPT account ID and email already exists. Solution: The existing account will be updated with new tokens instead of creating a duplicate.Next Steps
Managing API Keys
Create API keys to access your load balancer
Rate Limiting
Configure rate limits for your accounts