# OCR an Image API

> Read the text in an image, by URL or as an inline base64 upload. Returns the full text plus every detected line with its confidence score and pixel bounding box. Runs locally on PP-OCR/ONNX — no cloud vision API, no per-image fee.

Category: [Tools APIs](https://upapi.io/apis/tools) · Last updated 2026-11-02

## How to call it

- Endpoint: `POST https://api.upapi.io/image-ocr.post`, key in the `X-Api-Key` header, JSON body.
- Cost: 4 weighted units per call.
- Timeout: 25 seconds.
- Cache: identical requests are served from cache for 86400 seconds, unbilled.
- Try it without writing code: https://app.upapi.io/try/image-ocr.post

```bash
curl -X POST https://api.upapi.io/image-ocr.post \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{ "url": "https://example.com/receipt.png" }'
```

## Request parameters

- `url` (string) — Public URL of the image to read (e.g. https://example.com/receipt.png). Provide this OR `file`, not both.
- `file` (string) — The image itself, base64-encoded (no data: URI prefix). Max 3.7 MB decoded — base64 inflates by 4/3 and the API request body is capped at 5 MB. Supply `url` instead for anything larger. Expected media type image/*.
- `languages` (array) — Scripts present in the image (e.g. en). Supported: ch, en — one bundled model covers Latin and Chinese. Omit for the default.

## Response fields

- `text` (string, required) — All recognised text, one detected line per row
- `width` (integer, required) — Image width in pixels
- `blocks` (array, required) — Each detected line with its confidence and box
- `blocks[].bbox` (object, required)
- `blocks[].bbox.x` (integer, required) — Left edge, pixels from the image's left
- `blocks[].bbox.y` (integer, required) — Top edge, pixels from the image's top
- `blocks[].bbox.width` (integer, required)
- `blocks[].bbox.height` (integer, required)
- `blocks[].text` (string, required) — Text of this detected line
- `blocks[].confidence` (number, required) — Recognition confidence, 0-1
- `height` (integer, required) — Image height in pixels
- `truncated` (boolean, required) — True when more than 5000 text blocks were detected and cut

## Example request and response

The example response is generated from the published output schema: it shows the shape and field names, not values from a recorded call.

```json
{
  "url": "https://example.com/receipt.png"
}
```

```json
{
  "text": "Hello, world",
  "width": 1,
  "blocks": [
    {
      "bbox": {
        "x": 1,
        "y": 1,
        "width": 1,
        "height": 1
      },
      "text": "Hello, world",
      "confidence": 1
    }
  ],
  "height": 1,
  "truncated": false
}
```

## Frequently asked questions

### How much does the OCR an Image API cost per call?

Each call spends 4 weighted units of your plan's monthly quota. Full pricing is at https://upapi.io/pricing.

### How do I authenticate to the OCR an Image API?

Send your key in the X-Api-Key header. A free guest key is available without creating an account.

### Are OCR an Image API responses cached?

Yes — identical requests are served from cache for 86400 seconds, and a cache hit is not billed.

## More Tools APIs

- [Extract Text from PDF](https://upapi.io/apis/tools/pdf-extract-text)
- [Render HTML or URL to PDF](https://upapi.io/apis/tools/html-to-pdf)
- [Capture Website Screenshot](https://upapi.io/apis/tools/screenshot)
- [Search Hacker News](https://upapi.io/apis/tools/hackernews-search)
- [Fetch URL as Markdown](https://upapi.io/apis/tools/fetch-markdown)
- [Get Cloudflare Page Title](https://upapi.io/apis/tools/cloudflare-page-title)
