信息抽取 API

從票據、證件、表單等圖像中提取結構化信息,支持自定義 JSON Schema,以 JSON 格式返回提取結果

概述

信息抽取 API 可以從票據、證件、表單等圖像中提取結構化信息,支持自定義 JSON Schema 定義提取字段,以 JSON 格式返回提取結果。模型會智能識別圖像中的對應信息並填充到 Schema 中。

它使用統一的 JSON 請求格式,支持 URL 引用或 base64 編碼的圖像數據。

身份驗證

API 支持以下身份驗證方法:

  • API 密鑰: 通過查詢參數傳遞您的 API 密鑰 ?key=YOUR_API_KEY

從圖像提取結構化信息

使用智能識別技術從圖像文件中提取結構化信息,支持自定義 JSON Schema。

請求

POST /api/key-information-extraction

參數:

參數類型必需描述
documentobject文檔對象
document.typestring固定值 "image_url"
document.image_urlstring圖像 URL 或 base64 數據
result_schemaobject/stringJSON Schema,定義要提取的字段
filenamestring文件名(推薦用於 base64 數據)
keystringAPI 密鑰(查詢參數,已登錄用戶可選)

result_schema 說明:

  • 可以是 JSON 對象或 JSON 字符串
  • 最多支持 3 層嵌套
  • 只需要定義 key(字段名),value 保持為空字符串
  • 支持數組結構

示例:

使用圖像 URL:

curl -X POST "https://llmocr.com/api/key-information-extraction?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "type": "image_url",
      "image_url": "https://llmocr.com/invoice.jpg"
    },
    "result_schema": {
      "銷售方名稱": "",
      "購買方名稱": "",
      "不含稅價": "",
      "發票代碼": ""
    }
  }'

使用 Base64 圖像數據:

curl -X POST "https://llmocr.com/api/key-information-extraction?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "document": {
      "type": "image_url",
      "image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA..."
    },
    "result_schema": {
      "姓名": "",
      "身份證號": "",
      "地址": ""
    },
    "filename": "id-card.jpg"
  }'

響應

參數:

參數類型描述
idstring數據庫記錄 ID
filenamestring文件名
contentstring提取的結構化信息(JSON 字符串格式)
formatstring輸出格式,固定為 "json"
timestampnumber處理完成時間戳
payloadstringAPI 端點 URL

示例:

{
  "id": "12345",
  "filename": "invoice.jpg",
  "content": "{\"銷售方名稱\":\"湖北中基汽車銷售服務有限公司\",\"購買方名稱\":\"蔡應時\",\"不含稅價\":\"270000.00\",\"發票代碼\":\"142011726001\"}",
  "format": "json",
  "timestamp": 1640995200000,
  "payload": "https://llmocr.com/api/key-information-extraction?key=YOUR_API_KEY"
}
信息抽取 API - LLMOCR Developer Guide