Creating an API Key
1
Navigate to API Keys
In the Codex-LB dashboard, go to the API Keys section.
2
Configure Key Settings
Click “Create API Key” and configure:Basic Settings
- Name: A descriptive name for the key (e.g., “Production App”, “Development”, “QA Testing”)
- Allowed Models: Optional list of models this key can access (leave empty for all models)
- Expiration: Optional expiration date for automatic key rotation
3
Copy the API Key
After creation, the full API key will be displayed once. Copy and store it securely.
4
Use the API Key
Include the API key in your requests using the
Authorization header:API Key Properties
Name
A human-readable identifier for the key. Use descriptive names to easily identify keys:production-web-appmobile-app-iosstaging-environmentteam-dev-testing
Key Format
All Codex-LB API keys follow the format:- Prefix:
sk-clb-identifies the key as a Codex-LB API key - Token: 32-character URL-safe random string
- Storage: Keys are hashed using SHA-256 before storage
Key Prefix
The dashboard displays only the first 15 characters of each key for identification:Allowed Models
Restrict which models an API key can access:- Leave empty or
nullto allow all models - Requests for non-allowed models will return
403 Forbidden - Model names must match exactly (case-sensitive)
Expiration
Set an expiration date for automatic key rotation:- Expired keys return
401 Unauthorized - Set to
nullfor keys that never expire - Use expiration for temporary access or security policies requiring rotation
Active Status
Keys can be enabled or disabled:- Active (
is_active: true): Key can authenticate requests - Inactive (
is_active: false): Key is disabled and returns401 Unauthorized
Managing Existing Keys
Viewing API Keys
The API keys list shows:- Key name
- Key prefix (first 15 characters)
- Active status
- Allowed models (if configured)
- Expiration date (if set)
- Created date
- Last used timestamp
- Current usage for each limit
Updating an API Key
You can update most key properties:1
Select the Key
Click on the key you want to modify in the API Keys list.
2
Edit Properties
Modify any of the following:
- Name
- Allowed models
- Expiration date
- Active status
- Rate limits (add, remove, or modify)
3
Save Changes
Click “Save” to apply changes. The key itself (token) remains unchanged.
Regenerating an API Key
Regenerate a key to create a new token while keeping the same configuration:1
Select the Key
Navigate to the key you want to regenerate.
2
Regenerate
Click “Regenerate” and confirm the action.
3
Copy New Key
Copy the new API key and update your applications.The key configuration (name, limits, expiration) remains the same, but a new token is generated.
Deactivating an API Key
Temporarily disable a key without deleting it:- Investigating suspicious activity
- Temporarily revoking access
- Compliance requirements
- Testing fallback behavior
is_active: true.
Deleting an API Key
Permanently remove an API key:1
Select the Key
Navigate to the key you want to delete.
2
Delete
Click “Delete” and confirm the action.
3
Update Applications
Update any applications using the deleted key with a new API key.
Rate Limits
API keys support granular rate limiting. See the Rate Limiting guide for detailed information.Limit Types
- Total Tokens: Combined input and output tokens
- Input Tokens: Prompt tokens only
- Output Tokens: Completion tokens only
- Cost (USD): Total cost in microdollars
Limit Windows
- Daily: Resets every 24 hours
- Weekly: Resets every 7 days
- Monthly: Resets every 30 days
Model-Specific Limits
Apply different limits for different models:Usage Tracking
Real-Time Usage
Each API key displays current usage for all configured limits:Last Used Timestamp
Track when each key was last used:last_used_at: Timestamp of the most recent successful request- Updated asynchronously after request completion
- Useful for identifying unused keys
Resetting Usage
Manually reset usage counters:current_value fields to 0 and updates reset_at timestamps.
Authentication Flow
When a request arrives with an API key:1
Extract Key
Codex-LB extracts the API key from the
Authorization: Bearer {key} header.2
Validate Key
The key is hashed and looked up in the database:
- Check if key exists
- Check if key is active (
is_active: true) - Check if key has expired (
expires_at > now) - Check if requested model is allowed
3
Check Rate Limits
For each configured limit:
- Check if limit applies to the requested model
- Check if current usage is below max value
- Reserve usage quota for the request
- Update
last_used_attimestamp
4
Process Request
If all checks pass, the request is forwarded to the upstream ChatGPT API.After the request completes, actual token usage is calculated and limits are updated.
Error Responses
Invalid API Key
401 Unauthorized
Causes:
- Key doesn’t exist
- Key is inactive
- Key has expired
- Invalid key format
Model Not Allowed
403 Forbidden
Cause: Requested model not in allowed_models list.
Rate Limit Exceeded
429 Too Many Requests
Headers:
Security Best Practices
Key Management
- Rotate keys regularly: Set expiration dates and rotate before they expire
- Use environment variables: Store keys in environment variables, not in code
- Separate keys per environment: Use different keys for dev, staging, and production
- Monitor usage: Review
last_used_atto identify unused or compromised keys - Revoke compromised keys: Immediately delete or deactivate any exposed keys
Access Control
- Principle of least privilege: Grant minimum necessary access (models, limits)
- Model restrictions: Limit expensive models to production keys only
- Rate limits: Set appropriate limits based on expected usage
- Expiration dates: Use temporary keys for contractors or testing
Monitoring
- Review API key usage regularly
- Set up alerts for unusual activity
- Track rate limit violations
- Monitor last used timestamps for stale keys
API Reference
For programmatic API key management:Next Steps
Rate Limiting
Configure detailed rate limits for your API keys
Model Routing
Control how requests are routed to ChatGPT accounts