---
title: "Deploy PaddleOCR | (Just Updated) OCR API for Images and PDFs, Weights Baked In, API Key Pre-Set"
description: "PaddleOCR PP-OCRv6 text recognition API for images and PDFs, API key set"
category: "AI/ML"
url: https://railway.com/deploy/paddleocr-or-just-updated-ocr-api-for-im
---

# Deploy PaddleOCR | (Just Updated) OCR API for Images and PDFs, Weights Baked In, API Key Pre-Set

PaddleOCR PP-OCRv6 text recognition API for images and PDFs, API key set

**[Deploy PaddleOCR | (Just Updated) OCR API for Images and PDFs, Weights Baked In, API Key Pre-Set on Railway](https://railway.com/template/paddleocr-or-just-updated-ocr-api-for-im)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/paddleocr-or-just-updated-ocr-api-for-im/manifest.json

- **Creator:** SuperSlowSloth
- **Category:** AI/ML

## Template content

### paddleocr

- **Image:** ghcr.io/bon5co/paddleocr-railway:1.0.0@sha256:a6362c9acf550f73ce60ec2b739cbf20c1f9c0f7b332d7fa9c2bc749b990b98d
- **Health check:** /health
- **Public domain:** Yes

## Documentation

# Deploy and Host PaddleOCR on Railway

PaddleOCR is the open-source OCR toolkit from Baidu's PaddlePaddle team. This template serves its current PP-OCRv6 text detection and recognition models as one HTTP API: upload a scan, a photo or a PDF and get back the text, a confidence score for every line and the box it sits in. The weights are already inside the image, a bearer key is generated for you at deploy, and everything runs on CPU.

## About Hosting PaddleOCR

This template runs PaddleOCR 3.7.0 with PaddlePaddle 3.3.1 behind a small FastAPI server. `POST /ocr` takes a multipart `file` (PNG, JPEG, WebP, TIFF, BMP or PDF) and returns `text`, a per-page `pages` array and, for every line, `text`, `confidence`, an axis-aligned `box` and the four-point `polygon`. PDFs are rendered page by page with pdfium, so a scanned PDF and a photographed receipt go through the same call.

All three PP-OCRv6 sizes (medium, small, tiny) and the page-orientation model are baked into the image, so the first request is answered from disk and no model download hides inside a request that Railway's edge would abandon after five minutes. The default is the **small** tier; set `OCR_TIER` to `medium` for a little more accuracy or `tiny` for speed. The service sizes its thread pool from the container's own CPU quota instead of the host's core count, which a container otherwise oversubscribes. Requests are processed one at a time so memory stays bounded.

**Measured on Railway, 8 vCPU, one dense A4 page (53 lines, 1240 by 1754 pixels):** small tier **28.6 to 30.3 s** per page and **85.9 s** for a three-page PDF; medium tier **55 s** per page and **158 s** for the same three pages. Measured locally on 4 vCPU, resident memory peaked at **1.65 GB** (small tier, three-page PDF) and **2.25 GB** (medium tier, one page); a 2 GB container was OOM-killed on the three-page PDF. Give the service **4 GB of RAM**. A page of sparse text is far quicker than a dense one. Because of the five minute edge limit the number of PDF pages per request is capped (`MAX_PAGES`: 8 for small, 4 for medium, 20 for tiny) and a longer PDF is read in slices with `first_page`; the response carries `next_page` until the document ends.

### Agent contract

- Public URL: `https://RAILWAY_PUBLIC_DOMAIN` (the generated domain of the `paddleocr` service)
- Private URL: `http://paddleocr.railway.internal:8080`
- Credentials: the `API_KEY` variable of the `paddleocr` service
- Auth: send `Authorization: Bearer $API_KEY` on every route except `GET /health`; a call without the key or with a wrong one answers `401`
- Health: `GET /health` returns 200 once the model is loaded (503 while it loads)

```bash
# needs: RAILWAY_PUBLIC_DOMAIN, API_KEY (a variable of the paddleocr service); also curl, base64, mktemp.
R="https://$RAILWAY_PUBLIC_DOMAIN"
n=0; until [ "$(curl -s -o /dev/null -w '%{http_code}' "$R/health")" = 200 ]; do n=$((n+1)); [ "$n" -le 60 ] || break; sleep 5; done
curl -s -o /dev/null -w "health: %{http_code}\n" "$R/health"
# a 560x90 PNG that reads "Invoice 4821 Total 1,284.50"
F=$(mktemp --suffix=.png); echo 'iVBORw0KGgoAAAANSUhEUgAAAjAAAABaAQAAAACOelHXAAADGUlEQVR42u2YQYscRRTHf9XTZDpk3G0UYZWNNnr1sMhCBgUpRPSqn8D1C8igF0VlCwkiEs0cc1w85ZoP4FKRgQySwxw9BNI6Q1hBQs9kkJqhp56H7p6dXWc3HoIE6b68qn6PX/3fq1dFzyjhSTwBNabG1JgaU2NqTI3532JG/6GabjmcljZeRIw1PcZKLeN68JuZxUjC7YDwHDVZNZjOGQzQxUQKq+Hg4KhcSRaPT0oY3+fdzwQ2xj8dv0S+z4aHeLh0b97WZ2PiwniCLV7Q8wTF25VvnsDrJtwhh94r9M5R01puTLif5O7Egk7jtes3y1mQrsH0own9sR5JzFXIDUBy0QBINO/NErhoivowA1gp/QpmMW/CYMB8Kl+VgeCLZOZwlFUzYHJO33wI/femHB36XU1GnqPTCICj+9/sDtsQAcY6RwqxndBZp+aGga2UxpX8FwhIUCYp3I1tot6XxRCtIYQ/3veYdWrC0AieEZ+TMuKZm6bq/xRLVCLpv/gBfYimwVpMAHSTGBuioE/0EdjCHa72ldn8mS48Ojz7THmESE3K/SyKAVjS4zrEWQhwbWc9JiSwiY4gMBi6jB8uD1qkWCqTZHhPEjBypprSs1AdSXhw6UTkeK8SfPd5r2EnevxFEXuw4PeOXw1Km1tDXnbh2p1CpUXrN76wXCEKbL4ScqfsfEccmo8LXesxeKzDwdUk/+4TwJVxTuDbKjnAPTcCnl3eUacwBq2I8JTJPCrdEUl18nlQ2oSHx3fTSUz2tQU362Kb8oPzVCe4vRJqyfJN2QYXL9GnMDlphi73UqPvVmX1UDFvYDBAR4mcsVNaZb+TO/EJkOfLEr6U67RIYLYPzgEHLot8sh4z4693uHwr2tXA5V/3N0oFctP8+elbCwC/bd+4BXTe/DF8Tf/j6pXrd/L922I3h1nDIyLXM5XTkKHIWJyShnk1FRk6RzNtiLy8aZseOfUEVfV3OrRaqgnQurBc5MIGZs/GgAO2WkC33VaN02LUv/0BPdl4mj4FgieDyc71qvrPhRpTY2pMjakxNabGPC2YvwGzMUOx56FdPAAAAABJRU5ErkJggg==' | base64 -d | dd of="$F" status=none
curl -s -o /dev/null -w "write without key: %{http_code}\n" -X POST "$R/ocr" -F file=@"$F"
curl -s -o /dev/null -w "write wrong key: %{http_code}\n" -X POST "$R/ocr" -H "Authorization: Bearer not-the-key" -F file=@"$F"
curl -s -X POST "$R/ocr" -H "Authorization: Bearer $API_KEY" -F file=@"$F" | grep -o '"model":"[^"]*"\|"text":"[^"]*","pages"' | sed 's/,"pages"//; s/"//g; s/:/: /'
rm -f "$F"
```

A fresh deploy prints `health: 200`, `write without key: 401`, `write wrong key: 401`, `model: PP-OCRv6_small` and `text: Invoice 4821 Total 1,284.50`. The snippet uploads a small PNG that it writes itself, so it needs no file of yours. To read a real document:

```bash
curl -X POST "https://$RAILWAY_PUBLIC_DOMAIN/ocr?min_confidence=0.5" \
  -H "Authorization: Bearer $API_KEY" -F file=@scan.pdf
```

Query parameters: `min_confidence` drops lines scored below it, `rotate=false` turns the page-orientation check off, `first_page` and `max_pages` select PDF pages.

## Why Deploy PaddleOCR on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying PaddleOCR on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

- **Documents stay on your infrastructure** — scans, invoices and IDs are read by your own container, not sent to a third-party OCR API.
- **Answers the first request** — the models are inside the image, so there is no download hiding in your first call.
- **Private by default** — a generated bearer key guards every route but the health check, and the container refuses to start without one.
- **Flat CPU pricing** — no per-page fee and no GPU bill.

## Common Use Cases

- **Invoice and receipt capture** — turn a photographed receipt or a scanned invoice into text and line positions for bookkeeping automation.
- **Searchable archives** — run scanned PDFs through the API and index the text next to the original file.
- **AI agent tool** — give an LLM agent a vision-free way to read screenshots, forms and PDFs by calling one authenticated endpoint.

## Dependencies for PaddleOCR Hosting

- A service with **4 GB of RAM** (measured peak 1.65 GB for the small tier on a three-page PDF, 2.25 GB for the medium tier, OOM-killed at 2 GB). Free and Trial plans cannot run it.
- No volume: the service keeps no state and every model is in the image.

### Deployment Dependencies

- [PaddlePaddle/PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) — the upstream toolkit, Apache-2.0
- [bon5co/paddleocr-railway](https://github.com/bon5co/paddleocr-railway) — the Railway wrapper image this template deploys, Apache-2.0
- Weights licence: the PP-OCRv6 models baked into the image (`PaddlePaddle/PP-OCRv6_medium_det`, `_medium_rec`, `_small_det`, `_small_rec`, `_tiny_det`, `_tiny_rec`) and the orientation model `PaddlePaddle/PP-LCNet_x1_0_doc_ori` each carry `license: apache-2.0` in their Hugging Face model card, and the PaddleOCR repository's LICENSE reads "Apache License Version 2.0, January 2004". Apache-2.0 allows commercial use.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/paddleocr-or-just-updated-ocr-api-for-im
