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.
Set XBERG_BASE_URL to your deployment origin, XBERG_API_KEY to a project key, and
XBERG_TARGET to pro or enterprise. Set XBERG_DOCUMENT to the path of a text document
containing Xberg SDK snippet fixture, or replace the example’s content assertion with your own
expected text. The repository provides this document as test_documents/snippet.txt.
Extract one document and wait
Section titled “Extract one document and wait”import osfrom pathlib import Path
from xberg_io_sdk import XbergClient
with XbergClient( api_key=os.environ["XBERG_API_KEY"], base_url=os.environ["XBERG_BASE_URL"], target=os.environ["XBERG_TARGET"],) as client: job = client.extract_and_wait(file=Path(os.environ["XBERG_DOCUMENT"])) result = client.get_job_result(str(job.id)) if not result.results or "Xberg SDK snippet fixture" not in result.results[0].content: raise RuntimeError("The extracted document did not contain the expected text") print("Extraction verified")import { readFile } from "node:fs/promises";import { XbergClient } from "@xberg-io/sdk";
const baseUrl = process.env.XBERG_BASE_URL;if (!baseUrl) throw new Error("Set XBERG_BASE_URL to your deployment URL");const client = new XbergClient({ apiKey: process.env.XBERG_API_KEY, baseUrl, target: process.env.XBERG_TARGET === "pro" ? "pro" : "enterprise",});const document = process.env.XBERG_DOCUMENT;if (!document) throw new Error("Set XBERG_DOCUMENT to a local document path");const data = await readFile(document);const job = await client.extractAndWait({ file: { name: "snippet.txt", data, mimeType: "text/plain" } });const result = await client.getJobResult(job.id);if (!result.results?.[0]?.content?.includes("Xberg SDK snippet fixture")) { throw new Error("The extracted document did not contain the expected text");}console.log("Extraction verified");package main
import ( "context" "fmt" "os" "strings"
xberg "github.com/xberg-io/sdks/packages/go")
func run() error { client, err := xberg.New( xberg.WithAPIKey(os.Getenv("XBERG_API_KEY")), xberg.WithBaseURL(os.Getenv("XBERG_BASE_URL")), xberg.WithTarget(xberg.Target(os.Getenv("XBERG_TARGET"))), ) if err != nil { return err } file, err := os.Open(os.Getenv("XBERG_DOCUMENT")) if err != nil { return err } defer file.Close() job, err := client.ExtractAndWait(context.Background(), xberg.FileSource{Name: "snippet.txt", Reader: file}, nil) if err != nil { return err } result, err := client.GetJobResult(context.Background(), job.Id.String()) if err != nil { return err } if result.Results == nil || len(*result.Results) != 1 || !strings.Contains((*result.Results)[0].Content, "Xberg SDK snippet fixture") { return fmt.Errorf("the extracted document did not contain the expected text") } fmt.Println("Extraction verified") return nil}
func main() { if err := run(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) }}What extract_and_wait actually does
Section titled “What extract_and_wait actually does”The helper submits and polls; the example then reads the result:
- 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.