# Getting started with Xberg Enterprise

A minimal end-to-end walkthrough: sign up, get an API key, extract one document.

## 1. Get access

Xberg Enterprise (the managed cloud API) is reached through the invitation-only Design Partner program — apply at <https://xberg.io/apply>. Once accepted, the dashboard creates a default project (more can be created from `/dashboard`); generate an API key from project settings. Keys look like `kz_…`. Treat them as secrets.

Don't want to wait on an application? Self-host the open-source library (free, MIT-licensed — see [section 6](#6-open-source-alternative)), or ask about Xberg Pro, the self-hosted single-container product.

## 2. Extract a document — curl

The extraction API base URL is `https://api.xberg.io`. Inline `POST /v1/extract` is the simplest path; max 10 documents per request, max 1 MB per document.

```bash
# Encode without line wrapping. Use base64 -w0 on Linux, -i on macOS.
B64=$(base64 < invoice.pdf | tr -d '\n')

curl -X POST https://api.xberg.io/v1/extract \
  -H "Authorization: Bearer $XBERG_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "documents": [{
      "filename": "invoice.pdf",
      "mime_type": "application/pdf",
      "data": "'"$B64"'"
    }],
    "options": {
      "extraction_config": {
        "output_format": "markdown",
        "ocr": { "backend": "tesseract", "language": "eng" }
      }
    },
    "webhook": {
      "url": "https://your-app.invalid/hooks/xberg",
      "secret": "your-shared-secret"
    }
  }'
```

Response (HTTP 202):

```json
{ "job_ids": ["550e8400-e29b-41d4-a716-446655440000"], "status": "pending" }
```

Poll the job (or wait for the webhook):

```bash
curl -H "Authorization: Bearer $XBERG_API_KEY" \
  https://api.xberg.io/v1/jobs/550e8400-e29b-41d4-a716-446655440000
```

Recommended polling cadence: every 1 second for the first ~10 seconds, then every 5 seconds. Treat any `*ing` status (`pending`, `processing`, `chunking`, `aggregating`) as in-flight.

## 3. Python

```python
import base64
import httpx

with open("invoice.pdf", "rb") as f:
    data = base64.b64encode(f.read()).decode()

response = httpx.post(
    "https://api.xberg.io/v1/extract",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
        "documents": [{
            "filename": "invoice.pdf",
            "mime_type": "application/pdf",
            "data": data,
        }],
        "options": {
            "extraction_config": {
                "output_format": "markdown",
                "ocr": {"backend": "tesseract", "language": "eng"},
            },
        },
        "webhook": {"url": webhook_url, "secret": webhook_secret},
    },
)
response.raise_for_status()
job_ids = response.json()["job_ids"]
```

## 4. TypeScript

```ts
const data = Buffer.from(await fs.readFile("invoice.pdf")).toString("base64");

const response = await fetch("https://api.xberg.io/v1/extract", {
	method: "POST",
	headers: {
		Authorization: `Bearer ${apiKey}`,
		"Content-Type": "application/json",
	},
	body: JSON.stringify({
		documents: [{ filename: "invoice.pdf", mime_type: "application/pdf", data }],
		options: {
			extraction_config: {
				output_format: "markdown",
				ocr: { backend: "tesseract", language: "eng" },
			},
		},
		webhook: { url: webhookUrl, secret: webhookSecret },
	}),
});
const { job_ids } = await response.json();
```

## 5. Verifying webhook signatures

Webhooks include `X-Webhook-Signature: t=<unix seconds>,v1=<hex>` when a `webhook.secret` is supplied. Compute HMAC-SHA256 of `"<t>.<raw body>"` using the secret as the key, hex-encode, and compare with `v1`. Reject a delivery whose `t` is more than 5 minutes from your clock.

```python
import hmac, hashlib, time
parts = dict(p.split("=", 1) for p in request.headers["X-Webhook-Signature"].split(","))
assert abs(time.time() - int(parts["t"])) <= 300
expected = hmac.new(secret.encode(), f"{parts['t']}.".encode() + raw_body, hashlib.sha256).hexdigest()
assert hmac.compare_digest(expected, parts["v1"])
```

## 6. Open-source alternative

If you'd rather self-host, the same extraction core is on GitHub: <https://github.com/xberg-io/xberg>. SDKs ship for Rust, Python, Node.js, WebAssembly, Java, Go, C#, PHP, Ruby, Elixir, Dart, Kotlin, Swift, Zig, and C (FFI) — 15 total. License is MIT (free for personal, internal, and commercial use; the only requirement is preserving the copyright notice). Arbitrary embedding providers are available in the self-hosted library, alongside the Tesseract, PaddleOCR, Candle, and VLM OCR backends.

## See also

- [Capabilities](https://xberg.io/llms/capabilities.md)
- [Extraction API](https://xberg.io/llms/api.md)
- [Pricing](https://xberg.io/llms/pricing.md)
- [Full documentation](https://docs.xberg.io/)
