← 返回 2026-11-12 简报

推出提取API

Introducing the Extractions API

摘要
事件:OpenRouter正式发布提取API Alpha版,支持从文本、图像及PDF中按需抽取结构化数据,初始集成Cloudflare Clairic等模型。 要点:提供九种字段类型如日期与估算分布,返回置信度及来源跨度,单次请求成本仅0.00011美元,具备自动计算缺失值能力。 影响:开发者可低成本构建高精度数据管道,降低非结构化信息处理门槛,推动文档解析向标准化、低延迟方向演进。

OpenRouter 上的提取 API(Extractions API)现已进入 Alpha 测试阶段。您可以使用它通过描述所需字段,从文本、图像和 PDF 中提取特定详细信息,例如电子邮件中的姓名或收据上的总金额。

我们首批推出了来自 Cloudflare、Inception 和 ScaleDown 的三个提取模型。您可以通过阅读文档或在 Playground 中试用来开始使用。

提取(Extraction)是指一个请求,其中指定了您希望从文档中提取的字段名称,并针对每个字段返回一个已键入的值。state 携带文本(或图像/PDF 在 assets 中的键),而 fields 将每个名称映射到一个规范:包括类型(type),以及可选地说明该字段含义的指令。

共有九种字段类型,每种都返回为一种无需解析即可存储的 JSON 类型。以下是向这张发票提出的六个问题,发票作为 state 发送;表格中的示例是 Clairic 返回的结果,高亮显示的单词是值的来源:

state · 发票,以文本形式

来自 Larkspur Studio 的发票 INV-4417,开具日期为 2026-10-14,付款条款为 net 45。账单收件人:Harbor & Pine LLC。联系人:Dana Ruiz (dana@harborpine.example)、Priya Shah。行项目:品牌审计 2,400.00;图标集 1,150.00;加急费 300.00。应付总额 $3,850.00。逾期付款每月累积 1.5% 的利息。

所请求的字段为 invoice_number: text、total: number、due_date: date、contacts: list、po_number: text 和 days_to_pay: estimate。

类型 获取的内容 示例
text 从文档中读取的字符串 "INV-4417"
number 数字,包含您选择的小数位和单位 3850
date ISO 日期,读取或计算得出 "2026-11-28"
time ISO 时间(一天中的时刻) 未向此发票请求
datetime ISO 日期和时间 未向此发票请求
list 文本、数字或日期项的数组(items 指定具体类型) ["Dana Ruiz", "Priya Shah"]
duration 您选择单位的数字,从秒到年 45,单位:"days"
estimate 文档暗示的数量分布,在您设定的最小值和最大值之间 中位数 45, p10 42, p90 47
forecast 同上,针对未来间隔步骤的预测;value、mean、median、p10 和 p90 是包含每个步骤一个条目的数组 未向此发票请求

每个答案都携带其值;其他携带的内容取决于字段类型和模型。在 Clairic 上,从文本中读取的值会附带一个跨度(span),即 [start, end),基于 Unicode 码点计算 state 中的位置,这样您就可以切片文档并显示值的来源(列表会携带多个跨度,每个项目一个)。单个值会携带 p_null,即文档中该字段为空的可能性;当 p_null 超过 0.5 时,值变为 null(可通过设置每字段的 null_threshold 来移动这条线),而 guess 则是即使在这种情况下最可能的值。它们还携带 confidence,即模型对该值的置信度,而从图像中读取的字符串会额外添加拼写置信度(spell_confidence)。估计值或预测值不携带置信度;mean、median、p10 和 p90 描述其分布,而 p10 到 p90 的宽度即为不确定性。Extract 返回每个值的置信度且不返回 p_null;在文本上它也会返回跨度,而在 PDF 上则不返回(见第 3 节)。

这些字段构成了信任模型。设置一个置信度下限,将低于该下限的内容发送给人工处理,并存储其余部分。null 是一个答案,而非低分:模型判断该字段不存在(其 p_null 超过了阈值),而 guess 表示它原本会尝试获取的值。没有置信度的值(如估计值)则通过其分布进行判断。

输入的是文档和一组命名、已键入的字段列表。输出的是每个字段一个值、从文本中读取值的跨度、单个值的置信度和 p_null,以及估计值的分布。

