viakite
Dashboard

API/Basics/Errors

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

response.json
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}
error.codestringrequired
Stable, lower-case snake_case. Write your code against this. New codes may be added; existing ones never change meaning.
error.messagestringrequired
A sentence for people. It may be reworded, so don't match on it.
error.detailsobject
Extra facts, when there are any. For validation_error it maps each field that failed to what is wrong with it.
request_idstring
The request's id, also sent in the 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.

StatusCodeWhen
400bad_requestThe body isn't valid JSON, holds more than one value, or has a field the endpoint doesn't know. details.reason says which
400invalid_limit?limit= is not a number from 1 to 200
400invalid_cursor?cursor=, or a query's cursor, is not a cursor the API gave you for this list or query
401unauthorizedNo key, or a key that is unknown, revoked, expired after rotation, or public
402project_limit, alert_limit, member_limit, plan_requiredYour plan doesn't allow more of this, or doesn't include the feature
403forbiddenThe key lacks the scope this endpoint needs
403session_requiredOnly a signed-in person can do this, not a key
404not_foundIt doesn't exist, was deleted, or is outside what your key can reach
409goal_name_taken, slug_taken, …It clashes with something that exists. The code names what
409delivery_not_failed, webhook_disabledThe thing is in a state that doesn't allow this, such as retrying a delivery that succeeded
410share_expired, invite_expiredIt existed but has expired
413payload_too_largeThe request body is over 1 MB
413too_many_eventsAn ingest batch is over 100 events or 500 KB
422validation_errorThe body was read but some fields are wrong. details names each one
422too_many_queriesA batch query holds more than 10 queries
422goal_limit, export_too_largeOver a limit of the feature, such as an export of more than 10,000 rows
429rate_limitedThe secret key made more requests this second than its rate limit allows. Retry-After says how many seconds to wait
500internal_errorSomething went wrong on our side. The details never reach you; the request_id lets us find them
501not_available_yetIt needs a product that isn't live yet, such as previewing an alert on a Monitoring signal
503clickhouse_not_configured, provider_not_configuredA 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:

response.json
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

viakite.mjs
1export async function viakite(url, body) {
2 const res = await fetch(url, {
3 method: body ? "POST" : "GET",
4 headers: {
5 Authorization: `Bearer ${process.env.VIAKITE_SECRET_KEY}`,
6 "Content-Type": "application/json",
7 },
8 body: body ? JSON.stringify(body) : undefined,
9 });
10 if (res.ok) return res.status === 204 ? null : res.json();
11
12 const { error, request_id } = await res.json();
13 const err = new Error(`${error.code}: ${error.message} (request ${request_id})`);
14 err.status = res.status;
15 err.code = error.code;
16 err.details = error.details;
17 throw err;
18}
viakite.py
1import os
2import requests
3
4class ViakiteError(Exception):
5 def __init__(self, status, code, message, details, request_id):
6 super().__init__(f"{code}: {message} (request {request_id})")
7 self.status, self.code, self.details = status, code, details
8
9def viakite(url, body=None):
10 headers = {"Authorization": f"Bearer {os.environ['VIAKITE_SECRET_KEY']}"}
11 res = requests.post(url, json=body, headers=headers) if body is not None else requests.get(url, headers=headers)
12 if res.ok:
13 return None if res.status_code == 204 else res.json()
14 payload = res.json()
15 e = payload["error"]
16 raise 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, 503 and 429. Wait between tries and double the wait each time, starting at about 1 second, for up to 5 tries. On a 429, wait at least the seconds in Retry-After.
  • Don't retry other 4xx answers. 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.

Next steps