API 文檔
信息抽取 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參數:
| 參數 | 類型 | 必需 | 描述 |
|---|---|---|---|
| document | object | 是 | 文檔對象 |
| document.type | string | 是 | 固定值 "image_url" |
| document.image_url | string | 是 | 圖像 URL 或 base64 數據 |
| result_schema | object/string | 是 | JSON Schema,定義要提取的字段 |
| filename | string | 否 | 文件名(推薦用於 base64 數據) |
| key | string | 否 | API 密鑰(查詢參數,已登錄用戶可選) |
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"
}'響應
參數:
| 參數 | 類型 | 描述 |
|---|---|---|
| id | string | 數據庫記錄 ID |
| filename | string | 文件名 |
| content | string | 提取的結構化信息(JSON 字符串格式) |
| format | string | 輸出格式,固定為 "json" |
| timestamp | number | 處理完成時間戳 |
| payload | string | API 端點 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"
}