在 Clairic 上运行此请求的费用为 $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 读取了 1,138 个输入 token 并给出了回答(响应中除去模型行):

{
"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;po_number 返回为 null,guess 显示了如果存在时会匹配到的值;days_to_pay 是一个估计值,因此它返回的是一个分布而非单点值,其中 80% 的概率质量分布在 42 到 47 天之间。通过每个 span 切片状态以在值旁边显示证据。在 Python 中,设 r 为上述调用的 requests 响应:

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 } " )

输入的是图像,在 assets 中通过 state 中的键引用,以及相同类型的字段列表。输出是与上述相同的记录结构,其中模型标记为从图片读取的值带有 source: "image"(source 是可选的,且下方的 paid_on 没有该字段,因此不要以其作为键),并且文本带有 spell_confidence。剪辑中照片上的方框是为演示而绘制的;API 返回的是值而非图像坐标。

在 Clairic 上运行请求的费用为 $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 读取了 1,064 个图像 token,总计 2,532 个,并给出了回答(响应内容,不含模型行):

{
"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 }
}
所有非空数值和日期字段的置信度均超过 0.99,而 tip 字段明确返回为 null 而非虚构的零值,其 p_null 值为 0.9999。商户名称有误(收据上显示的是“NORTH HARBOR CAFE”),Clairic 也指出了这一点:spell_confidence 为 0.73,比响应中其他所有值低了三分之一。这就是你需要路由给人工处理的那个字段,而响应已经告诉你该选哪一个了。

PDF 也可以放入 assets 中,设置 "type": "document" 和 "format": "pdf" 。Clairic 仅读取图像,因此 PDF 会发送至 ScaleDown Extract,它每次请求读取一个 PDF 或图像,并回答文本和列表字段。代码片段中页面上的方框仅为演示目的绘制;Extract 返回的是值和置信度,而非页面坐标。

在 Extract 上运行的请求,费用为 $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", "instructions": "Order total including shipping" },
"delivery_date": { "type": "text", "instructions": "Requested delivery date" },
"items": { "type": "list", "items": "text", "instructions": "Ordered line items" },
"approver": { "type": "text", "instructions": "Who approved the order" }
}
}
EOF
Extract 从 PDF 中读取了 3,972 个输入 token,并在 2.9 秒内完成回答(响应内容,不含模型行):

{
"answers" : {
"po_number" : { "type" : "text" , "value" : "PO-20931" , "confidence" : 1 , "source" : "document" },
"vendor" : { "type" : "text" , "value" : "Meridian Office Supply" , "confidence" : 1 , "source" : "document" },
"total" : { "type" : "text" , "value" : "$4,200.00" , "confidence" : 0.814 , "source" : "document" },
"delivery_date" : { "type" : "text" , "value" : "November 18, 2026" , "confidence" : 0.979 , "source" : "document" },
"items" : { "type" : "list" , "value" : [ "Standing desk, 60 in, walnut" , "Task chair, mesh back" , "Monitor arm, dual" ], "confidences" : [ 0.994 , 0.999 , 1 ], "source" : "document" },
"approver" : { "type" : "text" , "value" : "Priya Shah" , "confidence" : 1 , "source" : "document" }
},
"truncated" : false ,
"usage" : { "input_tokens" : 3972 , "output_tokens" : 0 , "cost" : 0.00015888 },
"id" : "gen-dec-1794274074-RzjUzkyrf7WfR9LpFUTO" ,
"provider" : "ScaleDown"
}

所有数值均正确,包括表格中的三个明细项。与 Clairic 相比,有两个差异需要规划:Extract 没有数字或日期类型,因此总额和交货日期以页面上的字符串形式返回,并且它为每个值(以及列表中的每一项)报告置信度,但不提供 p_null 或 span。0.81 的总额是需要注意的字段;其余字段的置信度都在 1 或接近 1。

模型列表

发布时提供三种模型,相同的请求适用于所有这些模型,因此你可以选择最适合该任务的模型。对于图像(如收据照片)以及需要返回数字、日期或估算值的情况,请使用 Clairic。若要提取 PDF 中的文本(如合同中的各方信息),请使用 ScaleDown Extract。若要从纯文本(如电子邮件或支持工单)中提取名称或短语,请使用 Mercury Decide。

模型读取字段类型 输入价格 提供商选项

