Cortex uses API key authentication to secure endpoints. This guide covers how authentication works and how to manage API keys.
Overview
Cortex has two authentication layers:
- Admin Login - Username/password for the web interface
- API Keys - Token-based authentication for API access
Admin Login
The frontend requires admin credentials to access:
Code
Login at http://localhost:3000/login with these credentials.
Serving over plain HTTP (no TLS)? The session cookie carries the Secure flag by default in production builds. Browsers silently drop Secure cookies over plain HTTP, so on a TLS-less setup (e.g. a LAN self-host) login appears to succeed but immediately bounces back to the login page. Set SESSION_COOKIE_SECURE=false in .env for that setup — and remove it once TLS termination is in front.
API Key Authentication
All API endpoints (except /health) require an API key.
Using API Keys
Include the key in the X-API-Key header:
Code
Or use the Authorization header:
Code
API Key Types
Admin Key
The admin API key has full access to all endpoints:
Code
Capabilities:
- All document operations (upload, delete, reprocess)
- Search and RAG queries
- Knowledge graph access
- Collection and community management
- API key management (create, revoke other keys)
- Background task management
User Keys
User API keys have configurable permissions:
| Permission | Description |
|---|---|
read | Search, view documents, ask questions |
write | Upload documents, create collections |
delete | Delete documents and collections |
admin | Full access including key management |
Managing API Keys
Create a New Key
Code
Response:
Code
Warning: The full API key is only shown once. Store it securely.
List API Keys
Code
Code
Update a Key
Code
Revoke a Key
Code
Reactivate a Key
Code
Delete a Key
Code
Permission Checks
API endpoints check permissions:
| Endpoint | Required Permission |
|---|---|
GET /api/documents | read |
GET /api/search | read |
POST /api/ask | read |
POST /api/upload | write |
POST /api/collections | write |
DELETE /api/documents/* | delete |
POST /api/admin/api-keys | admin |
Error Responses
Missing API Key
Code
Status: 401 Unauthorized
Invalid API Key
Code
Status: 401 Unauthorized
Expired API Key
Code
Status: 401 Unauthorized
Insufficient Permissions
Code
Status: 403 Forbidden
Best Practices
Key Rotation
Rotate API keys regularly:
- Create a new key with the same permissions
- Update your applications to use the new key
- Revoke the old key after confirming the switch
Least Privilege
Grant only necessary permissions:
Code
Key Expiration
Set expiration dates for temporary access:
Code
Secure Storage
- Never commit API keys to version control
- Use environment variables or secret managers
- Rotate keys if they may have been exposed
Audit Usage
Monitor API key usage:
Code
Check last_used_at to identify unused or suspicious keys.