Skip to main content

Async operations and polling

How long-running Talonic API calls work: 202 Accepted with a poll_url, status values per resource, a recommended backoff, and webhooks or /v1/events instead.

Work that takes longer than a request should wait for returns at once with `202 Accepted` and a `poll_url`: a path, relative to https://api.talonic.com, that reports the status of that work. You poll it until the status is terminal, then read the result. If you would rather not poll, subscribe to the matching webhook event or read the event feed. This page is for anyone integrating extraction, Spec runs or questions over documents into their own code.

Which calls are asynchronous

Async calls and where to poll

POST /v1/extract200 or 202Documents of 5 pages or fewer return 200 with the data. Larger documents, or any request with options: {"async": true}, return 202 with poll_url set to /v1/documents/{id}. Poll until status is completed, then read GET /v1/documents/{id}/extractions. Status values: pending, processing, completed, duplicate, error.
POST /v1/run202Always 202. Poll GET /v1/run/{id} (the poll_url). Status values: processing, then completed, failed or cancelled. Read rows with GET /v1/run/{id}/results. Events: run.completed, run.failed, run.cancelled.
POST /v1/pipelinesrunPoll GET /v1/pipelines/{id}/progress; the run is finished when completedDocuments plus errorDocuments reaches totalDocuments. Read rows with GET /v1/pipelines/{id}/results.
POST /v1/ask202Returns 202 with ask_id and poll_url (/v1/ask/{id}). Poll about every 2 seconds; answers take 10 to 60 seconds. Status values: processing, completed, error. Or stream GET /v1/ask/{id}/stream.
POST /v1/process202Always 202 with run_id and poll_url. Poll GET /v1/runs/{id}; completed and failed are terminal, every other value means in progress. Event: process.completed. Deprecated in favour of /v1/pipelines; still supported.
POST /v1/matching/runsrunStarts a matching run in the background. Poll GET /v1/matching/runs/{id} (or /progress), then read GET /v1/matching/runs/{id}/results.

The 202 response

A 202 means the work is accepted and credits for the accepted work are reserved or charged as the pricing for that action says; it does not mean the work succeeded. Store the identifier from the body (document.id, run_id or ask_id) before anything else, so a crash in your client never loses track of work already running. Each 202 body carries a status (processing on acceptance) and the poll_url.

POST /v1/run — 202 Accepted

{
  "run_id": "3d44a4dc-e3e4-4bca-b079-a9c85bf75026",
  "spec_id": "1fc7807e-e1aa-4504-b796-5709986e78ed",
  "status": "processing",
  "input_count": 2,
  "poll_url": "/v1/run/3d44a4dc-e3e4-4bca-b079-a9c85bf75026"
}

Recommended polling and backoff

Start polling after about 2 seconds and back off exponentially: 2, 4, 8, 16, then every 30 seconds. Give up and alert after a timeout that suits the work: about 5 minutes for a single extraction, longer for a Spec run over many documents. For /v1/ask, poll about every 2 seconds, since answers arrive within a minute. A poll is a read and counts against the read namespace of your rate limits, so a fast fixed-interval loop across many runs wastes quota; webhooks avoid that entirely.

curl — start a Spec run and poll it

RUN_ID=$(curl -s -X POST https://api.talonic.com/v1/run \
  -H "Authorization: Bearer $TALONIC_API_KEY" \
  -F "spec_id=1fc7807e-e1aa-4504-b796-5709986e78ed" \
  -F "files=@invoice.pdf" | jq -r '.run_id')

curl -s https://api.talonic.com/v1/run/$RUN_ID \
  -H "Authorization: Bearer $TALONIC_API_KEY" | jq '.status'

Node — poll any poll_url with backoff

const BASE = 'https://api.talonic.com';
const headers = { Authorization: `Bearer ${process.env.TALONIC_API_KEY}` };
const TERMINAL = new Set(['completed', 'complete', 'failed', 'cancelled', 'error', 'duplicate']);

async function pollUntilDone(pollUrl: string, timeoutMs = 5 * 60_000) {
  const started = Date.now();
  let delay = 2_000;
  while (Date.now() - started < timeoutMs) {
    await new Promise((r) => setTimeout(r, delay));
    const res = await fetch(BASE + pollUrl, { headers });
    if (res.status === 429) { delay = 30_000; continue; }
    const body = await res.json();
    if (TERMINAL.has(body.status)) return body;
    delay = Math.min(delay * 2, 30_000);
  }
  throw new Error(`Timed out polling ${pollUrl}`);
}

Without polling: webhooks and the event feed

Every async call above also announces its outcome as an event: document.extracted and extraction.complete for extraction, run.completed, run.failed and run.cancelled for Spec runs, process.completed for processing runs. Register a webhook with POST /v1/webhooks to have Talonic push the event to your server, or read GET /v1/events on your own schedule, resuming from next_cursor. A good pattern uses both: webhooks for speed, a periodic sweep of the feed to catch anything missed while your endpoint was down. See Webhooks at a glance.

Treat the event as a trigger and the API as the source of truth: when an event arrives, fetch the run or document it names before acting on it.

Errors

  • `402 insufficient_credits` on submission: no work started. Top up and resubmit unchanged.
  • `404` on a poll: the identifier is not in your workspace, or the key cannot see it. Check you are polling with a key from the same workspace.
  • `429` on a poll: slow down to the 30-second ceiling; see Rate limits.
  • Terminal `failed` or `error`: the body carries the error detail. Fix the input and submit again; resubmitting the same failing document unchanged gives the same result.

Frequently asked questions

How do I know a Talonic call is asynchronous?+
It returns 202 Accepted with a poll_url in the body. A 200 means the result is already in the response. POST /v1/extract returns 200 for short documents and 202 for longer ones or when you pass options.async true.
How often should I poll?+
Start at about 2 seconds and back off exponentially to a 30-second ceiling. For POST /v1/ask, poll about every 2 seconds, since answers arrive within a minute. Webhooks remove the need to poll at all.
Can I get notified instead of polling?+
Yes. Register a webhook with POST /v1/webhooks for events such as run.completed or document.extracted, or read GET /v1/events on your own schedule. Use the event as a trigger and fetch the resource it names for the authoritative state.