Authentication
All API requests to KlayrAI require authentication via an API key passed in the request headers. API access is available on the Agency plan.API keys
API keys are scoped to your workspace and inherit the permissions of the workspace owner. Each workspace can have up to 5 active API keys.Creating a key
- Open your dashboard at app.klayrai.com
- Navigate to Settings > API Keys
- Click Create API Key
- Give the key a descriptive name (e.g., “Production”, “Staging”)
- Copy the key immediately — it will only be shown once
Rotating a key
To rotate a key without downtime:- Create a new API key
- Update your application to use the new key
- Verify that requests succeed with the new key
- Revoke the old key
Revoking a key
- Navigate to Settings > API Keys
- Click the Revoke button next to the key
- Confirm the action
401 error.
Required headers
Every API request must include the following headers:| Header | Required | Description |
|---|---|---|
x-api-key | Yes | Your API key |
klayrai-version | Recommended | API version date string (e.g., 2026-03-01). If omitted, the latest version is used. Pinning a version protects your integration from breaking changes. |
Content-Type | Yes (for POST/PUT) | Must be application/json for request bodies |
Example request
Key format
API keys follow this format:klyr_live_keys access production dataklyr_test_keys access sandbox data (coming soon)
Authentication errors
| Status | Error code | Description |
|---|---|---|
401 | authentication_error | Missing or invalid API key |
401 | key_revoked | The API key has been revoked |
403 | permission_error | The API key does not have access to this resource |
403 | plan_insufficient | Your plan does not include API access (upgrade to Agency) |
Example error response
Security best practices
Use environment variables
Use environment variables
Store your API key in an environment variable rather than hardcoding it:Then reference it in your code:
Restrict key usage by environment
Restrict key usage by environment
Create separate API keys for development, staging, and production. This limits the blast radius if a key is compromised.
Monitor key usage
Monitor key usage
Review API key activity in your dashboard under Settings > API Keys > Usage. Look for unexpected spikes in request volume or requests from unfamiliar IP addresses.
Rotate keys regularly
Rotate keys regularly
Rotate your API keys every 90 days as a best practice. Use the rotation process described above to avoid downtime.

