Overview
switchAILocal uses Bearer token authentication compatible with the OpenAI API format. Configure access keys in yourconfig.yaml or use the Management Dashboard.
Authentication Methods
Bearer Token (Recommended)
Include your API key in theAuthorization header:
X-API-Key Header
Alternative header format:Configuring Access Keys
Option 1: Configuration File
Add access keys toconfig.yaml:
config.yaml
Option 2: Management Dashboard
- Open
http://localhost:18080/management - Navigate to API Keys section
- Click Add Key to generate new access keys
- Copy and use the generated key
Option 3: Environment Variable
Set a default key via environment variable:SDK Configuration
Access Control
Key Permissions
Each access key can be configured with specific permissions:config.yaml
Remote Access
By default, the API only accepts requests fromlocalhost. To enable remote access:
config.yaml
Management API Authentication
Management endpoints require a separate secret key:Initialize Management Secret
WebSocket Authentication
WebSocket connections support query parameter authentication:config.yaml:
config.yaml
Security Best Practices
Use Strong API Keys
Use Strong API Keys
Generate random keys with sufficient entropy:Prefix with
sk- for consistency with OpenAI format.Rotate Keys Regularly
Rotate Keys Regularly
Create new keys and deprecate old ones periodically. Use the Management Dashboard to manage active keys.
Restrict Remote Access
Restrict Remote Access
Only enable
allow_remote: true when necessary. Use firewall rules to limit access to trusted IPs.Monitor Usage
Monitor Usage
Check access logs in the Management Dashboard to detect unauthorized usage:
Troubleshooting
401 Unauthorized
Cause: Missing or invalid API key Solution:- Verify key is configured in
config.yamlunderaccess.keys - Check key is enabled:
enabled: true - Ensure
Authorization: Bearer <key>header is present
403 Forbidden
Cause: Remote access disabled or insufficient permissions Solution:- For remote access, set
allow_remote: truein config - Verify key has required permissions for the endpoint
- Check Management API secret is properly initialized