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

# Upload a document for OCR

> Send a card image as multipart form data and read the extracted fields.

OCR endpoints take the image as `multipart/form-data` in a field named `file`. This recipe reads a PAN card with `POST /v2/verify/pan_ocr`. The same pattern works for `dl_ocr`, `aadhaar_ocr` and `invoice_ocr`.

**1. Set your credentials**

Use `https://dev.idto.ai` (staging) while you build and `https://prod.idto.ai` (production) when you go live. Keep the client ID and API key on your server only. Never ship them to a browser or a mobile app.

```bash .env theme={null}
IDTO_BASE_URL=https://dev.idto.ai
IDTO_CLIENT_ID=your-client-id
IDTO_API_KEY=your-api-key
```

```bash theme={null}
set -a; source .env; set +a
```

**2. Upload the image**

```bash curl theme={null}
curl -sS -X POST "$IDTO_BASE_URL/v2/verify/pan_ocr" \
  -H "X-Client-ID: $IDTO_CLIENT_ID" \
  -H "X-API-Key: $IDTO_API_KEY" \
  -F "file=@pan-card.jpg;type=image/jpeg"
```

```python ocr_upload.py theme={null}
import os
import sys

import requests

BASE_URL = os.environ.get("IDTO_BASE_URL", "https://dev.idto.ai")
HEADERS = {"X-Client-ID": os.environ["IDTO_CLIENT_ID"], "X-API-Key": os.environ["IDTO_API_KEY"]}


def read_pan_card(path):
    with open(path, "rb") as image:
        response = requests.post(
            f"{BASE_URL}/v2/verify/pan_ocr",
            headers=HEADERS,
            files={"file": (os.path.basename(path), image, "image/jpeg")},
            timeout=(5, 60),
        )
    return response.status_code, response.json()


if __name__ == "__main__":
    status, body = read_pan_card(sys.argv[1])
    print(status, body["status"], body["error_code"], body.get("billed"))
```

**3. Read the result**

```json 200 theme={null}
{
  "status": "success",
  "message": "PAN details extracted successfully.",
  "error_code": null,
  "data": {
    "pan_number": "ABCDE1234F",
    "name": "RAHUL SHARMA",
    "father_name": "SURESH SHARMA",
    "dob": "1990-01-01"
  },
  "billed": true
}
```

A readable image that is not a PAN card, or has no readable PAN, returns a `2xx` with a non-null `error_code`. Branch on `error_code` as in [Verify a PAN and branch on error\_code](https://idto.mintlify.site/recipes/verify-pan-branch-on-error-code.md).

## Good to know

* Do not set the `Content-Type` header yourself. curl `-F` and `requests` `files=` set the multipart boundary for you.
* Send an `Idempotency-Key` to make retries safe. See [Retry safely with an idempotency key](https://idto.mintlify.site/recipes/pan-ocr-idempotent-retry.md).

Was this page helpful? Email us at [tech@idto.ai](mailto:tech@idto.ai?subject=Docs%20feedback%3A%20Upload%20a%20document%20for%20OCR) with the page link.


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