Kosmobids Public API

Automate a saved search

Create a saved search, trigger a matching run, poll until it is final, and page through the matches.

Saved searches are the repeatable form of a search. You define the criteria once, then trigger runs on your own schedule and consume the results.

curl -s -X POST "$KOSMOBIDS_BASE_URL/saved-searches" \
  -H "x-api-key: $KOSMOBIDS_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "name": "Cloud migration in DACH",
    "criteria": {
      "includeKeywords": ["cloud migration", "managed services"],
      "contractingCountry": ["DE", "AT", "CH"],
      "submissionDeadlineAtLeastDays": 14
    },
    "options": {
      "type": "mixed",
      "recommendedFilter": "all"
    }
  }' | jq

Keep the returned id. Each company can have up to 10 saved searches; creating an 11th returns 409.

2. Trigger a run

curl -s -X POST "$KOSMOBIDS_BASE_URL/saved-searches/$SAVED_SEARCH_ID/runs" \
  -H "x-api-key: $KOSMOBIDS_API_KEY" \
  -H "content-type: application/json" \
  -d '{
    "publishMatches": false,
    "includeCompanyDescription": true
  }' | jq
{
  "data": {
    "runId": "workflow-id",
    "workflowId": "workflow-id",
    "status": "new"
  },
  "error": null
}

Use publishMatches: false while you are validating the integration. Set it to true when you want qualifying matches to land in the company pipeline.

3. Poll the run

Poll the matches endpoint with a backoff. Stop when isFinalStatus is true. The snippets below use the api helper from the quickstart.

type RunMatches = {
  runId: string;
  status: 'new' | 'in_progress' | 'done' | 'error';
  isFinalStatus: boolean;
  matchScores: Array<{
    id: string;
    tender_id: string;
    evaluation?: { fit: 'match' | 'industry_match' | 'not_match'; reasoning: string };
    finalScore?: { score: number; reasoning: string; warnings: string[] };
  }>;
  count: number;
  total: number;
};

async function waitForRun(savedSearchId: string, runId: string): Promise<RunMatches> {
  let delay = 2_000;

  for (let attempt = 0; attempt < 60; attempt++) {
    const page = await api<RunMatches>(
      `/saved-searches/${savedSearchId}/runs/${runId}/matches?limit=100&offset=0`,
    );

    if (page.isFinalStatus) {
      if (page.status === 'error') throw new Error('Matching run failed');
      return page;
    }

    await new Promise((resolve) => setTimeout(resolve, delay));
    delay = Math.min(delay * 2, 30_000);
  }

  throw new Error('Timed out waiting for the matching run');
}

4. Page through the matches

The first page returns count items and a total for the filter. Keep requesting pages while offset + count < total.

async function allMatches(savedSearchId: string, runId: string, fit?: string) {
  const matches = [];
  let offset = 0;

  while (true) {
    const query = new URLSearchParams({ limit: '100', offset: String(offset) });
    if (fit) query.set('fit', fit);

    const page = await api<RunMatches>(
      `/saved-searches/${savedSearchId}/runs/${runId}/matches?${query}`,
    );
    matches.push(...page.matchScores);

    offset += page.count;
    if (page.count === 0 || offset >= page.total) return matches;
  }
}

Filter server-side with fit=match or fit=match,industry_match; do not download everything and filter in memory when the corpus is large.

5. Recover after a timeout

If the trigger request times out, do not blindly trigger another run. List the saved search's runs and look for a recent run in new, in_progress, or done:

curl -s "$KOSMOBIDS_BASE_URL/saved-searches/$SAVED_SEARCH_ID/runs?limit=5" \
  -H "x-api-key: $KOSMOBIDS_API_KEY" | jq '.data.runs'

Triggering a run is not idempotent; each accepted request starts a new run.

6. Scheduling

The Public API does not schedule runs for you. Trigger runs from your own scheduler (cron, workflow engine, or queue) and let the polling loop handle completion. A daily trigger is a common starting point; align it with the deadlines that matter to your team.

7. Publishing

publishMatches: true publishes qualifying matches to the pipeline. Publishing follows the product's quality policy, so a run can contain more matches than are published. Read the run matches for the full evaluation; use the pipeline for the published subset.

Next steps