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