API Key Authentication
switchAILocal requires clients to authenticate using API keys. Requests must include theAuthorization: Bearer <key> header.
Configuring API Keys
config.yaml
List of valid API keys for client authentication. All requests to
/v1/* endpoints require a key from this list.Key Rotation
API keys support hot reload. To rotate keys:- Add new key to
api-keyslist - Save
config.yaml - switchAILocal automatically reloads (no restart needed)
- Update clients to use new key
- Remove old key from config
Management Access Control
The Management API provides dashboard access and control endpoints. It has separate authentication and access controls.config.yaml
Management Secret Key
Management authentication key. All management requests require this key. Leave empty to disable Management API entirely (404 for all management routes).
The hashed value is persisted back to
config.yaml automatically. Future startups skip re-hashing.Remote Access Control
Allow remote (non-localhost) access to management endpoints. When
false, only localhost (127.0.0.1, ::1) can access management routes, even with valid key.- ✅ Requests from
127.0.0.1with valid key → Allowed - ❌ Requests from
192.168.1.100with valid key → Denied (403)
- ✅ Requests from any IP with valid key → Allowed
Management Control Panel
Disable the bundled management control panel asset download and HTTP route. When
true, management UI is not served.GitHub repository URL for management panel assets. Override to use custom dashboard.
Disabling Management API
To completely disable all management endpoints:- Management dashboard returns 404
- All
/api/management/*routes return 404 - Client API (
/v1/*) continues working normally
WebSocket Authentication
Control authentication for WebSocket API:config.yaml
Enable authentication for WebSocket API (
/v1/ws). Requires same API keys as REST endpoints.TLS/HTTPS Configuration
Enable HTTPS for encrypted transport:config.yaml
Enable HTTPS server mode with TLS certificates
Path to TLS certificate file (PEM format)
Path to TLS private key file (PEM format)
Production TLS Example
With Let’s Encrypt:TLS certificate changes require a server restart. Hot reload does not apply to TLS settings.
Authentication Directory
Configure storage location for authentication tokens:config.yaml
Directory for OAuth tokens, session data, and authentication cache. Supports
~ for home directory.tokens.json- OAuth refresh tokens (Gemini, etc.)- Session state for authenticated providers
- Authentication cache
Security Best Practices
1. Use Strong API Keys
2. Enable TLS in Production
3. Restrict Management Access
4. Secure Authentication Directory
5. Rotate Keys Regularly
Set up a key rotation schedule:- Client API keys: Rotate every 90 days
- Management secret key: Rotate every 180 days
- OAuth tokens: Automatically refreshed by switchAILocal
6. Use Environment-Specific Configs
Firewall Configuration
When deploying withallow-remote: true, configure firewall rules:
Complete Security Example
config.yaml
Troubleshooting
Authentication failures
Authentication failures
Problem: Requests return 401 UnauthorizedSolutions:
- Verify
Authorization: Bearer <key>header is included - Check key is in
api-keyslist - Ensure config.yaml has been reloaded
- Check for typos in API key
Management API returns 404
Management API returns 404
Problem: Management endpoints return 404Solutions:
- Ensure
remote-management.secret-keyis not empty - Check if
disable-control-panel: trueis set - Verify you’re accessing the correct endpoint
Remote management access denied
Remote management access denied
Problem: Management requests from network IPs return 403Solutions:
- Set
remote-management.allow-remote: true - Verify firewall allows traffic on the port
- Ensure correct management secret key is used