Errors
One error shape and every status
Every error from the API has the same shape and the right HTTP status. Branch on the code, which never changes; show the message to people; read details for the field that failed. Quote the request_id when you write to support.
The error shape
1{2"error": {3"code": "validation_error",4"message": "Some fields are not valid",5"details": {6"date_range": "use a preset (today, yesterday, 7d, 30d, 90d, this_month, last_month, this_year, all) or from and to as dates (2026-11-01) or RFC 3339 times, with from before to"7}8},9"request_id": "req_4f1c9a0b7d2e85a1c3f60b9e"10}
snake_case. Write your code against this. New codes may be added; existing ones never change meaning.validation_error it maps each field that failed to what is wrong with it.X-Request-Id header of every response, errors or not.Statuses and codes
These are the statuses the API uses and the codes you will meet most. Each endpoint in the reference lists its own codes.
| Status | Code | When |
|---|---|---|
400 | bad_request | The body isn't valid JSON, holds more than one value, or has a field the endpoint doesn't know. details.reason says which |
400 | invalid_limit | ?limit= is not a number from 1 to 200 |
400 | invalid_cursor | ?cursor=, or a query's cursor, is not a cursor the API gave you for this list or query |
401 | unauthorized | No key, or a key that is unknown, revoked, expired after rotation, or public |
402 | project_limit, alert_limit, member_limit, plan_required | Your plan doesn't allow more of this, or doesn't include the feature |
403 | forbidden | The key lacks the scope this endpoint needs |
403 | session_required | Only a signed-in person can do this, not a key |
404 | not_found | It doesn't exist, was deleted, or is outside what your key can reach |
409 | goal_name_taken, slug_taken, … | It clashes with something that exists. The code names what |
409 | delivery_not_failed, webhook_disabled | The thing is in a state that doesn't allow this, such as retrying a delivery that succeeded |
410 | share_expired, invite_expired | It existed but has expired |
413 | payload_too_large | The request body is over 1 MB |
413 | too_many_events | An ingest batch is over 100 events or 500 KB |
422 | validation_error | The body was read but some fields are wrong. details names each one |
422 | too_many_queries | A batch query holds more than 10 queries |
422 | goal_limit, export_too_large | Over a limit of the feature, such as an export of more than 10,000 rows |
429 | rate_limited | The secret key made more requests this second than its rate limit allows. Retry-After says how many seconds to wait |
500 | internal_error | Something went wrong on our side. The details never reach you; the request_id lets us find them |
501 | not_available_yet | It needs a product that isn't live yet, such as previewing an alert on a Monitoring signal |
503 | clickhouse_not_configured, provider_not_configured | A part the endpoint depends on is not available |
A key that can't reach a project gets 404, not 403. The API doesn't tell a key whether something it can't reach exists.
Not sent yet
421 wrong_region is planned and never sent today: it will answer a data request sent to the wrong region. Handle it now and your client keeps working when it arrives.
Validation errors
A 422 validation_error checks the whole body and reports every field that failed, not just the first:
1{2"error": {3"code": "validation_error",4"message": "Some fields are not valid",5"details": {6"measures": "unknown measure \"visits_total\"",7"granularity": "must be hour, day, week, month or auto"8}9},10"request_id": "req_…"11}
Show details next to the matching inputs if your users build the request, or log it if your code does.
Handling errors in code
1export async function viakite(url, body) {2const res = await fetch(url, {3method: body ? "POST" : "GET",4headers: {5Authorization: `Bearer ${process.env.VIAKITE_SECRET_KEY}`,6"Content-Type": "application/json",7},8body: body ? JSON.stringify(body) : undefined,9});10if (res.ok) return res.status === 204 ? null : res.json();1112const { error, request_id } = await res.json();13const err = new Error(`${error.code}: ${error.message} (request ${request_id})`);14err.status = res.status;15err.code = error.code;16err.details = error.details;17throw err;18}
1import os2import requests34class ViakiteError(Exception):5def __init__(self, status, code, message, details, request_id):6super().__init__(f"{code}: {message} (request {request_id})")7self.status, self.code, self.details = status, code, details89def viakite(url, body=None):10headers = {"Authorization": f"Bearer {os.environ['VIAKITE_SECRET_KEY']}"}11res = requests.post(url, json=body, headers=headers) if body is not None else requests.get(url, headers=headers)12if res.ok:13return None if res.status_code == 204 else res.json()14payload = res.json()15e = payload["error"]16raise ViakiteError(res.status_code, e["code"], e["message"], e.get("details"), payload.get("request_id"))
Retries
Retry only what can succeed on a second try:
- Retry network errors, timeouts,
500,502,503and429. Wait between tries and double the wait each time, starting at about 1 second, for up to 5 tries. On a429, wait at least the seconds inRetry-After. - Don't retry other
4xxanswers. The same request will fail the same way; fix the request, the key or its scopes first.
Reads (GET, and POST queries such as /analytics/query) are safe to retry. Be careful with a POST that creates something: the API doesn't deduplicate requests yet, so a retry after a timeout can create a second goal, key or webhook. Before you retry one, list what exists and check whether the first try went through. Some creates help you here, such as goals, which refuse a second goal with the same name with 409 goal_name_taken.
Idempotency-Key
Only the billing endpoints read the Idempotency-Key header today. Other endpoints ignore it.