Clairic ( cloudflare/clairic ) 文本和最多 4 张 PNG 或 JPEG 图像 每种类型 $0.10/M include_quantiles , return_state_text under provider.options.cloudflare

Extract ( scaledown/extract ) 文本,或一个 PDF 或图像 文本,以及文本列表 $0.04/M threshold , top_n under provider.options.scaledown

Mercury Decide ( inception/mercury-decide ) 仅限文本 文本,以及文本列表 $0.02/M snap_to_words , threshold , group_fields under provider.options.inception

所有三种模型的输出均免费。价格为 2026 年 11 月 6 日的目录值;模型页面上有当前价格。

Cloudflare 的 Clairic

Clairic ( cloudflare/clairic ) 是 Cloudflare 在 Workers AI 上的提取模型,应作为起点使用。它每次请求可读取文本和最多四张 PNG 或 JPEG 图像,支持所有字段类型,并且是唯一返回 p_null 、spans 以及用于估算和预测的分布的发布模型。上面第 1 节和第 2 节均在其上运行。两个提供商选项扩展了响应:include_quantiles: true 为每个估算和预测返回 99 个百分位数,return_state_text: true 回显 span 偏移量索引指向的确切文本,以便你可以对其进行检查切片。

Extract ( scaledown/extract ) 读取文本,或每次请求一个 PDF 或图像,并以每个值的置信度回答文本和列表字段。它是今天处理 PDF 的模型(第 3 节)。它不报告空值概率,因此拒绝 null_threshold;threshold 和 top_n 在 provider.options.scaledown 下用于调整其选择值的方式。

Inception 的 Mercury Decide

Mercury Decide ( inception/mercury-decide ) 仅读取文本,并以三种模型中最低的输入价格回答文本和列表字段。它拒绝 reference_date;snap_to_words 、threshold 和 group_fields 在 provider.options.inception 下是其选项。

仅限文本的字段可在任何地方运行。我们将第 1 节中发票的文本和列表字段发送给 Mercury Decide 和 Extract:两者返回相同的值,且在文本方面与 Clairic 返回相同的 spans,价格分别为 $0.000015 和 $0.000014。Extract 不返回 PDF 的 spans(第 3 节)。

两种路由都使用相同的信封( model , state , assets , provider ),区别在于你交给模型的内容以及它返回的内容。

决策(Decisions):你提供选项,模型进行权衡。一个决策请求包含问题,每个问题都附带其答案空间:noul 表示一个真或假的命题;choice 列出可选项目;score 指定一个评分尺度;box 要求识别图像中的某个区域。对于 noul、choice 或 score,模型绝不会生成你未列出的值;它仅在你写下的答案之间分配概率(box 则返回你所描述区域的坐标)。这正是处理任何需要判断力事项的正确工具:这是发票吗?这五个术语中哪一个适用?严重程度如何?这张图片是否包含收据。输出是一个可设定阈值校准数值,而错误答案也是你已处理的选项之一。

提取(Extractions):你指定字段名,模型查找对应值。一个提取请求包含字段,每个字段由名称和类型组成:text(文本)、number(数字)、date(日期)、list(列表)、duration(时长)、estimate(估算值)、forecast(预测值)。答案空间是类型本身,而非你列出的选项列表,因此模型必须在文档中定位该值(或根据开票日期和条款计算到期日,或对付款天数进行估算)。由于取值范围开放,答案会附带证据:读取该值的文本跨度、p_null(表示文档中是否完全不存在相关内容)、以及置信度。当答案本身就是内容时,这是正确的工具:收据上的金额、合同中的姓名、表格上的日期。

与第 1 节相同的发票,通过 Clef Flash 的决策功能处理:

{
"questions" : {
"overdue" : { "type" : "noul" , "instruc

本条评分 9.2 score-v1
  • 来源权威 8
    注册表 priority=8(OpenRouter)
  • 时效 1.225
    发布 46.5 小时前,衰减到 1.23/3.0
  • 多源印证 0
    只有 1 家在报(无旁证)
  • 社区信号 0
    无社区数据(本管线走 RSS,HN 的 hn_fetcher 未接入)

首次收录 · 2026-11-12 · 9.22 分

原文链接:https://openrouter.ai/blog/announcements/extractions-api/
来源:OpenRouter
以上内容由 AI 自动翻译,仅供参考。
← 返回简报