加载中...
加载中...
5 分钟内开始使用 OpenOCR。
在 open-ocr.com/signup 注册一个免费账户。新账户包含起步额度。然后在你的控制台中生成一个 API 密钥。
创建账户和 API 密钥需要真人完成(CAPTCHA 验证)。AI 代理:请向你的用户索取一个 sk-ocr- 密钥。
mistral-mistral-ocr-4-1。这是我们推荐的默认引擎,原生支持多页 PDF。google-gemini-3.1-flash-lite。使用你的 API 密钥和图像 URL 向 OCR 端点发送一个 POST 请求。每个请求都需要一个 Idempotency-Key 请求头,以防止重复处理:
curl -X POST https://api.open-ocr.com/v1/ocr \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"engine": "mistral-mistral-ocr-4-1",
"input": {
"type": "url",
"url": "https://tesseract-ocr.github.io/tessdoc/images/eurotext.png"
}
}'{
"request_id": "req_abc123",
"status": "succeeded",
"engine": "mistral-mistral-ocr-4-1",
"extracted_text": "INVOICE #12345\nDate: January 15, 2024\n...",
"extracted_text_preview": "INVOICE #12345...",
"cost_debited": 0.005,
"remaining_balance": 0.995,
"provider_latency_ms": 280
}每页费用取决于你选择的引擎。当前费率请查看定价页面。remaining_balance 字段会显示你更新后的额度余额。
你也可以将图像以 base64 编码数据的形式发送——当文件位于内存中时很有用:
# Encode a local file and send it
BASE64=$(base64 -w0 receipt.png)
curl -X POST https://api.open-ocr.com/v1/ocr \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"engine": "mistral-mistral-ocr-4-1",
"input": {
"type": "base64",
"data_base64": "'$BASE64'",
"mime_type": "image/png"
}
}'OpenOCR 是一个纯粹的 REST + JSON API——无需安装任何 SDK。使用你已有的任意 HTTP 客户端即可。
import uuid
import requests
resp = requests.post(
"https://api.open-ocr.com/v1/ocr",
headers={
"Authorization": "Bearer sk-ocr-your-api-key",
"Content-Type": "application/json",
"Idempotency-Key": str(uuid.uuid4()), # new UUID per logical request
},
json={
"engine": "mistral-mistral-ocr-4-1",
"input": {"type": "url", "url": "https://example.com/receipt.png"},
},
)
resp.raise_for_status() # an error envelope has no "status" field
result = resp.json()
if result["status"] != "succeeded":
raise RuntimeError(f"OCR ended as {result['status']}: {result.get('provider_error')}")
print(result["extracted_text"])const resp = await fetch("https://api.open-ocr.com/v1/ocr", {
method: "POST",
headers: {
Authorization: "Bearer sk-ocr-your-api-key",
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(), // new UUID per logical request
},
body: JSON.stringify({
engine: "mistral-mistral-ocr-4-1",
input: { type: "url", url: "https://example.com/receipt.png" },
}),
});
const result = await resp.json();
if (result.status !== "succeeded") throw new Error("OCR ended as " + (result.status ?? result.error?.code)); // error envelopes have no status
console.log(result.extracted_text);如需获取控制台风格的使用历史(支持分页和日期筛选),请使用 GET /api/usage。请使用 Authorization 请求头进行身份验证。 将 api_key 作为查询参数传递仅作为已弃用的后备方式受支持。
# Preferred — the API key alone identifies the caller
curl "https://open-ocr.com/api/usage?page=1&per_page=50" -H "Authorization: Bearer sk-ocr-your-api-key"
# Deprecated fallback (migration only; avoid in new clients)
# curl "https://open-ocr.com/api/usage?api_key=sk-ocr-your-api-key"迁移说明:请将现有客户端从查询参数认证迁移到请求头认证,以避免 API 密钥泄露在 URL、日志、分析引荐来源和浏览器历史记录中。
OpenOCR 提供多种 OCR 引擎,每种都针对不同的使用场景进行了优化。查看我们的引擎目录,或阅读对比工具以找到最适合的引擎。
# List available engines
curl https://api.open-ocr.com/v1/engines \
-H "Authorization: Bearer YOUR_API_KEY"
# Quick guide:
# mistral-mistral-ocr-4-1 — Recommended default: general documents, scans, tables
# google-gemini-3.1-flash-lite — Cheapest acceptable quality
# local-tesseract — OpenOCR-hosted, clean printed text
# local-easyocr — OpenOCR-hosted, multi-language
# local-doctr — OpenOCR-hosted, complex layouts
# openocr-ocrmypdf — OpenOCR-hosted, scanned PDFs with auto-deskew
# openocr-rapidocr — OpenOCR-hosted, lightweightAPI 响应中包含速率限制相关的请求头:
X-RateLimit-Limit: 60 # requests per minute
X-RateLimit-Remaining: 59 # requests left in window
X-RateLimit-Reset: 60 # seconds until window resets默认限制为每个 API 密钥每分钟 60 次请求。超过限制时,你会收到 429 响应。