# Open a draft from a receipt photo

`POST /businesses/{bid}/expenses/ocr`

Requires the `ocr` scope.

POST the raw image or PDF bytes with the matching `Content-Type`. A vision model reads the receipt and opens a draft expense from what it found; your user confirms and records.

Requires the `ocr` scope, which is granted separately, because every scan runs a billed AI call. Bodies are capped at 5MB and there is a daily quota per key.

## Path parameters

| Name | Type | | Description |
|---|---|---|---|
| `bid` | string | **required** | Business id, from `POST /businesses`. |

## Body

Raw bytes. Accepted content types: `image/jpeg`, `image/png`, `application/pdf`.

## Response

`201`: `{ "ok": true, … }`

| Field | Type | | Description |
|---|---|---|---|
| `ok` | boolean | **required** |  |
| `expense` | Expense | **required** | The purchase side of the ledger. A recorded expense is immutable; correct it with a storno. |
| `extracted` | OcrExtraction |  | What the vision model read off the receipt. Advisory: the operator confirms before recording. |
| `fileId` | string |  | The stored receipt. |

Errors: `400`, `401`, `403`, `404`, `413`, `429`. Every failure answers `{ "error": …, "reason": … }`. Branch on `reason`.

## Examples

### cURL

```bash
curl -X POST "$BASE/businesses/$BID/expenses/ocr" \
  -H "X-Api-Key: $KEY" \
  -H "Content-Type: image/jpeg" \
  --data-binary @receipt.jpg
```
### Node

```node
const res = await fetch(`${BASE}/businesses/${BID}/expenses/ocr`, {
  method: 'POST',
  headers: {
    'X-Api-Key': KEY,
  },
})
const data = await res.json()
if (!data.ok) throw new Error(data.reason)
```
### Python

```python
import requests
res = requests.post(
    f"{BASE}/businesses/{BID}/expenses/ocr",
    headers={"X-Api-Key": KEY},
)
data = res.json()
```