Core concepts
Idempotency
Make retries safe with the Idempotency-Key header: where it is required or optional, the key format, how long a key lasts, and what a reused key returns.
A request can fail after the API has already done the work: the connection drops, or your client times out while the answer is on its way. Retrying blindly could then start the work twice and charge for it twice. An idempotency key prevents that. You send a value of your choosing in the Idempotency-Key header, and send the same value again when you retry. The API recognizes the retry and returns the first result instead of doing the work again.
Where it applies#
| Routes | Idempotency-Key | What a retry with the same key does |
|---|---|---|
POST /v1/enrichment/jobs | Required | Returns the job the key started, rather than starting another. |
POST /v1/enrichment/lookups | Optional | Returns the first lookup's answer, charged once. |
POST /tools/v1/runs | Optional | Returns the first run, for 24 hours. |
Billed reads: POST /v1/search, /v1/similar, /v1/entities/*, /v1/relationships* and /v1/org-chart* | Optional | Charged once, if retried on the same UTC day. |
POST /v1/feedback | Optional | Returns the feedback already recorded, with 200 instead of 201. |
Every other route ignores the header. Reads such as GET requests are safe to retry without one, and the free routes have nothing to charge twice.
Starting an enrichment job without the header is refused with 400 request.invalid, before anything starts. A job can take minutes and spend credits, so the API insists that a retry be recognizable.
Agent runs take no key. POST /v1/agents/runs ignores the header: every start is a new run, held and charged on its own. So a start is never retried blindly. If one gets no answer, or answers 500 or 504, the run may have started: list your runs with GET /v1/agents/runs before you start again, and cancel any you do not want. See Agent runs.
Key format#
Generate a fresh, unique value for each piece of work you intend to do: a UUID is ideal. Its allowed form depends on the route:
| Routes | Allowed key |
|---|---|
| Tool runs and billed reads | 1 to 120 characters: letters, digits, and ., _, : or -. |
| Enrichment jobs, enrichment lookups and feedback | Up to 255 characters. |
A key that does not fit is refused before anything runs, with request.invalid: status 422, or 400 on enrichment jobs. The API never shortens a key, since two keys cut to the same length could otherwise share one charge.
How each kind of key behaves#
Billed reads#
On search, similar, record lookup, relationships and org chart, the key makes a retry free. A request counts as a retry when all of these match the first:
- the
Idempotency-Key, - the method, path and body,
- the API key that sent it,
- the UTC day.
The retry is answered normally and reports meta.credits_charged: 0. A different key, a new UTC day, or no key at all is a new request and is charged as one.
A key names one request for the day. Sending it again with a changed body, or to another of these routes, is refused with 409 idempotency.conflict before any work is done or charged: use a new key for the new request. A request that fails (a refused body, a 5xx) does not keep its key, so you may correct it and send it again with the same key.
Enrichment jobs#
Send one key per job you mean to start, and keep it with your own record of that work. If the start request fails or times out, send it again with the same key, and you get back the job the first attempt started, if it did. Reusing a key for a different enrichment job (different rows or fields) is refused with 409 enrichment.idempotency_key_reused.
Tool runs#
A tool run's key lasts 24 hours. Within that time, a retry with the same key returns the first run, its output included, instead of running (and paying for) the tool again. After 24 hours the same key starts a new run. Two refusals protect a key from misuse:
409 tools.idempotency_key_reused: the key already started a run of another tool, or someone else's run, in the last 24 hours.409 tools.idempotency_conflict: the key was already used for a different request: another tool or input, or another API key or person in the workspace.
Either way, generate a new key for the new run.
Sending a key#
curl -X POST "https://api.sproutsdata.ai/v1/search" \
-H "X-API-Key: $SPROUTS_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{"category": "company", "query": "payments companies in Germany", "limit": 10}'Good practice#
- One key per intent. Create the key when you decide to do the work, not when you send the request, and store it alongside the work so a retry after a restart can reuse it.
- Never reuse a key for different work. A key is a promise that the request is the same one.
- Retry with the key; don't invent a new one. A new key on a retry is a new request, and may be charged again.
- Combine with backoff. An idempotency key makes a retry safe; Rate limits and Errors cover when to retry.