Skip to main content
Starting a search costs money. So when a request fails, the first thing to find out is whether the search started anyway. This guide shows how to retry safely and what to do for each error.

Make starts safe with an idempotency key

An operation is idempotent when doing it twice has the same effect as doing it once. Starting a search is not idempotent on its own: two POST requests start two searches. An idempotency key fixes that. It is a unique string you choose and send in the Idempotency-Key header, and it tells the API “this is the same request as before”. Send one on every request that starts a search. Any unique string of 1 to 255 characters works. A UUID is a good choice.
What the key does:
Without an idempotency key, every POST starts a new search. If a request times out and you retry it, you can end up paying for two searches.

Generate the key before the first attempt

The key identifies what you are trying to do, not one HTTP request. Create it once, store it alongside whatever triggered the search, and reuse it on every retry of that search.

What to retry

GET requests are always safe to retry. They never start work or spend credits.

When you do not know if a search started

A connection can drop after the API accepted your request but before you saw the response. The search may be running and spending credits.
1

Retry with the same idempotency key

If the first request finished, you get its response back, including the search id. If it never arrived, the search starts now.
2

If you get a 409, wait and retry

A 409 with the same body means the first request is still being handled. Retry every few seconds.
3

If the 409 lasts more than five minutes, stop

The first attempt may have ended without a recorded response. Do not keep retrying. Check GET /usage for spend from the first attempt, and contact support with the request_id if you see spend you cannot account for.
4

If you never sent a key

The API cannot tell you whether the search started. Check GET /usage for unexpected spend, and send a key next time.

Rate limits

Every response includes your current standing: To stay under the limit, leave longer gaps between polls as shown in Poll and paginate, and read results in pages of 100.

Errors that are not HTTP errors

Some failures happen after a search was accepted. They show up on the search, not as an error response.

Getting help

Every response has an X-Request-Id header, and every error body repeats it as request_id:
When you contact support@avina.io, include the request_id and, for a search, its id. Never send your API key.
Log request_id for failed requests. Do not log the Authorization header.