OCR APIs turn text in images, scans, and screenshots into machine-readable data. Traditional OCR focuses on character recognition; multimodal models can go further, extracting structured fields, translating content, and proofreading the result.
This guide compares the main approaches, shows how to call an OCR-capable model through an OpenAI-compatible API, and explains how to evaluate accuracy before committing to a provider.
Note: OCR interfaces vary significantly between vendors. This article uses common approaches as examples; refer to official or in-site documentation for specifics.
1. Three OCR Approaches
| Approach | Best for | Characteristics |
|---|---|---|
| Traditional OCR | Invoices, ID documents, forms, receipts | Fast, inexpensive, reliable for fixed layouts |
| Multimodal LLM | Complex layouts, handwriting, understanding tasks | Flexible, but slower and more expensive |
| OCR + LLM | Recognizing first, then extracting or validating | Balances accuracy and structure |
No single approach is best for every document. A fixed invoice template and a handwritten note are different problems, and treating them as one often produces either unnecessary cost or unnecessary errors. The practical pattern is to match the method to the layout and to the value of the extracted data.
2. Traditional OCR APIs
Traditional services usually accept an image URL or a Base64 payload and return text plus bounding coordinates. They are suitable for:
- ID cards and business licenses.
- Invoices and receipts.
- Tables and forms.
- Fixed templates.
The advantages are speed and low cost. The limitation is that accuracy drops on complex layouts, handwriting, and low-quality images. Coordinate output is useful because it lets you match fields against a template and validate whether a value came from the expected region instead of trusting a single text blob.
3. Multimodal LLM OCR
With a vision-capable model, you send the image and ask for text or JSON directly:
Read the text in the image and output JSON by field:
{ "name": "", "amount": "", "date": "" }
This approach suits complex layouts and understanding tasks, but keep the following in mind:
- Image size and resolution limits.
- Output can vary, so validate it against a schema.
- Cost is higher than traditional OCR.
- Sensitive data requires a compliance review.
A useful compromise is to ask the model for both the raw text and the structured fields. When the two disagree, you have a signal for human review rather than a silent extraction error.
4. Calling Example (OpenAI-Compatible)
from openai import OpenAI
client = OpenAI(
api_key="sk-your-key",
base_url="https://ai.zhongshangqihang.com/v1",
)
resp = client.chat.completions.create(
model="gpt-5",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "Read the text in the image and output JSON"},
{"type": "image_url", "image_url": {"url": "https://example.com/a.png"}},
],
}
],
)
print(resp.choices[0].message.content)
Whether a model supports vision, and which image formats and sizes it accepts, depends on the model. Check the model pricing page and the in-site documentation before building a pipeline around a specific model name.
5. Selection Criteria
- Recognition accuracy for print, handwriting, and low-quality images.
- Layout support for tables, receipts, and multi-column pages.
- Language coverage.
- Output format: plain text, coordinates, or JSON.
- Latency and concurrency limits.
- Price, whether billed per image or per token.
- Data compliance and retention terms.
Score each candidate on your own documents rather than on a generic benchmark. A provider that leads on clean scans may fall behind on photos taken at an angle, and a cheaper per-image price may hide retries or a lower success rate.
6. How to Measure Accuracy
Prepare 50 to 100 real images that cover:
- Clear and blurry images.
- Straight and tilted photos.
- Printed and handwritten text.
- Single-column, multi-column, and table layouts.
Compare character accuracy, field accuracy, and the success rate of structured output. Do not test only with the provider's demo images; those are chosen to look good. Keep a small labeled set in your repository so you can rerun the comparison when a model or prompt changes.
7. Common Pitfalls
- Over-compressing images until the text is blurry.
- Losing the reading order of tables and multi-column pages.
- Expecting good results on handwriting and stamps.
- Treating LLM JSON output as stable without validation.
- Sending sensitive ID data without checking retention and cross-border rules.
- Comparing only the per-image price and ignoring failed retries.
FAQ
What is the difference between an OCR API and LLM vision?
OCR focuses on recognizing text. A vision-capable LLM can also understand the content, extract fields, translate it, and check consistency.
Can I use it for invoices and ID documents?
Yes, but confirm layout support, accuracy on your samples, and data compliance. For important decisions, keep a human review step.
What should I do if an image is too large?
Compress, crop, or rotate it first, or use an endpoint that accepts larger images. Confirm the size limit before uploading.
Next Steps
If you need a single entry point for several vision models, you can test a small batch of images through the ZSQH AI Gateway. Model names and prices are listed on the model pricing page.
Related reading:
