llmocrapi.comGuide
OCR API Integration: Code Examples in Python and Node
An OCR API integration here means adding one HTTP call after your OCR engine: you send the raw recognized text and get clean text back. The endpoint is OpenAI-compatible, so the SDK you probably already have works after you change two settings.
Updated

Key points
- Set the base URL to https://api.llmocrapi.com/v1, use the model ID uncensored, and send your key as a Bearer token.
- The API takes text only. Run your OCR engine first and pass its output as the user message.
- JSON mode returns machine-readable results, and a small thread pool of up to 8 workers keeps a batch fast.
- A 429 response is a signal to wait and retry, not a failure: failed requests are not charged.
Where the call fits in a pipeline
A typical document flow has four steps. A scanner or phone camera produces an image, an OCR engine turns the image into raw text, a cleanup step repairs that text, and your application stores or searches the result. The API described here is step three. It never sees the image, and it has no image input. This is a feature when you care about privacy of the original scans, because only text leaves your machine, and a limit when you expected a single endpoint that handles pictures.
Prompts are not used for training. Still, send only what the task needs: strip account numbers or names before the call if the cleanup does not depend on them.
Before you write any code, get an API key. New users can claim $0.50 of trial credit with one click on that page after signing up, which is enough to run every example below many times. The trial key allows 2 concurrent requests and 60 requests per minute; a full key allows 8 and 300.
Settings you need
| Setting | Value |
|---|---|
| Base URL | https://api.llmocrapi.com/v1 |
| Endpoint | POST /v1/chat/completions |
| Model ID | uncensored |
| Auth header | Authorization: Bearer YOUR_KEY |
| Context window | 100,000 tokens, prompt plus completion |
Store the key in an environment variable, never in source control. The examples read LLMOCR_API_KEY.
Two practical notes before you start. Keep the key out of front-end code, since anything shipped to a browser can be read by its users; call the API from a server or a worker. And decide early where raw OCR text and cleaned text will live, because the cleaned output is the file you will search, index and show to people, while the raw text is your evidence if a correction is ever questioned.
First request with curl
Start with curl so you can see the raw shape of a request before an SDK hides it. The sample below is a typical damaged OCR fragment: a hyphen split across a line break, a letter confused with a digit, and a stray page number.
curl https://api.llmocrapi.com/v1/chat/completions \
-H "Authorization: Bearer $LLMOCR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"temperature": 0,
"messages": [
{"role": "system", "content": "You repair raw OCR text. Fix broken words, rejoin hyphenated line breaks, remove page numbers. Return only the corrected text."},
{"role": "user", "content": "The inven-\ntory was com1leted on Tuesday.\n\n- 14 -\n\nA second ship-\nment arrived."}
]
}'
The reply follows the standard chat completion shape. The cleaned text is in choices[0].message.content, and usage reports the prompt and completion tokens for the call. Set temperature to 0 for cleanup. You want the same input to give the same output, not creative variation.
Python with the OpenAI SDK
Install the SDK with pip install openai. Only the constructor differs from a standard OpenAI setup.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.llmocrapi.com/v1",
api_key=os.environ["LLMOCR_API_KEY"],
max_retries=4,
)
SYSTEM = (
"You repair raw OCR text. Fix broken words, rejoin hyphenated line breaks, "
"remove page numbers and running headers. Do not add or remove facts. "
"Return only the corrected text."
)
def clean(raw: str) -> str:
resp = client.chat.completions.create(
model="uncensored",
temperature=0,
messages=[
{"role": "system", "content": SYSTEM},
{"role": "user", "content": raw},
],
)
return resp.choices[0].message.content
print(clean("The inven-\ntory was com1leted on Tuesday."))
The max_retries argument tells the SDK to retry on connection errors and 429 responses with backoff, so you do not need to write that loop yourself for light use.
Node.js example
With npm install openai and an ES module, the same call looks like this.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.llmocrapi.com/v1",
apiKey: process.env.LLMOCR_API_KEY,
});
export async function clean(raw) {
const resp = await client.chat.completions.create({
model: "uncensored",
temperature: 0,
messages: [
{ role: "system", content: "Repair raw OCR text. Return only the corrected text." },
{ role: "user", content: raw },
],
});
return resp.choices[0].message.content;
}
console.log(await clean("A second ship-\nment arrived."));
Anything that speaks the OpenAI chat format, such as a no-code automation tool or an existing internal wrapper, can use the same two settings. The documentation lists every supported parameter.
Structured output with JSON mode
Free text is fine for archives, but data extraction pipelines need fields. Turn on JSON mode with response_format and describe the shape you want in the prompt. Asking for JSON in the instructions as well as in the setting gives the most reliable results.
import json
resp = client.chat.completions.create(
model="uncensored",
temperature=0,
response_format={"type": "json_object"},
messages=[
{"role": "system", "content": (
"Clean the OCR text of a receipt and answer in JSON with keys "
"'vendor' (string), 'date' (YYYY-MM-DD or null), 'total' (number or null), "
"'cleaned_text' (string)."
)},
{"role": "user", "content": raw_receipt_text},
],
)
data = json.loads(resp.choices[0].message.content)
Always wrap json.loads in a try block and keep the raw text, because a very long or truncated response can still produce invalid JSON. If parsing fails, retry once and then queue the page for manual review.
Processing a batch in parallel
A single request at a time is slow for thousands of pages. A full key allows 8 concurrent requests, so a pool of 6 or 8 workers keeps you under the limit. Leave a little headroom if the same key is used by anything else.
from concurrent.futures import ThreadPoolExecutor
pages = [open(f"ocr/page_{i:04d}.txt").read() for i in range(1, 501)]
with ThreadPoolExecutor(max_workers=6) as pool:
cleaned = list(pool.map(clean, pages))
for i, text in enumerate(cleaned, start=1):
open(f"clean/page_{i:04d}.txt", "w").write(text)
If you do go over the limit, the API returns HTTP 429. The error code rate_limited means too many requests per minute, and concurrency means too many at once. A 429 with a Retry-After: 5 header means temporary overload: wait five seconds. Streamed requests keep a concurrency slot until the stream ends, so close streams you stop reading.
Watch the X-Balance-USD response header in long runs. When it gets low, pause and top up from the pricing page instead of letting the job fail midway.
Long documents and checking the output
Real OCR output is rarely one tidy page. A scanned book gives you thousands of pages, and the damage is uneven: a clean chapter, then a stained page full of broken characters. A few habits keep the cleanup step predictable.
Split by structure, not by character count. Cut at page breaks or paragraph boundaries, so the model never receives half a sentence at the start of a chunk. If a sentence runs across a page boundary, include the last paragraph of the previous page as read-only context and tell the model to return only the current page. That costs a few extra input tokens per request, which at $0.15 per 1M is almost nothing, and it fixes the hyphenated words that straddle two pages.
Verify each result with cheap checks before you accept it. Compare the length of the cleaned text with the source: a ratio far from 1 means the model dropped or invented material. Compare numbers: pull every digit sequence from both versions and flag pages where they differ, since dates, amounts and identifiers are the costliest errors to miss. Keep the raw OCR beside the cleaned text, so a person can always reconstruct what the engine actually saw.
Finally, treat the first run as a pilot. Clean 20 pages, read ten of them yourself, and tune the system prompt. Usually two or three rounds of edits to the instruction do more for quality than any parameter change.
Common mistakes
- Sending very large pages in one piece. The window is 100,000 tokens and the maximum request body is 8 MB, but accuracy is better with page-sized chunks, and a failed chunk costs less to redo.
- Letting the model rewrite. If the prompt does not say not to add or remove facts, it may smooth over a damaged passage. Keep the instruction explicit and compare lengths: a cleaned page that is far shorter than its source deserves a look.
- Using the wrong model name. The only model ID is
uncensored. You can list models withGET /v1/models. - Expecting embeddings or image input. Neither exists on this API. For search over cleaned text, use a separate embedding tool.
- Forgetting to log the request ID. Each response includes an
X-Request-Idheader. Store it next to the page so support can trace a bad result.
Content rules are simple: the model is tuned to answer without refusals for lawful adult use, and sexual content involving minors is never allowed. Questions about a specific case go to support.
More guides
Questions and answers
Do I need a special SDK?
No. Any OpenAI SDK or HTTP client works once you set the base URL to https://api.llmocrapi.com/v1, use the model ID uncensored and send a Bearer key.
Can I send an image or PDF directly?
No. The API accepts text only. Run an OCR engine first and send its output as the message content.
How many requests can I run at once?
A full key allows 8 concurrent requests and 300 requests per minute. A trial key allows 2 concurrent requests and 60 per minute.
What happens if I hit a rate limit?
You get HTTP 429 with the code rate_limited or concurrency. Wait and retry; failed requests are not charged.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.