名称: docstrange
描述: Nanonets 提供的文档提取 API。将 PDF 和图像转换为 Markdown、JSON 或 CSV,并提供置信度评分。适用于 OCR 文档、提取发票字段、解析收据或将表格转换为结构化数据。
文档提取 API — 将 PDF、图像和文档转换为 Markdown、JSON 或 CSV,并提供逐字段的置信度评分。
获取 API 密钥: https://docstrange.nanonets.com/app
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/sync" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@document.pdf" \
-F "output_format=markdown"
响应示例:
{
"success": true,
"record_id": "550e8400-e29b-41d4-a716-446655440000",
"status": "completed",
"result": {
"markdown": {
"content": "# 发票\n\n**发票编号:** INV-2024-001..."
}
}
}
# 访问控制面板
https://docstrange.nanonets.com/app
保存您的 API 密钥:
export DOCSTRANGE_API_KEY="your_api_key_here"
推荐:使用环境变量(最安全):
{
skills: {
entries: {
"docstrange": {
enabled: true,
// API 密钥将从环境变量 DOCSTRANGE_API_KEY 加载
},
},
},
}
备选方案:存储在配置文件中(谨慎使用):
{
skills: {
entries: {
"docstrange": {
enabled: true,
env: {
DOCSTRANGE_API_KEY: "your_api_key_here",
},
},
},
},
}
安全提示: 如果将 API 密钥存储在 ~/.openclaw/openclaw.json 中:
- 设置文件权限:chmod 600 ~/.openclaw/openclaw.json
- 切勿将此文件提交到版本控制系统
- 尽可能优先使用环境变量或代理的密钥存储
- 定期轮换密钥,并在支持时限制 API 密钥权限
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/sync" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@document.pdf" \
-F "output_format=markdown"
访问内容:response["result"]["markdown"]["content"]
简单字段列表:
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/sync" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@invoice.pdf" \
-F "output_format=json" \
-F 'json_options=["invoice_number", "date", "total_amount", "vendor"]' \
-F "include_metadata=confidence_score"
使用 JSON 模式:
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/sync" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@invoice.pdf" \
-F "output_format=json" \
-F 'json_options={"type": "object", "properties": {"invoice_number": {"type": "string"}, "total_amount": {"type": "number"}}}'
带置信度评分的响应:
{
"result": {
"json": {
"content": {
"invoice_number": "INV-2024-001",
"total_amount": 500.00
},
"metadata": {
"confidence_score": {
"invoice_number": 98,
"total_amount": 99
}
}
}
}
}
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/sync" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@table.pdf" \
-F "output_format=csv" \
-F "csv_options=table"
对于超过 5 页的文档,请使用异步模式并轮询结果:
将文档加入队列:
curl -X POST "https://extraction-api.nanonets.com/api/v1/extract/async" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY" \
-F "file=@large-document.pdf" \
-F "output_format=markdown"
# 返回:{"record_id": "12345", "status": "processing"}
轮询结果:
curl -X GET "https://extraction-api.nanonets.com/api/v1/extract/results/12345" \
-H "Authorization: Bearer $DOCSTRANGE_API_KEY"
# 返回:{"status": "completed", "result": {...}}
获取元素坐标用于布局分析:
-F "include_metadata=bounding_boxes"
提取文档结构(章节、表格、键值对):
-F "json_options=hierarchy_output"
增强的表格和数字格式化:
-F "markdown_options=financial-docs"
通过提示词指导提取:
-F "custom_instructions=Focus on financial data. Ignore headers."
-F "prompt_mode=append"
在一次调用中请求多种格式:
-F "output_format=markdown,json"
| 文档大小 | 端点 | 说明 |
|---|---|---|
| ≤5 页 | /extract/sync |
即时响应 |
| >5 页 | /extract/async |
轮询结果 |
JSON 提取:
- 字段列表:["field1", "field2"] — 快速提取
- JSON 模式:{"type": "object", ...} — 严格类型、嵌套数据
置信度评分:
- 添加 include_metadata=confidence_score
- 每个字段的评分范围为 0-100
- 手动检查评分 <80 的字段
{
"type": "object",
"properties": {
"invoice_number": {"type": "string"},
"date": {"type": "string"},
"vendor": {"type": "string"},
"total": {"type": "number"},
"line_items": {
"type": "array",
"items": {
"type": "object",
"properties": {
"description": {"type": "string"},
"quantity": {"type": "number"},
"price": {"type": "number"}
}
}
}
}
}
{
"type": "object",
"properties": {
"merchant": {"type": "string"},
"date": {"type": "string"},
"total": {"type": "number"},
"items": {
"type": "array",
"items": {"type": "object", "properties": {"name": {"type": "string"}, "price": {"type": "number"}}}
}
}
}
重要提示: 上传到 DocStrange 的文档将被传输到 https://extraction-api.nanonets.com 并在外部服务器上处理。
上传敏感文档前:
- 查阅 Nanonets 的隐私政策和数据保留政策:https://docstrange.nanonets.com/docs
- 验证传输中(HTTPS)和静态数据的加密
- 确认数据删除/保留时间线
- 首先使用非敏感样本文档进行测试
最佳实践:
- 在确认服务的安全性和合规性之前,请勿上传高度敏感的个人身份信息(SSN、医疗记录、金融账户号码)
- 如果可用,请使用具有有限权限/范围的 API 密钥
- 定期轮换 API 密钥(建议每 90 天)
- 监控 API 使用日志以发现未经授权的访问
- 切勿将 API 密钥记录或提交到代码仓库或示例中
file_url 配合可公开访问的 URL,而不是直接上传大文件"your_api_key_here"400 Bad Request:
- 只提供一种输入:file、file_url 或 file_base64
- 验证 API 密钥是否有效
同步超时:
- 对于 >5 页的文档,请使用异步模式
- 轮询 /extract/results/{record_id}
缺少置信度评分:
- 需要 json_options(字段列表或模式)
- 添加 include_metadata=confidence_score
认证错误:
- 验证 DOCSTRANGE_API_KEY 环境变量是否已设置
- 检查 API 密钥是否已过期或被撤销
- 确保 API 密钥值中没有多余的空格
在发布或更新此技能前,请验证:
package.json 声明了 DOCSTRANGE_API_KEY 的 requiredEnv 和 primaryEnvpackage.json 在 endpoints 数组中列出了 API 端点"your_api_key_here"),而非真实密钥SKILL.md 或 package.json 中没有嵌入 API 密钥或机密信息