Authentication
All Afternoon API endpoints (except the health check) require authentication via an API key sent as a Bearer token in the Authorization header.
Obtaining an API key
API keys are created from the Afternoon dashboard. Each key is scoped to a single company and has one of two modes:
Making authenticated requests
Include your API key in the Authorization header of every request:
Error responses
The API returns specific error codes for authentication failures:
Missing or malformed header
Returned when the Authorization header is absent or does not follow the Bearer <token> format.
Status: 401 Unauthorized
Invalid API key format
Returned when the token is present but does not match the expected ak_live_* or ak_test_* pattern.
Status: 401 Unauthorized
Invalid API key
Returned when the token format is valid but the key does not exist.
Status: 401 Unauthorized
Revoked API key
Returned when the API key has been revoked from the dashboard.
Status: 401 Unauthorized
Service unavailable
Returned when the authentication service cannot reach the database. Retry with exponential backoff.
Status: 503 Service Unavailable
Rate limiting
Authenticated requests are subject to rate limits of 1,000 requests per 60-second window per company. Rate limit status is communicated via response headers:
When the limit is exceeded, the API returns a 429 Too Many Requests response.
Security best practices
Never expose API keys in client-side code, public repositories, or browser requests. Always send API calls from your server.
- Rotate keys regularly — Generate new keys and revoke old ones from the dashboard.
- Use test keys for development — Keep
ak_test_keys for staging and local development. Useak_live_keys only in production. - Store keys securely — Use environment variables or a secrets manager. Never commit keys to source control.
- Monitor usage — Check the dashboard for unexpected spikes in API usage that may indicate a compromised key.
