Skip to main content

Overview

switchAILocal uses Bearer token authentication compatible with the OpenAI API format. Configure access keys in your config.yaml or use the Management Dashboard.

Authentication Methods

Include your API key in the Authorization header:

X-API-Key Header

Alternative header format:

Configuring Access Keys

Option 1: Configuration File

Add access keys to config.yaml:
config.yaml

Option 2: Management Dashboard

  1. Open http://localhost:18080/management
  2. Navigate to API Keys section
  3. Click Add Key to generate new access keys
  4. 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 from localhost. To enable remote access:
config.yaml
Enabling remote access requires setting a strong secret key. Use the Management Dashboard to initialize security settings.

Management API Authentication

Management endpoints require a separate secret key:

Initialize Management Secret

See Management API for details.

WebSocket Authentication

WebSocket connections support query parameter authentication:
Alternatively, disable WebSocket auth in config.yaml:
config.yaml

Security Best Practices

Generate random keys with sufficient entropy:
Prefix with sk- for consistency with OpenAI format.
Create new keys and deprecate old ones periodically. Use the Management Dashboard to manage active keys.
Only enable allow_remote: true when necessary. Use firewall rules to limit access to trusted IPs.
Check access logs in the Management Dashboard to detect unauthorized usage:

Troubleshooting

401 Unauthorized

Cause: Missing or invalid API key Solution:
  1. Verify key is configured in config.yaml under access.keys
  2. Check key is enabled: enabled: true
  3. Ensure Authorization: Bearer <key> header is present

403 Forbidden

Cause: Remote access disabled or insufficient permissions Solution:
  1. For remote access, set allow_remote: true in config
  2. Verify key has required permissions for the endpoint
  3. Check Management API secret is properly initialized

Next Steps

Chat Completions

Start sending authenticated requests

Management API

Configure advanced security settings