Quickstart
Extraction is asynchronous on both tiers. Submitting returns job ids and a pending status; the
result arrives once the job reaches a terminal state. The clients wrap that loop for you, so
nothing rides on a single long-lived HTTP request and a large file cannot trip a request timeout.
Extract one document and wait
Section titled “Extract one document and wait”from pathlib import Path
from xberg_io_sdk import XbergClient
with XbergClient(api_key="kz_...") as client: job = client.extract_and_wait(file=Path("invoice.pdf")) if job.result is not None: print(job.result.content)import { readFile } from "node:fs/promises";
import { XbergClient } from "@xberg-io/sdk";
const client = new XbergClient({ apiKey: process.env.XBERG_API_KEY! });
const data = await readFile("invoice.pdf");const job = await client.extractAndWait({ file: { name: "invoice.pdf", data, mimeType: "application/pdf" },});
console.log(job.result?.content);package main
import ( "context" "fmt" "log" "os"
xberg "github.com/xberg-io/sdks/packages/go")
func main() { client, err := xberg.New(xberg.WithAPIKey("kz_...")) if err != nil { log.Fatal(err) }
file, err := os.Open("invoice.pdf") if err != nil { log.Fatal(err) } defer file.Close()
job, err := client.ExtractAndWait(context.Background(), xberg.FileSource{Name: "invoice.pdf", Reader: file}, nil) if err != nil { log.Fatal(err) } fmt.Println(job.Status)}What extract_and_wait actually does
Section titled “What extract_and_wait actually does”It is a convenience over two calls you can make yourself:
- Submit —
POST /v1/extractreturnsjob_idsandstatus: "pending", with 202. - Poll —
GET /v1/jobs/{id}until the status is terminal (completed,partial_success,failedorcancelled). - Read —
GET /v1/jobs/{id}/resultreturns the extracted documents.
Two timeouts are in play and they are deliberately separate: a per-request timeout of 30 seconds, and a wait timeout of 5 minutes covering the whole poll loop. Polling starts at one second and can back off exponentially. Raise the wait timeout for large documents rather than the request timeout — the request is only ever a short status read.
If the job ends failed or cancelled, the wait raises rather than returning a job you would
have to inspect.