Skip to main content

Error Codes

All KlayrAI API errors follow a consistent JSON format. This page documents every error code, what causes it, and how to resolve it.

Error response format

Every error response includes:

Error code reference

400 — Bad Request

Cause: The request body or query parameters are malformed or missing required fields.Example:
Resolution: Check the API reference for required parameters and ensure your request body is valid JSON with the correct field types.
Cause: The date range provided is invalid — either the start date is after the end date, or the range exceeds the maximum allowed period (90 days).Example:
Resolution: Ensure from is before to and the range does not exceed 90 days.
Cause: More than 20 campaign IDs were provided in a single request (applies to report generation).Example:
Resolution: Split your request into multiple reports with 20 or fewer campaigns each.

401 — Unauthorized

Cause: The API key is missing, malformed, or invalid.Example:
Resolution:
  • Verify the x-api-key header is present in your request
  • Check that the key starts with klyr_live_ or klyr_test_
  • Ensure the key has not been revoked in your dashboard settings
  • Confirm there are no extra spaces or characters in the key
Cause: The API key was previously valid but has been revoked.Example:
Resolution: Create a new API key in Settings > API Keys and update your application.

403 — Forbidden

Cause: The API key does not have permission to access the requested resource. This typically occurs when trying to access a campaign or account that belongs to a different workspace.Example:
Resolution: Verify that the resource ID belongs to your workspace. API keys can only access data within their own workspace.
Cause: Your current plan does not include API access. The API is available on the Agency plan only.Example:
Resolution: Upgrade to the Agency plan at app.klayrai.com/settings/billing.
Cause: White-label report options were requested, but this feature requires the Agency plan.Example:
Resolution: Upgrade to the Agency plan or remove the whiteLabel object from your request.

404 — Not Found

Cause: The requested resource does not exist or is not accessible in your workspace.Example:
Resolution:
  • Check the resource ID for typos
  • Verify the resource exists by listing resources first (e.g., GET /v1/campaigns)
  • Ensure the resource belongs to your workspace

409 — Conflict

Cause: A diagnostic is already running for the specified campaign. Only one diagnostic can run per campaign at a time.Example:
Resolution: Wait for the current diagnostic to complete (typically 5-10 seconds) and then try again, or retrieve the existing diagnostic result.

422 — Unprocessable Entity

Cause: The campaign’s data has not been synced from Meta yet. Diagnostics require synced data.Example:
Resolution: Wait for the initial sync to complete. For newly connected accounts, this typically takes 30-60 seconds.

429 — Too Many Requests

Cause: You have exceeded the rate limit for your API key.Example:
Resolution: Implement exponential backoff with jitter. Check the meta.remaining_requests field in successful responses to monitor your usage. See the Rate Limits page for detailed guidance.

500 — Internal Server Error

Cause: An unexpected error occurred on the KlayrAI server.Example:
Resolution:

Error handling best practices

Always check the HTTP status code first, then the type field in the error body. Do not rely on parsing the message field — it may change between API versions.
  1. Handle every status code — At minimum, handle 400, 401, 403, 404, 429, and 500
  2. Implement retries for transient errors — 429 and 500 errors are usually transient and should be retried with backoff
  3. Do not retry 400, 401, 403, or 404 — These indicate a problem with the request itself, not a transient server issue
  4. Use structured error handling — Parse the type field for programmatic error handling rather than matching on message strings