Compare

Gemini 2.5 Flash PDF extraction: the request, the price per page, and the measured fabrication rate

Gemini 2.5 Flash takes a PDF inline and returns JSON in the shape of a schema. This page has the exact request Velrim's published comparison of six extraction setups (September 2026) sent it, Google's prices and page-token rule as quoted on the day, and the model's numbers on 124 public documents: accuracy, how often it invented a value for a field the document did not contain, and the difference constrained decoding made. Velrim runs on this model and is in the same table, so the comparison is between the bare model and the pipeline around it.

The request

One generateContent call, the schema in the prompt text, the PDF as a base64 part, temperature 0 and nothing else set. This is the body Velrim's published comparison of six extraction setups (September 2026) sent for every document, with a two-field schema in place of the corpus schemas.

terminal
curl -s "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-d @request.json
request.json
{
"contents": [{
"role": "user",
"parts": [
{ "text": "Extract the following fields from the document. Return JSON matching this schema. Use null for fields not present in the document.\n\nJSON Schema:\n{\"type\":\"object\",\"properties\":{\"invoice_number\":{\"type\":\"string\"},\"total\":{\"type\":\"number\"}},\"required\":[\"invoice_number\",\"total\"]}" },
{ "inline_data": { "mime_type": "application/pdf", "data": "<base64 of the PDF>" } }
]
}],
"generationConfig": { "temperature": 0 }
}

The prompt text is the sentence "Extract the following fields from the document. Return JSON matching this schema. Use null for fields not present in the document." followed by the JSON Schema. Every model in the comparison got these bytes. The same body runs on the Vertex AI endpoint for the same model pin, https://aiplatform.googleapis.com/v1/projects/<project>/locations/global/publishers/google/models/gemini-2.5-flash:generateContent, which is the route the comparison used.

Constrained decoding: two more fields

The constrained variant sends the identical prompt and adds a MIME type and the schema to the generation config. The model then cannot emit a token that breaks the schema.

request.json, generationConfig
"generationConfig": {
"temperature": 0,
"responseMimeType": "application/json",
"responseJsonSchema": {"type":"object","properties":{"invoice_number":{"type":"string"},"total":{"type":"number"}},"required":["invoice_number","total"]}
}
This is an alternative to responseSchema that accepts JSON Schema. If set, responseSchema must be omitted, but responseMimeType is required. While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported: $id $defs $ref $anchor type format title description enum (for strings and numbers) items prefixItems minItems maxItems minimum maximum anyOf oneOf (interpreted the same as anyOf) properties additionalProperties required.
Gemini API reference, GenerationConfig, read
responseSchema (deprecated) object (Schema). This item is deprecated! Optional. Output schema of the generated candidate text. Schemas must be a subset of the OpenAPI schema and can be objects, primitives or arrays. If set, a compatible responseMimeType must also be set.
Gemini API reference, GenerationConfig, read

As of 2026-09-03 the reference marks responseSchema deprecated and keeps responseJsonSchema with the list of supported keywords above. Google's structured outputs guide now documents the Interactions API on Gemini 3 models and does not mention gemini-2.5-flash or generateContent.

While generateContent remains fully supported, we recommend the Interactions API for all new development.
Gemini API docs, Migrate to the Interactions API, read
In the Interactions API, output format controls move to a top-level response_format array.
Gemini API docs, Migrate to the Interactions API, read

What Google says about pages, tokens and prices

Each document page is equivalent to 258 tokens.
Gemini API docs, Document understanding, read
Larger pages are scaled down to a maximum resolution of 3072 x 3072 while preserving their original aspect ratio, while smaller pages are scaled up to 768 x 768 pixels.
Gemini API docs, Document understanding, read
Gemini 2.5 Flash, Standard, Paid Tier, per 1M tokens in USD. Input price: $0.30 (text / image / video), $1.00 (audio). Output price: $2.50. Context caching price: $0.03 (text / image / video), $0.1 (audio), $1.00 / 1,000,000 tokens per hour. Last updated 2026-09-02 UTC.
Gemini API pricing, read
Gemini 2.5 Flash, Free Tier. Input price: Free of charge. Output price: Free of charge. Context caching price: Not available. Used to improve our products: Yes.
Gemini API pricing, read
gemini-2.5-flash. Release date: June 17, 2025. Shutdown date: No shutdown date announced.
Gemini API deprecations, read

The model card lists text, images, video and audio as inputs, a 1,048,576-token input limit, a 65,536-token output limit and a January 2025 knowledge cutoff (Gemini 2.5 Flash model card, read 2026-09-03).

Cost per 1,000 pages

Gemini 2.5 Flash at list price and as measured, beside Velrim, per 1,000 pages
Per 1,000 pagesGemini 2.5 Flash directVelrim
Page tokens at list price, 258 tokens a page at $0.30 per 1M$0.08
Measured in the comparison, prompt, schema, page and answer tokens~$2.2 (measured, token-priced)
List price, grounding and confidence included$20

