Kosmobids Public API

Asynchronous work and polling

How to poll document downloads, matching runs, and document analyses, and when to retry.

The Public API has no webhooks in v1. Work that cannot finish inside a request is scheduled and reported through a status field or a polling endpoint.

Async operations

Operation Start Identifier Poll Final condition
Tender document download POST /tenders/:tenderId/documents/download tenderDocumentId GET /tenders/:tenderId/files Files appear, or the download finishes with none.
Matching run POST /saved-searches/:id/runs runId GET /saved-searches/:id/runs/:runId/matches isFinalStatus is true.
Document analysis POST /tenders/:tenderId/analyze workflowId GET /analyses/:workflowId isFinalStatus is true.

Status models

The three flows use different status vocabularies.

Matching runs

Status Final?
new No
in_progress No
done Yes
error Yes

Document analysis workflows

Status Final?
pending No
running No
waiting No
retry No
completed Yes
failed Yes
aborted Yes

isFinalStatus is the portable signal. Prefer it over a hand-written status list, and use isStatusSuccess to distinguish success from failure.

Document download

The download trigger reports scheduled: true with HTTP 202 when a workflow was created, and scheduled: false with HTTP 200 when a download is already running or there is nothing to download. There is no separate download-status endpoint; poll the file list.

Backoff

A reasonable default:

  1. Start with a 2 second delay.
  2. Double the delay on each attempt, capped at 30 seconds.
  3. Give up after a documented timeout in your own integration, not by hammering the API.

Downloads can take minutes to hours. Matching runs and analyses usually finish in minutes, but the corpus size and document count affect the duration.

async function pollUntilFinal<T>(fn: () => Promise<T>, isFinal: (value: T) => boolean, timeoutMs = 15 * 60_000): Promise<T> {
  const started = Date.now();
  let delay = 2_000;

  while (Date.now() - started < timeoutMs) {
    const value = await fn();
    if (isFinal(value)) return value;
    await new Promise((resolve) => setTimeout(resolve, delay));
    delay = Math.min(delay * 2, 30_000);
  }

  throw new Error('Polling timed out');
}

Do not poll faster than once per second. Polling counts against the rate limits; when a window is exhausted the API returns 429 and the poll was not executed. Honor Retry-After or the x-rate-limit-*-reset headers rather than retrying immediately.

Retries

Failure Retry? Notes
Network error or 502 / 503 Yes Use exponential backoff.
429 Yes Wait for Retry-After (or the x-rate-limit-*-reset header) before retrying.
500 Maybe Treat as transient once; then escalate.
401 / 403 No Fix the key or scope.
404 No The resource does not exist or is not visible to this company.
409 No A business rule is blocking the request; resolve the condition first.
422 No Fix the request.
Final error / failed / aborted Yes, as a new request Start a new run or analysis; polling will not revive a failed workflow.

Idempotency

  • Triggering a document download while one is already running returns 200 and does not start a second workflow.
  • Triggering a matching run always starts a new run.
  • Starting an analysis always starts a new workflow.
  • Posting a comment is not idempotent.

When a request times out after it may have been accepted, look up the resulting state before retrying. For a run, list the saved search's runs; for an analysis, you need the workflowId from the accepted response, so avoid blind retries that could create duplicate analyses.

Concurrency

There is no published concurrency quota. Keep the number of simultaneous analyses and runs modest, especially for the same company, and queue work on your side rather than launching everything at once.