BroadRouter
Get started

Read Arabic invoices and receipts with a vision model

Updated

Send the image as a base64 data URL in the message content to a vision model such as broadnet/qwen3.8-27b or broadnet/gemma-4-26b-a4b, and ask for the fields you need as JSON. Keep the MIME type accurate. On pay-as-you-go an image counts as input tokens; larger images use more.

Three chat models on BroadNet Inference take images: DeepSeek V4.1 Flash, Qwen3.8 27B and BroadNet Gemma 4 VL 26B. GLM 5.3 is text only. For Arabic documents, Qwen3.8 27B is the one BroadNet tested in Arabic: fluent writing, Gulf and Egyptian dialects understood, and accurate Arabic–English translation. Gemma 4 VL 26B is the cheapest of the three on BroadNet and works on the free credit.

Ask a question about one invoice

import base64, os
from openai import OpenAI

client = OpenAI(base_url="https://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"])
invoice = base64.b64encode(open("invoice.jpg", "rb").read()).decode()

response = client.chat.completions.create(
    model="broadnet/gemma-4-26b-a4b",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "ما هو المبلغ الإجمالي في هذه الفاتورة؟"},
        {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + invoice}},
    ]}],
)
print(response.choices[0].message.content)

The question asks “What is the total amount on this invoice?” in Arabic. Use image/png in the data URL for PNG files: the MIME type must match. To set it from the file name:

import mimetypes
mime = mimetypes.guess_type("invoice.png")[0]   # "image/png"
url = f"data:{mime};base64," + base64.b64encode(open("invoice.png", "rb").read()).decode()

Get structured fields back

Ask for JSON and say exactly which keys you want:

prompt = (
    "Read this invoice. Reply with JSON only, keys: vendor, date (YYYY-MM-DD), "
    "currency, total (number), vat (number or null). Keep the vendor name in Arabic if it is written in Arabic."
)
response = client.chat.completions.create(
    model="broadnet/qwen3.8-27b",
    max_tokens=2000,  # Qwen3.8 27B reasons first
    messages=[{"role": "user", "content": [
        {"type": "text", "text": prompt},
        {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + invoice}},
    ]}],
)

Qwen3.8 27B reasons before answering, so give it room. See why reasoning models return empty answers. BroadNet’s docs list structured output for Qwen3.8 27B; see structured output for how JSON schemas work in general. Parse the reply with json.loads and check the fields before you store them.

Cost

On pay-as-you-go, an image is billed as input tokens at the model’s input price, so resize very large photos first; the image token calculator shows how many tokens a given size costs. On an unlimited DeepSeek V4.1 Flash plan, images are part of the unlimited use.

Compare the vision models’ prices, or see how a vision model compares with Google, Azure, Textract and Mistral OCR in the Arabic OCR API comparison.

Troubleshooting

  • Empty answer from Qwen3.8 27B or DeepSeek V4.1 Flash. Reasoning used up max_tokens. Raise it or set reasoning_effort to low.
  • 400 or 422 on the image. Check that the data URL starts with data:image/jpeg;base64, or data:image/png;base64, and that the MIME type matches the file.
  • 403 or an error on the model. GLM 5.3 does not take images, and Qwen3.8 27B and DeepSeek V4.1 Flash need a top-up. Use BroadNet Gemma 4 VL 26B on the free credit.
  • Request too large or context errors. A big photo uses many tokens, and Gemma 4 VL 26B has the smallest context window of the three (listed in pricing.json). Resize to a sensible width or crop to the totals area.
  • Wrong totals or swapped digits. Arabic-Indic digits (٠١٢٣) and Latin digits can both appear on one receipt. Ask the model to return numbers in Latin digits, and check totals against line items in your code.
  • Invalid JSON. Ask for “JSON only”, strip any code fences before parsing, and retry once if parsing fails.
An Arabic and English invoice beside a phone showing the JSON {"total":125.00,"currency":"AED"}, with the text "From documents to structured data."
Illustrative example; the figures are not real output.

Questions

Which BroadNet models can read images?

DeepSeek V4.1 Flash, Qwen3.8 27B and BroadNet Gemma 4 VL 26B accept images through chat completions. GLM 5.3 is text only, and the transcription models take audio.

How do I send a local image file to a vision LLM API?

Read the file, base64-encode it and put it in an image_url content part as a data URL, such as data:image/jpeg;base64, followed by the encoded bytes. The MIME type in the URL must match the file.

Can I extract invoice data on the free credit?

Yes, with BroadNet Gemma 4 VL 26B, which runs on the free starting credit. Qwen3.8 27B and DeepSeek V4.1 Flash open after a top-up.

Can I send a PDF invoice?

BroadNet's docs describe images sent as data URLs, not PDF files. Render each PDF page to a JPEG or PNG first, for example with pdftoppm, and send the pages as images.

Read as MarkdownAsk ChatGPTAsk ClaudeAsk Perplexity