At 258 tokens a page and $0.30 per million input tokens, the pages themselves cost $0.08 per 1,000. The measured figure in Velrim's published comparison of six extraction setups (September 2026) came to ~$2.2 (measured, token-priced) over 319 pages at the paid tier. The gap is prompt and schema tokens on the input side and answer tokens at $2.50 per million on the output side. The free tier is priced at zero and, per the pricing page, the inputs are used to improve Google's products.

What the comparison measured

Headline table from Velrim's September 2026 comparison: accuracy, fabrication on absent fields, error among the top 90% by confidence, and price per thousand pages, six setups
Armmacro-F1 (norm)fabrication (absent fields)wrong among the top 90% by confidence$/1k pages
Velrim0.69111.5% [6.1, 19.8]36.1% [29.9, 44.1]$20 (list; measured matches)
Gemini free-decode0.70917.0% [10.1, 26.7]not requested~$2.2 (measured, token-priced)
Gemini constrained0.69712.8% [7.6, 20.5]not requested~$2.2 (measured, token-priced)
gpt-5.4-mini free0.73510.8% [5.7, 18.4]none surfaced~$1.0 (measured, prompt-cached)
gpt-5.4-mini structured0.71810.4% [5.3, 17.6]none surfaced~$1.0 (measured, prompt-cached)
Mistral OCR 40.71240.3% [31.0, 52.5]none surfaced$5 (list; measured $5.3)

124 public documents, 2102 fields, 96 of them absent by the audited answer key. Free-decode Gemini invented a value for 17.0% of the absent fields, interval [10.1, 26.7]. With constrained decoding, 12.8%, interval [7.6, 20.5]. Accuracy moved from 0.710 to 0.697 macro-F1. Pooled across all six setups the rate is 17%. Velrim, on the same model: 11.5%.

Fabrication table from Velrim's September 2026 comparison: pooled rate, the all-attempted rule, the answer rate when the field is present, and completed attempts, six setups
Armfabrication (pooled, n=96)all-attempted ruleanswered when field presentcompleted/attempted
Velrim11.5% [6.1, 19.8]11.5% [6.1, 19.8]88.0% [84.0, 91.2]372/372
Gemini free-decode17.0% [10.1, 26.7]15.6% [9.3, 24.4]96.5% [95.0, 97.7]328/372
Gemini constrained12.8% [7.6, 20.5]11.1% [6.6, 18.1]96.7% [95.4, 97.9]315/372
gpt-5.4-mini free10.8% [5.7, 18.4]10.8%96.1% [94.6, 97.3]372/372
gpt-5.4-mini structured10.4% [5.3, 17.6]10.4%95.6% [93.0, 96.9]372/372
Mistral OCR 440.3% [31.0, 52.5]40.3%96.6% [95.2, 97.9]372/372

The two Gemini rows completed 328/372 and 315/372 attempts. The shortfall was rate limiting on a new Google Cloud project at its default quota, plus one document that twice came back without usable JSON. Google's status page was clean for the window. On the other side of the fabrication column, Gemini answered 96.5% [95.0, 97.7] of the fields that were in the document and Velrim 88.0% [84.0, 91.2], so the lower invention rate is paid for in blanks.

The same call through Velrim

extract.ts
import { z } from "zod";
import { VelrimClient } from "@velrim/sdk";
const Invoice = z.object({ invoice_number: z.string(), total: z.number() });
const velrim = new VelrimClient({ apiKey: process.env.VELRIM_API_KEY! });
const result = await velrim.extract(Invoice, { bytes: pdfBytes });
result.data.total; // number, parsed with the schema
result.field("/total")?.state; // "present" | "null" | "missing"
result.field("/total")?.confidence; // 0 to 1
result.field("/total")?.anchor; // { page, bbox, snippet, page_dims }
one field of the response
"/total": {
"state": "present",
"value": 4210.55,
"confidence": 0.89,
"anchor": {
"page": 2,
"bbox": [451.0, 700.2, 512.4, 714.0],
"snippet": "Total due $4,210.55",
"page_dims": { "width": 612, "height": 792 }
}
}
Gemini 2.5 Flash called directly and Velrim, on what comes back and on the comparison's numbers
Gemini 2.5 Flash directVelrim
What comes backJSON in the shape of the schema. With responseJsonSchema, the shape is enforced as the model writes.The same JSON, plus a state, a 0 to 1 score and a page location for every field.
Fabrication on absent fieldsGemini 2.5 Flash free-decode: 17.0%. Gemini 2.5 Flash constrained: 12.8%.11.5%
Accuracy, macro-F10.710 and 0.6970.691
Answered when the field is present96.5% [95.0, 97.7]88.0% [84.0, 91.2]
Same document, three runs, answers differ12% and 23% of repeats36% of repeats, nearly all on nested line-item tables
Price per 1,000 pages~$2.2 (measured, token-priced)$20

The score is one number per field, 0 to 1, with its error curve on the error curves page and the definition of the fabrication measure on the metric page. Grounding is a page number, a box and the matched text from the PDF's own word map, no second model call. Price is $0.02 per extracted page, prepaid from $5, about 500 pages free with no card.

Which to pick

Gemini direct, when the schema is small, every field is always on the page and a wrong value costs little, at a tenth of the price. Velrim, when a value needs a number to sort on and a place on the page to check it, and a blank is cheaper than an invention.