页面简介
The Extractions API is live: POST /api/alpha/extractions pulls typed fields out of text, images and PDFs, with spans, null probability and confidence on every answer. Three models at launch, including Cloudflare's Clairic for text and images.
正文摘录
Introducing the Extractions APIWilliam Kofski ·11/10/2026What are Extractions?What are Extractions?1: Extract from text2: Extract from images3: Extract from filesModel listDecisions vs. ExtractionsGetting startedFAQsThe Extractions API is now live on OpenRouter in alpha. Use it to pull specific details out of text, images, and PDFs by describing the fields you need, like the names in an email or the total on a receipt. We’re launching with three extraction models from Cloudflare, Inception, and ScaleDown. Get started by reading the docs or trying it out in the Playground. What are Extractions? An extraction is a request that names the fields you want out of a document and gets one typed value per field back. state carries the text (or the key of an image or PDF in assets), and fields maps each name to a spec: a type, and optionally instructions that say what the field means. There are nine field types, and each comes back as a JSON type you can store without parsing. Six of them were asked of this invoice, sent as state; the examples in the table are what Clairic returned, and the highlighted words are where the values came from: state · invoice, as text Invoice INV-4417 from Larkspur Studio, issued 2026-10-14, payment terms net 45. Bill to: Harbor & Pine LLC. Contacts: Dana Ruiz (dana@harborpine.example), Priya Shah. Line items: brand audit 2,400.00; icon set 1,150.00; rush fee 300.00. Total due $3,850.00. Late payments accrue 1.5% per month. The fields asked for were invoice_number: text, total: number, due_date: date, contacts: list, po_number: text and days_to_pay: estimate. TypeWhat you getExampletextA string read from the document"INV-4417"numberA number, with decimals and unit you choose3850dateAn ISO date, read or computed"2026-11-28"timeAn ISO time of daynot asked of this invoicedatetimeAn ISO date and timenot asked of this invoicelistAn array of text, number or date items (items picks which)["Dana Ruiz", "Priya Shah"]durationA number in the unit you choose, from seconds to years45 with unit: "days"estimateA distribution for a quantity the document implies, between a min and max you setmedian 45, p10 42, p90 47forecastThe same, for horizon steps into the future at an interval you set; value, mean, median, p10 and p90 are arrays with one entry per stepnot asked of this invoice Every answer carries its value; what else it carries depends on the field type and the model. On Clairic, a value read from the text comes with a span, [start, end) into the state counted in Unicode code points, so you can slice the document and show where it came from (a list carries spans, one per item). Single values carry p_null, the probability that the document holds nothing for the field; a value becomes null when it passes 0.5 (set null_threshold per field to move that line), and guess is the most likely value even then. They also carry confidence, the model’s confidence in the value, and a string read from an image adds spell_confidence for its spelling. An estimate or forecast carries no confidence; mean, median, p10 and p90 describe its distribution, and the width of p10 to p90 is the uncertainty. Extract returns a confidence per value and no p_null; on text it returns spans too, on a PDF none (section 3). Those fields are the trust model. Set a confidence floor, send anything under it to a person, and store the rest. A null is an answer, not a low score: the model judges the field absent (its p_null passed the threshold), and guess says what it would have reached for. A value with no confidence, such as an estimate, is judged by its distribution instead. 1: Extract from text What goes in is the document and a list of named, typed fields. What comes out is one value per field, a span where a value was read from the text, a confidence and p_null on single values, and a distribution for an estimate. The request, run on Clairic for $0.00011: curl https://openrouter.ai/api/alpha/extractions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "cloudflare/clairic", "state": "Invoice INV-4417 from Larkspur Studio, issued 2026-10-14, payment terms net 45. Bill to: Harbor & Pine LLC. Contacts: Dana Ruiz (dana@harborpine.example), Priya Shah. Line items: brand audit 2,400.00; icon set 1,150.00; rush fee 300.00. Total due $3,850.00. Late payments accrue 1.5% per month.", "fields": { "invoice_number": { "type": "text" }, "total": { "type": "number", "decimals": 2, "unit": "USD" }, "due_date": { "type": "date", "instructions": "Issue date plus the net payment days" }, "contacts": { "type": "list", "items": "text", "instructions": "People named as contacts" }, "po_number": { "type": "text", "instructions": "Purchase order number, if any" }, "days_to_pay": { "type": "estimate", "min": 0, "max": 120, "step": 1, "instructions": "How many days after issue this invoice will actually be paid" } }, "reference_date": "2026-11-06" }' Clairic read 1,138 input tokens and answered (the response, less its model line): { "answers": { "invoice_number": { "type": "text", "value": "INV-4417", "span": [8, 16], "p_null": 4.9e-6, "confidence": 0.9999 }, "total": { "type": "number", "value": 3850, "p_null": 1.6e-5, "confidence": 0.9999 }, "due_date": { "type": "date", "value": "2026-11-28", "p_null": 4.4e-5, "confidence": 0.9994 }, "contacts": { "type": "list", "value": ["Dana Ruiz", "Priya Shah"], "spans": [[118, 127], [155, 165]] }, "po_number": { "type": "text", "value": null, "guess": "INV-4417", "p_null": 0.9999 }, "days_to_pay": { "type": "estimate", "value": 45, "mean": 44.79, "median": 45, "p10": 42, "p90": 47 } }, "truncated": false, "usage": { "input_tokens": 1138, "output_tokens": 0, "cost": 0.0001138, "state_tokens": 118, "schema_tokens": 666, "passes": 4 }, "id": "gen-dec-1794000212-JVtrkaQ2JbqaR59u2bjZ", "provider": "Cloudflare" } due_date has no date in the text, so the model computed it from the issue date and the terms; po_number came back null with guess showing what it would have reached for; days_to_pay is an estimate, so it returns a distribution rather than a point, with 80% of the mass between 42 and 47 days. Slice the state with each span to show the evidence next to the value. In Python, with r the requests response to the call above: state = "Invoice INV-4417 from Larkspur Studio, issued 2026-10-14, payment terms net 45. Bill to: Harbor & Pine LLC. Contacts: Dana Ruiz (dana@harborpine.example), Priya Shah. Line items: brand audit 2,400.00; icon set 1,150.00; rush fee 300.00. Total due $3,850.00. Late payments accrue 1.5% per month." answers = r.json()["answers"] for name, answer in answers.items(): spans = answer.get("spans") or ([answer["span"]] if answer.get("span") else []) evidence = [state[start:end] for start, end in spans] print(f"{name}: {answer['value']!r} <- {evidence!r}") 2: Extract from images What goes in is the image, in assets, referenced by its key from state, plus the same kind of field list. What comes out is the same shape of record, with source: "image" on values the model marks as read off the picture (source is optional and paid_on below lacks it, so do not key on it) and a spell_confidence on text. The boxes on the photo in the clip are drawn for the demo; the API returns values, not image coordinates. The request, run on Clairic for $0.00025: import base64 import os import requests API = "https://openrouter.ai/api/alpha/extractions" HEADERS = {"Authorization": f"Bearer {os.environ['OPENROUTER_API_KEY']}"} with open("receipt.png", "rb") as f: receipt = base64.b64encode(f.read()).decode() r = requests.post( API, headers=HEADERS, json={ "model": "cloudflare/clairic", "state": "receipt", "assets": {"receipt": {"type": "image", "format": "png", "data_base64": receipt}}, "fields": { "merchant": {"type": "text"}, "total": {"type": "number", "decimals": 2}, "paid_on": {"type": "date"}, "tax": {"type": "number", "decimals": 2, "instructions": "Sales tax charged"}, "tip": {"type": "number", "decimals": 2, "instructions": "Gratuity, if any"}, }, }, ) r.raise_for_status() print(r.json()["answers"]) Clairic read 1,064 image tokens and 2,532 in total, and answered (the response, less its model line): { "merchant": { "type": "text", "value": "NORTH HAROR C", "p_null": 8.0e-5, "confidence": 0.733, "source": "image", "spell_confidence": 0.733 }, "total": { "type": "number", "value": 29.04, "p_null": 5.3e-8, "confidence": 0.9995, "source": "image" }, "paid_on": { "type": "date", "value": "2026-10-24", "p_null": 0.0061, "confidence": 0.9999 }, "tax": { "type": "number", "value": 3.79, "p_null": 2.8e-4, "confidence": 0.9982, "source": "image" }, "tip": { "type": "number", "value": null, "guess": 0, "p_null": 0.9999, "confidence": 0.8923 } } Every non-null numeric and date field came back above 0.99 confidence, and tip is an explicit null rather than a made-up zero, with p_null at 0.9999. The merchant name is wrong (the receipt says “NORTH HARBOR CAFE”), and Clairic says so: spell_confidence is 0.73, a third below everything else in the response. That is the field you route to a person, and the response told you which one. 3: Extract from files PDFs go in assets too, with "type": "document" and "format": "pdf". Clairic reads images only, so a PDF goes to ScaleDown Extract, which reads one PDF or image per request and answers text and list fields. The boxes on the page in the clip are drawn for the demo; Extract returns values and confidences, not page coordinates. The request, run on Extract for $0.00016: curl https://openrouter.ai/api/alpha/extractions \ -H "Authorization: Bearer $OPENROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d @- <<EOF { "model": "scaledown/extract", "state": "po", "assets": { "po": { "type": "document", "format": "pdf", "data_base64": "$(base64 < purchase-order.pdf | tr -d '\n')" } }, "fields": { "po_number": { "type": "text" }, "vendor": { "type": "text", "instructions": "The supplier the order is placed with" }, "total": { "type": "text