Skip to content

ReferenceDevelopers

Server SDKs

Kontiga’s API in eight languages: TypeScript, Python, Go, Java, .NET, PHP, Ruby and Rust. One method per call of the API, typed errors, retries that are safe to repeat, and file uploads, the same in every language.

Updated

Ask about this pageRead this page as Markdown

Each client reads its key from KONTIGA_API_KEY and the API’s address from KONTIGA_BASE_URL when you pass neither. Use a secret key on your server only, never in a browser or an app. A test key (kt_test_) works on Kontiga’s sample documents and is never billed.

Check a document

One call uploads a file and checks it. The answer is the document: its state, verdict, risk_score, fraud_score and findings. With wait (up to 10 seconds) the first result comes back in the answer; read the document again, or take the document.checked webhook, for the full result.

Every call of the API

Every call of the API is a method, grouped by its resource: documents.get is documents.get(...) in Python and Ruby, documents.get(...) in TypeScript, PHP and Java, Documents.Get(...) in Go and Documents.GetAsync(...) in .NET. The path’s ids come first, in order; an id that is empty, . or .., or holds a slash, is refused before anything is sent. Every other parameter goes in one map, sent as the query of a GET or a DELETE and as the JSON body of any other call. The answer is the API’s JSON exactly as it was sent, numbers and empty objects included, or a file for a download. Each resource’s page lists its calls.

A call only a signed-in member may make, such as a second approval, has no method: a key gets 403. Every client can still call any route by its method and path (request_path in Python, Do in Go), with the same retries and errors.

Retries and idempotency keys

  • Every call is tried up to three times: after a 408, a 429, any 5xx, a timeout or a lost connection. A 400, 401, 402, 403, 404, 409 or 422 is never tried again.
  • When the API says how long to wait (Retry-After or retry-after-ms), the client waits that long, up to a minute; otherwise it waits about half a second, then a second.
  • When the API answers x-kontiga-should-retry, the client follows it.
  • Every write carries an Idempotency-Key, made by the client when you pass none, and the same key on each try, so a call is never done twice. Pass your own to make a repeat of your own safe.
  • Each try may take 60 seconds; set timeout and max_retries on the client or on one call.
  • Redirects are never followed, and the address must be https (plain http only on your own machine), so a key never travels unencrypted.

Errors

What each answer raises
AnswerError
400BadRequestError
401AuthenticationError
402InsufficientCreditError
403PermissionDeniedError
404NotFoundError
409ConflictError
413RequestTooLargeError
422ValidationError, with issues
429RateLimitError, with retry_after
503ServiceUnavailableError, with retry_after
Any other 5xxServerError
No answerAPIConnectionError, or APITimeoutError after the timeout

Every error is a KontigaError (KontigaException in Java, .NET and PHP; an *Error with its Kind in Go) with the API’s status, code, message, request_id, doc_url, issues and details. The code is stable: decide on it, and quote the request id when you write to support. See Errors.

Files

  • upload_file (uploadFile, UploadFile) asks for an upload address, sends the file’s bytes to it exactly as they are, and answers the upload with its upload_id. The storage gets only the headers the API gave: never your key.
  • check_file (checkFile, CheckFile) uploads a file and checks it in one call.
  • A download (the original file, the report) answers a file: its bytes, its type and its name. Send Accept: application/json on the call for a link that lives 5 minutes instead.
  • Send each file exactly as it arrived. Never resize, compress, crop, convert or save it again.
import { Kontiga } from "@kontiga/sdk";

const kontiga = new Kontiga(); // reads KONTIGA_API_KEY
const document = await kontiga.checkFile("payslip.pdf", { wait: 10 });
console.log(document.verdict, document.risk_score, document.findings);
const document = await kontiga.documents.get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a");
const page = await kontiga.documents.list({ verdict: "high_risk", limit: 20 });