API 文檔
公式識別 API
從圖像中識別數學公式,返回 LaTeX 格式的文本
概述
公式識別 API 能夠解析圖像中的數學公式,並以 LaTeX 格式返回識別結果。該 API 支持手寫和印刷體公式。 它使用統一的 JSON 請求格式,支持 URL 引用或 base64 編碼的圖像數據。
身份驗證
API 支持以下身份驗證方法:
- API 密鑰: 通過查詢參數傳遞您的 API 密鑰
?key=YOUR_API_KEY
識別公式
從圖像文件中識別數學公式,返回 LaTeX 格式的文本。
請求
POST /api/formula-recognition參數:
| 參數 | 類型 | 必需 | 描述 |
|---|---|---|---|
| document | object | 是 | 文檔對象 |
| document.type | string | 是 | 固定值 "image_url" |
| document.image_url | string | 是 | 圖片 URL 或 base64 數據 |
| filename | string | 否 | 文件名(建議在使用 base64 數據時提供) |
| key | string | 否 | API 密鑰(查詢參數,已登錄用戶可選) |
示例:
使用圖片 URL:
curl -X POST "https://llmocr.com/api/formula-recognition?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {
"type": "image_url",
"image_url": "https://llmocr.com/formula.jpg"
}
}'使用 Base64 圖片數據:
curl -X POST "https://llmocr.com/api/formula-recognition?key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"document": {
"type": "image_url",
"image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEA..."
},
"filename": "formula.jpg"
}'響應
參數:
| 參數 | 類型 | 描述 |
|---|---|---|
| id | string | 數據庫記錄 ID |
| filename | string | 文件名 |
| content | string | 識別的 LaTeX 格式公式 |
| format | string | 輸出格式,固定為 "latex" |
| timestamp | number | 處理完成時間戳 |
| payload | string | API 端點 URL |
示例:
{
"id": "12345",
"filename": "formula.jpg",
"content": "$$\\tilde { Q } ( x ) : = \\frac { 2 } { \\pi } \\Omega$$",
"format": "latex",
"timestamp": 1640995200000,
"payload": "https://llmocr.com/api/formula-recognition?key=YOUR_API_KEY"
}