> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sahlfinancial.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Bank statements

> Read a bank statement line by line and reconcile it. Synchronous up to 6 pages, queued with a webhook beyond.

`POST /v1/statements/extract` reads a bank statement (a native PDF, a scanned PDF or an image) into its header and its transactions, line by line, and reconciles the balances. `GET /v1/statements/{statement_id}` returns a queued statement. Scope for both: `statements:read`. Open to every plan.

All calls go to `https://app.sahlfinancial.com/api` with `Authorization: Bearer <key>`. The environment comes from `X-Sahl-Environment` (`sandbox` by default) or an `environment` form field. The Sandbox reads [specimen documents](https://docs.sahlfinancial.com/guides/sandbox-specimens.md) only. Production needs your workspace to be approved for Production API calls (see [Go live](https://docs.sahlfinancial.com/go-live.md#partner-document-apis)). Each key is limited to 60 calls a minute on these routes.

## Extract a statement

`multipart/form-data`:

| Part | Required | Rules |
| - | - | - |
| `file` | yes | PDF (native or scanned) or image (JPEG, PNG, TIFF, WebP). Up to 30 MB and up to 60 pages. |
| `reference` | no | Your id, 1 to 64 characters of `A-Z a-z 0-9 _ . : -`. Echoed back and sent in the webhook. |
| `environment` | no | `sandbox` or `production`. Must agree with `X-Sahl-Environment` if you send both. |

```bash cURL theme={"dark"}
curl -X POST https://app.sahlfinancial.com/api/v1/statements/extract \
  -H "Authorization: Bearer $SAHL_API_KEY" \
  -H "X-Sahl-Environment: sandbox" \
  -F file=@specimen-releve-bancaire.pdf \
  -F reference=releve-2026-07
```

```javascript JavaScript theme={"dark"}
import { openAsBlob } from "node:fs";

const form = new FormData();
form.append("file", await openAsBlob("specimen-releve-bancaire.pdf"), "specimen-releve-bancaire.pdf");
form.append("reference", "releve-2026-07");

const res = await fetch("https://app.sahlfinancial.com/api/v1/statements/extract", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SAHL_API_KEY}`,
    "X-Sahl-Environment": "sandbox",
  },
  body: form,
});
const statement = await res.json(); // 200 with the statement, or 202 with statement_id
```

```python Python theme={"dark"}
import os, requests

with open("specimen-releve-bancaire.pdf", "rb") as f:
    res = requests.post(
        "https://app.sahlfinancial.com/api/v1/statements/extract",
        headers={
            "Authorization": f"Bearer {os.environ['SAHL_API_KEY']}",
            "X-Sahl-Environment": "sandbox",
        },
        files={"file": f},
        data={"reference": "releve-2026-07"},
        timeout=120,
    )
statement = res.json()
```

### Up to 6 pages: the answer is the statement (200)

```json theme={"dark"}
{
  "statement_id": null,
  "status": "completed",
  "environment": "sandbox",
  "reference": "releve-2026-07",
  "bank": "Banque Atlas du Maroc",
  "account_holder": "M. Soufiane Lahlou",
  "account_number": "9999546660564257",
  "rib": "811780999954666056425703",
  "iban": "MA64811780999954666056425703",
  "currency": "MAD",
  "period_start": "2026-07-01",
  "period_end": "2026-07-31",
  "opening_balance": 18450.75,
  "closing_balance": 22894.11,
  "transactions": [
    {"date": "2026-07-01", "value_date": null, "label": "VIREMENT SALAIRE JUILLET MENARA AGRO SA",
     "debit": null, "credit": 14250.0, "amount": 14250.0, "balance": 32700.75},
    {"date": "2026-07-03", "value_date": null, "label": "PRLV FACTURE EAU ELECTRICITE REF 7718245",
     "debit": 412.36, "credit": null, "amount": -412.36, "balance": 32288.39}
  ],
  "reconciliation": {
    "opening_balance": 18450.75, "movements_total": 4443.36,
    "expected_closing_balance": 22894.11, "closing_balance": 22894.11,
    "difference": 0.0, "passed": true, "gaps": [],
    "totals": [{"kind": "total_debits", "printed": 13306.64, "rows_sum": 13306.64, "passed": true}]
  },
  "warnings": [],
  "read": {"pages": 1, "scanned": false, "source": "text_layer", "model_calls": 0},
  "billing": {"documents_billed": 1, "pages": 1, "environment": "sandbox"},
  "latency_ms": 310
}
```

The values come from Sahl's synthetic sample statement.

* **Line by line.** Every transaction row, with `amount` signed (credit positive, debit negative), as a number with two decimals.
* **Reconciliation is the acceptance test.** The opening balance plus all movements must equal the closing balance, each printed running balance must follow from the previous one, and printed totals must equal the sum of the rows. A break is reported in `gaps` with its row, as a missed or misread line. `passed: null` means the balances could not be read, so nothing was checked: treat it as not verified.
* **Scans and native PDFs.** A native PDF is read from its text layer; a scan or image with OCR. When a scan does not reconcile, its rows are read again by Sahl's document reader and the reading that reconciles best is kept. `read.source` says which: `text_layer`, `ocr` or `vision`.
* **A synchronous read stores nothing.**

### More than 6 pages: queued (202)

A statement of 7 to 60 pages is queued. The answer is HTTP 202:

```json theme={"dark"}
{
  "statement_id": "9e8d0000-0000-4000-8000-000000000005",
  "status": "queued",
  "environment": "production",
  "reference": "releve-2026-07",
  "pages": 14,
  "poll_url": "/api/v1/statements/9e8d0000-0000-4000-8000-000000000005",
  "webhook_event": "statement.extracted",
  "billing": {"documents_billed": 2, "pages": 14, "environment": "production"}
}
```

Wait for the `statement.extracted` webhook, or poll:

```bash theme={"dark"}
curl -H "Authorization: Bearer $SAHL_API_KEY" \
  https://app.sahlfinancial.com/api/v1/statements/$STATEMENT_ID
