Get started

SDKs and CLI

Clients for Python and TypeScript, and a trivda command line. They wrap every operation in the API reference, type the licence and provenance on every passage, retry safely and report what each search cost.

Python

ShellPython 3.9 or later
pip install trivda
export TRIVDA_URL="https://13-63-0-55.sslip.io"
export TRIVDA_API_KEY="sk_test_..."      # a sandbox key while you build
Python
from trivda import Trivda

client = Trivda()  # reads TRIVDA_URL and TRIVDA_API_KEY

result = client.search("How often should the compressor be serviced?", top_k=5)
for hit in result.results:
    print(hit.rank, round(hit.score, 2), hit.license.spdx, hit.citation.source_uri)
    print("   ", hit.text[:160])

print("cost EUR", result.cost.query_cost_eur, "| credits left", result.cost.credits_remaining)

Its one dependency is httpx. Errors are exceptions named after the status: InsufficientFundsError (402), RateLimitError (429, with retry_after), AuthenticationError (401) and so on, each with the server's detail.

TypeScript and JavaScript

ShellNode 20 or later, server-side only
npm install trivda
TypeScript
import { Trivda } from "trivda";

const client = new Trivda(); // reads TRIVDA_URL and TRIVDA_API_KEY

const result = await client.search("How often should the compressor be serviced?", { topK: 5 });
for (const hit of result.results ?? []) {
  console.log(hit.rank, hit.license?.spdx, hit.citation?.source_uri);
}
console.log("cost EUR", result.cost.queryCostEur);

No runtime dependencies: it uses the platform's fetch. ESM and CommonJS (require("trivda")) both work, with types. Methods are the operation ids in camelCase: listDatasets, usageWallet, uploadDataset.

What the clients do for you

Command line

The Python package installs a trivda command. It reads the same two environment variables, or takes --base-url and --api-key.

CommandDoes
trivda search "<question>" --top-k 5Search, and print each passage with its licence and the cost.
trivda datasets list --allList the datasets you can see, every page.
trivda balanceWallet credits, earnings and free searches.
trivda upload ./reports --dataset-id annual-reports --recursiveUpload a file, or every file in a folder, into one of your datasets. Private unless --offered.
trivda keys whoamiThe organisation, key and scopes in use, and whether the key is a sandbox key.

Add --json to any command for the API's JSON. The exit code is 1 when the API refused, with the reason printed.

Sandbox keys

A sandbox key starts with sk_test_. It works with the same routes and the same request and response shapes as a live key, but every answer comes from a fixed set of synthetic data. Use it to build and test before you spend credits.

Create one on the dashboard's API keys page with the Sandbox key switch, or with POST /api/v1/api-keys and "sandbox": true. GET /api/v1/api-keys/current tells you which kind of key a script is using. See Authentication.