OCR (Optical Character Recognition)
Extract text from images and PDFs by sending image content to a vision-capable model through the LLMBase Inference API.
Updated
LLMBase does not have a separate OCR endpoint. Text extraction works through the standard chat completions API: send an image as part of a user message to a vision-capable model, and ask it to return the text it reads.
Try it without an account
The OCR demo lets you upload a receipt, invoice, screenshot, or PDF and see the extracted result in your browser, with no account and no API key required. It is rate-limited and intended for evaluation, not production traffic.
Extracting text via the API
Send the image as an image_url content part alongside a text instruction.
This example uses qwen/qwen3-vl-30b-a3b-instruct, the vision-capable model
used by the public OCR demo:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.llmbase.ai/v1",
apiKey: process.env.LLMBASE_API_KEY,
});
const response = await client.chat.completions.create({
model: "qwen/qwen3-vl-30b-a3b-instruct",
temperature: 0,
messages: [
{
role: "user",
content: [
{
type: "text",
text: "Extract all readable text from this image. Return only the extracted text, preserving line breaks.",
},
{
type: "image_url",
image_url: { url: "data:image/png;base64,<base64-encoded-image>" },
},
],
},
],
});
console.log(response.choices[0].message.content);
image_url.url accepts either a data URI (as above) or a publicly reachable
https:// URL. See Chat completions for
the full request and response reference.
Structured extraction
For invoices, receipts, and forms, request JSON output instead of a text blob
with response_format, and describe the fields you want in the prompt:
const response = await client.chat.completions.create({
model: "qwen/qwen3-vl-30b-a3b-instruct",
temperature: 0,
response_format: { type: "json_object" },
messages: [
{
role: "user",
content: [
{
type: "text",
text: 'Extract this invoice as JSON with keys: vendor, invoiceNumber, date, total, lineItems (array of {description, amount}). Use an empty string for missing fields. Do not invent values.',
},
{ type: "image_url", image_url: { url: "data:image/png;base64,<base64-encoded-image>" } },
],
},
],
});
See Structured outputs for JSON mode and JSON Schema details.
Choosing a vision-capable model
Not every model accepts image input. Check input_modalities and
supported_input_image_media_types before sending a request:
curl "https://api.llmbase.ai/v1/models?metadata=true" \
-H "Authorization: Bearer $LLMBASE_API_KEY"
If a model does not advertise image support, LLMBase returns a 400 error
instead of silently ignoring the image. See
Model discovery for the full metadata
reference.
Supported inputs
- Images — JPEG, PNG, and WebP are broadly supported; confirm exact
formats against the selected model’s
supported_input_image_media_types. - PDFs — the chat completions API accepts image content parts, not PDF files directly. Render each PDF page you want to process to an image first, then send it the same way as a photo or screenshot.
- Handwriting — vision models can attempt handwritten text, but accuracy is lower than for printed text. Treat handwritten results as a starting point and verify against the source.
Authentication
Use your LLMBase API key in the Authorization header, the same as any other
Inference API request:
Authorization: Bearer <LLMBASE_API_KEY>
See Authentication for how to create and manage API keys.