```

```json theme={"dark"}
{
  "statement_id": "9e8d0000-0000-4000-8000-000000000005",
  "status": "completed",
  "environment": "production",
  "reference": "releve-2026-07",
  "pages": 14,
  "created_at": "2026-11-24T10:00:00+00:00",
  "completed_at": "2026-11-24T10:00:40+00:00",
  "expires_at": "2026-12-01T10:00:40+00:00",
  "error_code": null,
  "billing": {"documents_billed": 2, "pages": 14, "environment": "production"},
  "bank": "...",
  "transactions": ["..."],
  "reconciliation": {"passed": true}
}
```

When `status` is `completed`, the answer carries the same statement fields as the synchronous answer. `status` is `queued`, `processing`, `completed` or `failed`; a `failed` job has an `error_code`: `sandbox_specimen_required`, or `processing_failed` when the statement could not be read. A queued result is kept 7 days, then the call answers 410 `statement_expired`. An unknown id, or another workspace's, answers 404 `not_found`. The uploaded file of a queued statement is deleted once it is read.

## Billing

One document per started block of 10 pages: 1 to 10 pages is 1 document, 11 to 20 is 2, and so on. Every answer carries `billing`. In Sandbox nothing counts against your plan, but a fair-use cap of 200 documents per workspace and UTC day applies (429 `sandbox_daily_cap_reached`). In Production the documents count against your plan's monthly quota together with documents uploaded in the console (429 `usage_limit_reached`). The quota is checked before the statement is read, so a refused call costs nothing. A statement Sahl could not queue is not billed.

## Which banks

There is no per-bank template. The reader handles the layout Moroccan banks share (date, value date, label, débit, crédit, solde, French labels) and names the bank from the header, or from the bank code of the RIB. A layout it does not read well shows up as a failed reconciliation with its `gaps`, never as invented rows. Sahl's tests run on synthetic statements and the coverage of each bank's real layout is still being measured. If a statement from your bank does not reconcile, send Sahl a specimen.

## Webhook

`statement.extracted` is sent when a queued statement has been read (or has failed). It carries `statement_id`, `reference`, `environment`, `status`, `error_code`, `transaction_count` and `reconciliation_passed`, and never a balance, a transaction or a name. See [Webhook endpoints](https://docs.sahlfinancial.com/guides/webhook-endpoints.md).

## Errors

| Status | `detail.code` | Cause |
| - | - | - |
| 400 | (message) | Unsupported file type, or the content does not match the declared type. |
| 403 | `production_api_not_approved`, `production_requires_paid_plan`, `work_email_required`, `production_trial_ended` | Production rules. See [Go live](https://docs.sahlfinancial.com/go-live.md#partner-document-apis). |
| 404 | `not_found` | Unknown statement id. |
| 410 | `statement_expired` | A queued result older than 7 days. |
| 413 | `statement_too_long` | More than 60 pages. Split it by period. |
| 413 | (message) | A file over 30 MB. |
| 422 | `invalid_reference`, `invalid_environment`, `environment_conflict` | Bad input. |
| 422 | `sandbox_specimen_required` | A real statement in the Sandbox. A queued one ends `failed` with this `error_code`. |
| 429 | `rate_limit_exceeded`, `sandbox_daily_cap_reached`, `usage_limit_reached` | See above. |
| 503 | `storage_unavailable` | A long statement could not be queued. Nothing is billed. Retry. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.