Kosmobids Public API

Document analysis

Ask structured questions about a tender and poll the asynchronous document-research workflow that answers them with citations.

Document analysis runs a research workflow over the tender's processed documents and the company's own knowledge documents. It returns answers with page-level citations, so a caller can verify each statement against the source.

Prerequisites

The tender must have at least one processed document for your company. Either path produces one:

  1. The procurement source files: POST /tenders/:tenderId/documents/download, then wait for processing.
  2. Your own upload: POST /tenders/:tenderId/files, then poll GET /tenders/:tenderId/files until the file's documentStatus is processed. This works even when the notice has no source files at all.

If no processed document exists yet, POST /tenders/:tenderId/analyze returns 409:

{
  "data": {
    "error": "Documents not ready",
    "message": "No processed documents are available for this tender yet. Trigger the document download, or upload a document, then wait for processing."
  },
  "error": null
}

Start an analysis

POST /tenders/:tenderId/analyze

{
  "questions": [
    "Do we meet the mandatory requirements?",
    "Which certifications are required?",
    "What are the penalty clauses?"
  ]
}
  • questions is an array of 1 to 20 non-empty strings.
  • Questions are assigned IDs in order: q1, q2, and so on.
  • The response is 202 with a workflow ID:
{
  "data": {
    "workflowId": "workflow-id",
    "status": "scheduled"
  },
  "error": null
}

A 404 means the tender does not exist or has no source tender ID.

Poll the analysis

GET /analyses/:workflowId

While the workflow is running:

{
  "data": {
    "id": "workflow-id",
    "status": "running",
    "isFinalStatus": false,
    "isStatusSuccess": false
  },
  "error": null
}

On success:

{
  "data": {
    "id": "workflow-id",
    "status": "completed",
    "isFinalStatus": true,
    "isStatusSuccess": true,
    "answers": [
      {
        "questionId": "q1",
        "answer": "The company meets the mandatory requirements... [Ref:1]",
        "references": [
          {
            "idx": 1,
            "fileId": "processed-document-id",
            "pageNumber": 12,
            "regionIndex": 0,
            "uploadedFileId": "page-image-id",
            "filename": "specification.pdf"
          }
        ]
      }
    ],
    "usage": {
      "inputTokens": 15000,
      "outputTokens": 1200,
      "totalTokens": 16200
    }
  },
  "error": null
}
Field Meaning
status Workflow status: pending, running, completed, failed, retry, aborted, or waiting.
isFinalStatus true when the status is completed, failed, or aborted.
isStatusSuccess true only when the workflow completed successfully.
answers Present only after a successful run.
usage Token usage for the analysis.
error A generic "Analysis failed" on failure. No internal error text is forwarded.

References identify the exact page and region:

  • fileId → GET /documents/:fileId or /pages to read the processed document.
  • pageNumber and regionIndex → the specific region on that page.
  • uploadedFileId → GET /files/:uploadedFileId/download to fetch the page image.
  • idx → the citation marker used in the answer text.

Workflow states

Status Final? Meaning
pending No Scheduled and waiting for a worker.
running No The agent is working.
waiting No The workflow is waiting on a child operation.
retry No The workflow is being retried.
completed Yes Answers are available.
failed Yes The workflow failed.
aborted Yes The workflow was stopped.

Error and isolation rules

  • A workflow of another company returns 404.
  • A workflow that exists but is not a document-research workflow returns 404.
  • A failed workflow returns 200 with isFinalStatus: true, isStatusSuccess: false, and error: "Analysis failed". Polling does not turn a failed run into a successful one; start a new analysis if you need to retry.
  • Analyses consume LLM tokens. usage reports the actual consumption for a successful run.

Best practices

  • Ask specific, verifiable questions. Broad questions produce broad answers and weaker citations.
  • Keep the question list short when latency matters; the workflow answers all questions in one run.
  • Store the mapping from your question text to questionId so you can join the answers back to your own data.
  • Treat the analysis as a research aid. For high-stakes decisions, open the cited pages and read them.