Selling through the API

API errors

Every error the Kili API can answer, what it means and what to do.

Every error has the same shape: a code to branch on, a message that says what happened in this request with its own numbers, and a request_id to send Kili support.

{
  "error": {
    "code": "limit_reached",
    "message": "Your account's limit is 50 eSIMs a day and 48 have been used.",
    "request_id": "req_6Yc2m1Lx8Rz0"
  }
}

Branch on code, not on message: the wording can improve, the codes do not change within an API version.

Note

An error from POST /orders before the 201 or 202 means nothing was charged. When a charge has been made and something goes wrong after it, the order answers 202 instead of an error, and finishes by webhook.

The codes

StatusCodeWhat happenedWhat to do
400validation_failedA field is missing or not valid. The message names it.Fix that field and send the request again.
401unauthenticatedNo key, a header that is not a Kili key, or a revoked or unknown key.Send Authorization: Bearer kili_live_…. If the key was revoked, switch to a current one from Developers → API keys.
402insufficient_balanceYour wallet did not hold the order's cost. The message gives both.Add credit, then retry with the same Idempotency-Key.
403forbiddenA read-only key tried to buy or manage webhooks, Kili paused API orders for your account, or your account is not active.Use a full-access key. If paused, reads still work; contact your Kili manager to resume.
404not_foundNo such plan on sale, or no such order, eSIM or endpoint on your account.Check the plan against GET /catalogue, or the id against GET /orders.
409idempotency_mismatchThe Idempotency-Key was used before with a different body. The message names the field.Use a new key for a new order. Reuse a key only to retry the exact same request.
409request_in_progressThe first request with this Idempotency-Key is still running.Wait a few seconds, then retry with the same key.
409price_changedThe plan costs more than your max_cost_minor.Refresh the catalogue, quote again, and send the new price.
422limit_reachedOver the eSIMs-per-order or eSIMs-a-day limit.Split a large order. A daily limit resets at midnight Addis Ababa time; your Kili manager can raise it.
428idempotency_key_requiredPOST /orders came without an Idempotency-Key.Send a unique key per booking and store it with the booking.
429rate_limitedToo many requests a minute, for the key or the account.Wait for the Retry-After header's seconds and try again.
503insufficient_supplier_balanceKili cannot buy from its network partner right now. Nothing was charged.Retry in a few minutes with the same Idempotency-Key.
503pausedKili has paused API orders for everyone for a short while. The message says why.Retry later with the same Idempotency-Key. Reads keep working.
500internalSomething went wrong on Kili's side.Retry with the same Idempotency-Key. If it keeps happening, send Kili support the request id.

Retrying safely

A retry with the same Idempotency-Key and the same body can never buy twice, so it is always safe to retry a POST /orders that timed out or answered 409 request_in_progress, 429, 500 or 503. Do not retry 400, 401, 403, 404, 409 idempotency_mismatch or 409 price_changed without changing something first.

Finding a request

Every response, error or not, carries Kili-Request-Id. Developers → Request logs finds any request from the last 30 days by its id, with the request and response for every order.