公式识别 API

从图像中识别数学公式,返回 LaTeX 格式的文本

概述

公式识别 API 能够解析图像中的数学公式,并以 LaTeX 格式返回识别结果。该 API 支持手写和印刷体公式。 它使用统一的 JSON 请求格式,支持 URL 引用或 base64 编码的图像数据。

身份验证

API 支持以下身份验证方法:

  • API 密钥: 通过查询参数传递您的 API 密钥 ?key=YOUR_API_KEY

识别公式

从图像文件中识别数学公式,返回 LaTeX 格式的文本。

请求

POST /api/formula-recognition

参数:

参数类型必需描述
documentobject文档对象
document.typestring固定值 "image_url"
document.image_urlstring图片 URL 或 base64 数据
filenamestring文件名(建议在使用 base64 数据时提供)
keystringAPI 密钥(查询参数,已登录用户可选)

示例:

使用图片 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"
  }'

响应

参数:

参数类型描述
idstring数据库记录 ID
filenamestring文件名
contentstring识别的 LaTeX 格式公式
formatstring输出格式,固定为 "latex"
timestampnumber处理完成时间戳
payloadstringAPI 端点 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"
}
公式识别 API - LLMOCR Developer Guide