Authentication
API key and session authentication methods
The API supports two authentication methods. Use API keys for server-to-server integrations; use session cookies when calling from the application UI.
API key authentication
API keys are the recommended method for third-party integrations.
Generate a key
- Sign in to the dashboard.
- Open Dashboard → API keys.
- Click Generate key and give it a descriptive name (e.g. "Zapier", "Internal CRM sync").
- Optionally set an expiration date.
- Copy the key immediately — it is shown once and never again. The server only stores a SHA-256 hash plus the 12-character prefix.
Use the key
Send the key as a Bearer token:
Authorization: Bearer tke_live_aB3dE5gH7jK9mN1pQ3rS5tU7vW9xY1zAKey format
tke_<environment>_<22-char base64url>| Segment | Meaning |
|---|---|
tke | Product prefix (configurable via API_KEY_PREFIX). |
environment | live or test (API_KEY_ENVIRONMENT). |
| random | 24 bytes of CSPRNG entropy, base64url-encoded. |
Lifecycle
| Status | Description |
|---|---|
active | Valid; accepted by the API. |
revoked | Manually revoked. Terminal. |
expired | Past the expiresAt date. Flipped on first use after expiry. |
Security checklist
- Never commit keys to source control or ship them to clients.
- Store in environment variables or a secret manager.
- Set expiry dates for time-bounded integrations.
- Revoke immediately if exposed.
- Rotate periodically — generate a new key, deploy, then revoke the old one.
- Use a separate key per integration so revoking one doesn't break the others.
See API keys endpoints for programmatic management.
Session authentication
Used implicitly when the application UI calls the API. Sessions are managed
by better-auth via secure HTTP-only cookies.
Flow
- User signs in at
/login. - Server sets the session cookie.
- Subsequent requests from the same browser carry the cookie automatically.
- Sessions expire after the configured window (see
better-authconfig).
When to use
- First-party web app calls.
- Browser-side interactive flows.
For anything else — including any server-side code outside the Next.js app — use an API key.
Rate limiting
Both methods share the same per-principal quota.
Rate limit100 requests per 60s
See Rate limits for headers and backoff guidance.