POST /api/alpha/extractions asks an extraction model for typed fields: the invoice number in a document, the total as a number, a due date, a list of names, or an estimate with its distribution. You describe each field once in a fields map and get one typed answer per field back, with the probability that the text contains nothing for it.
The route is alpha and its shape can change. It takes the Decisions envelope (model, state, assets, provider, user, session_id, trace) with a fields map in place of questions. The envelope is shared, but the specs inside it are not: a field spec is one of the types in the table below, not a Decisions question (noul, choice, score, box), so moving a request between the routes means rewriting each question as a field as well as renaming the key. A top-level questions field on this route fails with a 400 that says so.
Supported models
A request a model cannot serve (a
date field on Mercury Decide, an image on a text-only model, a fifth image on Clairic) fails with a 400 from OpenRouter before anything is sent to the provider. The response provider field names the provider that answered.
Quickstart
Request
modelis a model slug from the table above.stateis the text to read from. It may be empty only when the request carries assets.fieldsmaps each field name to a typed field spec. At least one field is required. Unknown keys at the top level or inside a field are rejected with a400, not ignored, so a provider option in the wrong place never silently does nothing.reference_date(YYYY-MM-DD) anchors dates written without a year. Models without date fields reject it.assets,provider,user,session_id, andtracework as on/api/alpha/decisions; see Assets and Provider options.
Field types
Every field takestype, an optional instructions string saying what the field should contain, and an optional null_threshold: the probability of null above which the answer’s value is null (default 0.5). The other keys depend on the type. A key marked ? is optional.
numberanddurationtakeunit,integer, anddecimals(0 to 6 decimal places kept invalue). Adurationunitisseconds,minutes,hours,days,weeks,months, oryears.listtakesitems:text,number, ordate.estimateandforecasttakeminandmax(numbers, or ISO dates for date-valued estimates), an optionalstep(a positive number, in days for date estimates, or"month"or"year"), and an optionalscaleoflinearorlog. Aforecastalso takeshorizon(1 to 64 steps) andinterval(step,minute,hour,day,week,month,quarter, oryear).
Answers
valueis the typed answer, ornullwhenp_nullcrossed the field’s threshold.guessis the most likely value even then.p_nullis the probability that the state contains nothing for the field;confidenceis the model’s confidence invalue.span(spansfor lists, one per item) is[start, end)as Unicode code point offsets into the state text, so an emoji or an accented letter counts once. Setreturn_state_texton Clairic to get the exact text the offsets index into back asstate_text.sourceisimageordocumentwhen the answer was read from an asset rather than the state text;spell_confidencethen reports how sure the model is of the spelling.estimateandforecastanswers carry the distribution:mean,median,p10,p90,p_belowandp_above(probability mass outsideminandmax),quantileswhen asked for, and per-step values understepsfor forecasts.truncatedistruewhen the provider read only a prefix of the state.usage.passescounts the upstream calls the fields needed when they did not fit in one.
Assets
Images and PDFs go in a top-levelassets map, each sent once and referenced by its key. An asset is { "type": "image" | "document", "format": "png" | "jpg" | "jpeg" | "pdf", "data_base64": "..." }; type is optional and data_base64 is the file in standard base64 with no data: prefix. Every asset must be referenced in state or a field’s instructions, or the request fails with a 400 naming the unused key.
- A
statethat is exactly the sole asset’s key carries no text of its own and is read as file-only. - Clairic reads up to 4 PNG or JPEG images, each at most 4 MiB decoded, 8 MiB decoded in total, in a request body of at most 16 MiB. It does not read PDFs.
- Clairic reads images positionally, in
assetskey order, and has no in-text reference syntax. With one image, the file-only form above works. With two or more images, a key used as the wholestateor as the wholeinstructionsof a field fails with a400(the model could not tell which image is meant), so name each image inside longer text instead; every key still has to appear somewhere, or the request fails with the unused-asset400above:
- ScaleDown Extract reads one PDF or image per request, and reads either the text or the document, not both: send the file-only form of
state. - Mercury Decide reads text only; any asset fails with a
400.
Provider options
Provider-specific knobs go underprovider.options.<provider slug>, and each model accepts only its own keys; anything else fails with a 400 naming the accepted keys.
cloudflare:include_quantilesadds 99 percentiles to estimates asquantiles;return_state_textreturns the text that spans index into asstate_text.inception:snap_to_wordsandthresholdpass through to Mercury Decide;group_fieldssends all fields in one question (up to 26 per upstream pass) instead of one question per field, which costs fewer state copies but lets a token belong to only one field.scaledown:thresholdandtop_npass through to Extract. Extract reports no null probability, sonull_thresholdon a field fails with a400.
Related
- Extractions API reference has the full request and response schema.
- Extract invoice fields with ScaleDown Extract walks through the same task on the Responses API.
- Multimodal Decisions covers the Decisions route this one shares its envelope with.