Overview
CEMS uses Bearer token authentication for all API requests. Each user is issued a unique API key that must be included in theAuthorization header.
Authentication Methods
Bearer Token
All requests must include anAuthorization header with a Bearer token:
API Key Format
API keys follow this format:- Prefix:
cems_ak_(user API key) - Random part: 48 hexadecimal characters (24 bytes)
- Total length: 56 characters
cems_ak_1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p7q8r9s0t1u2v3w4x
API Key Lookup Process
When you make a request, CEMS validates your API key through the following process:- Extract token from
Authorization: Bearer <token>header - Calculate key prefix (first 8 characters of random part)
- Look up user in PostgreSQL by key prefix
- Verify hash using bcrypt comparison
- Check user status (must be active)
- Set user context for request scope
server.py:104-149:
Security Features
Bcrypt Hashing
API keys are hashed using bcrypt before storage. The full key is only shown once during generation. Fromauth.py:36-45:
Key Prefix Indexing
Only the first 8 characters after the prefix are stored for lookup, enabling fast database queries while maintaining security. Fromauth.py:65-80:
Team Context
Optionally, you can specify a team context using theX-Team-ID header:
Credential Storage
The CEMS CLI stores credentials in~/.cems/credentials (chmod 600) and checks them in order:
- CLI flags:
--api-url,--api-key - Environment variables:
CEMS_API_URL,CEMS_API_KEY - Credentials file:
~/.cems/credentials
Obtaining an API Key
API keys are generated by your CEMS administrator using the Admin API:Resetting an API Key
If your API key is compromised, ask your administrator to reset it:Unauthenticated Endpoints
These endpoints do not require authentication:GET /health- Health check for Docker/monitoringGET /api/config/setup- Setup discovery for client configurationGET /ping- Simple ping endpoint