Skip to content

SDKs

Official SDKs are not yet published to PyPI or npm during the beta. Use a plain HTTP client — every endpoint is a normal JSON or NDJSON call, and the examples in this section use httpx (Python) and fetch (JavaScript).

Language Suggested client Example
Python httpx (or requests) Extract, Streaming
JavaScript / TypeScript built-in fetch Extract, Streaming
Anything else any HTTP client see the formats below

Not available yet

pip install trusttyped and npm install @trusttyped/sdk do not work yet. This page will be updated here when the packages are published; do not add them to your dependencies until then.

Minimal Python client

import httpx

BASE = "https://api.trusttyped.com"

class TrustTyped:
    def __init__(self, api_key: str):
        self.http = httpx.Client(
            base_url=BASE,
            headers={"Authorization": f"Bearer {api_key}"},
            timeout=120,
        )

    def extract(self, schema: dict, input: dict) -> dict:
        resp = self.http.post("/v1/extract", json={"schema": schema, "input": input})
        resp.raise_for_status()
        return resp.json()

    def stream(self, schema: dict, input: dict):
        with self.http.stream(
            "POST", "/v1/extract", json={"schema": schema, "input": input, "stream": True}
        ) as r:
            r.raise_for_status()
            for line in r.iter_lines():
                if line:
                    yield __import__("json").loads(line)

tt = TrustTyped("tt_live_…")
print(tt.extract({"total": {"type": "number", "integer": True}}, {"text": "Total 33000."}))

Minimal JavaScript client

const BASE = "https://api.trusttyped.com";

export function makeClient(apiKey) {
  return {
    async extract(schema, input) {
      const resp = await fetch(`${BASE}/v1/extract`, {
        method: "POST",
        headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
        body: JSON.stringify({ schema, input }),
      });
      if (!resp.ok) throw new Error((await resp.json()).error.code);
      return resp.json();
    },
  };
}

Conventions worth copying

  • Set a ≥120 s timeout. The engine is CPU-only today.
  • Send an Idempotency-Key on retried requests — see Idempotency.
  • Pass a X-Request-Id so your logs line up with support — see Extract.
  • Prefer streaming for anything user-facing — see Streaming.
  • Branch on error.code, never on message — see Errors.