# Server SDKs

> Kontiga is document fraud detection by Bynn Intelligence for insurers, letting agents, lenders and HR screening teams: every document is compared with a proprietary library of more than 300 million original documents, gathered over 20 years.

Documentation index: https://kontiga.com/llms.txt

Section: Reference. URL: https://kontiga.com/docs/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 December 1, 2026

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.

TypeScript:

```typescript
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);
```

Python:

```python
from kontiga import Kontiga

kontiga = Kontiga()  # reads KONTIGA_API_KEY
document = kontiga.check_file("payslip.pdf", {"wait": 10})
print(document["verdict"], document["risk_score"], document["findings"])
```

Go:

```go
client, err := kontiga.NewClient() // reads KONTIGA_API_KEY
if err != nil {
	return err
}
res, err := client.CheckFile(ctx, "payslip.pdf", kontiga.Params{"wait": 10})
if err != nil {
	return err
}
var document struct {
	Verdict   string  `json:"verdict"`
	RiskScore float64 `json:"risk_score"`
}
err = res.Decode(&document)
```

Java:

```java
Kontiga kontiga = new Kontiga(); // reads KONTIGA_API_KEY
Map<String, Object> document = (Map<String, Object>) kontiga.checkFile(Path.of("payslip.pdf"), Map.of("wait", 10));
System.out.println(document.get("verdict"));
```

.NET:

```csharp
var kontiga = new KontigaClient(); // reads KONTIGA_API_KEY
var document = await kontiga.CheckFileAsync("payslip.pdf", new Dictionary<string, object?> { ["wait"] = 10 });
Console.WriteLine(document["verdict"]);
```

PHP:

```php
$kontiga = new \Bynn\Kontiga\Kontiga(); // reads KONTIGA_API_KEY
$document = $kontiga->checkFile('payslip.pdf', ['wait' => 10]);
echo $document['verdict'];
```

Ruby:

```ruby
kontiga = Kontiga::Client.new # reads KONTIGA_API_KEY
document = kontiga.check_file("payslip.pdf", { "wait" => 10 })
puts document["verdict"]
```

Rust:

```rust
let kontiga = kontiga::Client::new()?; // reads KONTIGA_API_KEY
let answer = kontiga.check_file("payslip.pdf", Some(serde_json::json!({ "wait": 10 }))).await?;
println!("{}", answer.json()["verdict"]);
```

## 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.

TypeScript:

```typescript
const document = await kontiga.documents.get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a");
const page = await kontiga.documents.list({ verdict: "high_risk", limit: 20 });
```

Python:

```python
document = kontiga.documents.get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a")
page = kontiga.documents.list({"verdict": "high_risk", "limit": 20})
```

Go:

```go
res, err := client.Documents.Get(ctx, "doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a", nil)
page, err := client.Documents.List(ctx, kontiga.Params{"verdict": "high_risk", "limit": 20})
```

Java:

```java
Object document = kontiga.documents.get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a");
Object page = kontiga.documents.list(Map.of("verdict", "high_risk", "limit", 20));
```

.NET:

```csharp
var document = await kontiga.Documents.GetAsync("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a");
var page = await kontiga.Documents.ListAsync(new Dictionary<string, object?> { ["verdict"] = "high_risk", ["limit"] = 20 });
```

PHP:

```php
$document = $kontiga->documents->get('doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a');
$page = $kontiga->documents->list(['verdict' => 'high_risk', 'limit' => 20]);
```

Ruby:

```ruby
document = kontiga.documents.get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a")
page = kontiga.documents.list({ "verdict" => "high_risk", "limit" => 20 })
```

Rust:

```rust
let document = kontiga.documents().get("doc_0193f6b8e1a47c2d9b3f5a6e7d8c9b0a", None, Default::default()).await?;
let page = kontiga.documents().list(Some(json!({ "verdict": "high_risk", "limit": 20 })), Default::default()).await?;
```

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

| Answer | Error |
| --- | --- |
| `400` | `BadRequestError` |
| `401` | `AuthenticationError` |
| `402` | `InsufficientCreditError` |
| `403` | `PermissionDeniedError` |
| `404` | `NotFoundError` |
| `409` | `ConflictError` |
| `413` | `RequestTooLargeError` |
| `422` | `ValidationError`, with `issues` |
| `429` | `RateLimitError`, with `retry_after` |
| `503` | `ServiceUnavailableError`, with `retry_after` |
| Any other `5xx` | `ServerError` |
| No answer | `APIConnectionError`, 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](https://kontiga.com/docs/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.
