Authentication#
Learn how WatchLLM authenticates API requests and how to manage your API keys.
Overview#
WatchLLM uses Bearer token authentication with project-scoped API keys. Every request to the proxy must include a valid API key in the Authorization header.
API Key Format#
WatchLLM API keys follow a specific format for easy identification:
| Key Type | Prefix | Example | Use Case |
|---|---|---|---|
| Project Key | lgw_proj_ |
lgw_proj_abc123def456 |
Production API access |
| Test Key | lgw_test_ |
lgw_test_xyz789ghi012 |
Sandbox testing (free, limited) |
Making Authenticated Requests#
HTTP Header#
Include your API key as a Bearer token:
POST https://proxy.watchllm.dev/v1/chat/completions
Authorization: Bearer lgw_proj_your_key_here
Content-Type: application/json
{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}Using OpenAI SDK#
The standard OpenAI SDK handles authentication automatically:
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'lgw_proj_your_key_here',
baseURL: 'https://proxy.watchllm.dev/v1',
});from openai import OpenAI
client = OpenAI(
api_key="lgw_proj_your_key_here",
base_url="https://proxy.watchllm.dev/v1",
)Using cURL#
curl https://proxy.watchllm.dev/v1/chat/completions \
-H "Authorization: Bearer lgw_proj_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-4o",
"messages": [{"role": "user", "content": "Hello!"}]
}'Authentication Flow#
When a request arrives at the WatchLLM proxy:
- Key Extraction — The
Authorization: Bearer <key>header is parsed - Format Validation — The key must match the
lgw_proj_orlgw_test_prefix pattern - Database Lookup — The key is validated against the
api_keystable in Supabase - Project Resolution — The associated project record is fetched (plan, settings, cache config)
- Rate Limit Check — Per-key and per-IP rate limits are enforced
- Request Processing — The request proceeds to cache lookup and/or provider forwarding
Error Responses#
| Status | Error | Cause |
|---|---|---|
401 |
Invalid API key |
Key doesn't exist or is inactive |
401 |
Missing API key |
No Authorization header provided |
403 |
API key disabled |
Key has been deactivated |
429 |
Rate limit exceeded |
Too many requests per minute |
429 |
Monthly quota exceeded |
Plan's monthly request limit reached |
Managing API Keys#
Creating Keys#
- Log in to the WatchLLM Dashboard
- Navigate to your project
- Go to Settings → API Keys
- Click Generate New Key
- Copy and securely store the key — it won't be shown again
Rotating Keys#
To rotate a key without downtime:
- Generate a new key in the dashboard
- Update your application to use the new key
- Verify the new key works in production
- Deactivate the old key
Deactivating Keys#
Deactivated keys immediately stop working. Any requests using a deactivated key will receive a 401 response.
Security Best Practices#
Do's#
- Store keys in environment variables — never hardcode in source code
- Use separate keys for development, staging, and production
- Rotate keys regularly — at least every 90 days
- Monitor key usage in the dashboard for anomalies
- Use server-side only — never expose keys in client-side JavaScript
Don'ts#
- Don't commit keys to Git — add
.envto.gitignore - Don't share keys between team members — create individual keys
- Don't log keys — ensure your logging doesn't capture authorization headers
- Don't use project keys for testing — use test keys (
lgw_test_) instead
Environment Variable Setup#
Node.js#
# .env
WATCHLLM_API_KEY=lgw_proj_your_key_hereconst client = new OpenAI({
apiKey: process.env.WATCHLLM_API_KEY,
baseURL: 'https://proxy.watchllm.dev/v1',
});Python#
# .env
WATCHLLM_API_KEY=lgw_proj_your_key_hereimport os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["WATCHLLM_API_KEY"],
base_url="https://proxy.watchllm.dev/v1",
)BYOK Authentication#
When using Bring Your Own Key (BYOK) mode, authentication works in two layers:
- WatchLLM Authentication — Your
lgw_proj_key authenticates with WatchLLM - Provider Authentication — Your stored provider keys (OpenAI, Anthropic, Groq) are used to authenticate with upstream providers
See the BYOK Guide for detailed setup instructions.