siliconflow_deepseekocr

DeepSeek-OCR 支持多种场景的提示词(要求固定格式)：

- 文档转Markdown："<image>\n<|grounding|>Convert the document to markdown."
- 通用OCR："<image>\n<|grounding|>OCR this image."
- 无布局提取："<image>\nFree OCR."
- 图表解析："<image>\nParse the figure."
- 图像描述："<image>\nDescribe this image in detail."
- 文本定位："<image>\nLocate <|ref|>特定文字<|/ref|> in the image."

DeepSeek-OCR 还支持 PDF URL 或 base64 编码数据。

例如

POST `https://api.siliconflow.cn/v1/chat/completions`
Authorization: `Bearer $SILICONFLOW_API_KEY`
Content-Type: `application/json`

Example request body:
{
  "model": "deepseek-ai/DeepSeek-OCR",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image_url",
          "image_url": {
            "url": "data:application/pdf;base64,..."
          }
        },
        {
          "type": "text",
          "text": "<image>\\n<|grounding|>Convert the document to markdown."
        }
      ]
    }
  ]
}

---

MinerU 轻量解析 API

    免登录，无需 Token，IP 限频防滥用。专为 OpenClaw 等 AI Agent 场景设计，仅输出 Markdown，免登录零门槛。

概述

Agent 轻量解析接口专为 OpenClaw 等 AI Agent 场景设计，提供快速、免登录的文档解析能力。

核心特性：

    无需登录：通过 IP 限频防滥用，无需申请 Token
    轻量快速：PDF、图片使用 pipeline 轻量模型，禁用表格/公式识别，追求最快解析速度; Word、PPT使用Office原生API解析
    统一输出：仅输出 Markdown 格式，返回 CDN 链接
    双模式提交：URL 解析和文件上传为独立接口，文件上传采用签名上传模式

文件限制：
限制项	限制值
文件大小上限	10 MB
文件页数上限	20 页
支持文件类型	PDF、图片（png/jpg/jpeg/jp2/webp/gif/bmp）、Docx、PPTx、Xls、Xlsx

IP 限频：

    每 IP 每分钟提交请求数有限制
    超出限制将返回 HTTP 429 状态码
import requests
import time

BASE_URL = "https://mineru.net/api/v1/agent"

def parse_by_file(file_path, language="ch", page_range=None, enable_table=True, is_ocr=False, enable_formula=True):
    """通过文件上传提交文档解析任务并等待结果。"""
    file_name = file_path.split("/")[-1].split("\\")[-1]

    # 1. 获取签名上传 URL
    data = {"file_name": file_name, "language": language, "enable_table": enable_table, "is_ocr": is_ocr, "enable_formula": enable_formula}
    if page_range:
        data["page_range"] = page_range

    resp = requests.post(f"{BASE_URL}/parse/file", json=data)
    result = resp.json()
    if result["code"] != 0:
        print(f"获取上传链接失败: {result['msg']}")
        return None

    task_id = result["data"]["task_id"]
    file_url = result["data"]["file_url"]
    print(f"任务已创建, task_id: {task_id}")

    # 2. PUT 上传文件到 OSS
    with open(file_path, "rb") as f:
        put_resp = requests.put(file_url, data=f)
        if put_resp.status_code not in (200, 201):
            print(f"文件上传失败, HTTP {put_resp.status_code}")
            return None
    print("文件上传成功，等待解析...")

    # 3. 轮询等待结果
    return poll_result(task_id)


def poll_result(task_id, timeout=300, interval=3):
    """轮询查询解析结果。"""
    state_labels = {
        "pending": "排队中",
        "running": "解析中",
        "waiting-file": "等待文件上传",
    }
    start = time.time()
    while time.time() - start < timeout:
        resp = requests.get(f"{BASE_URL}/parse/{task_id}")
        result = resp.json()
        state = result["data"]["state"]
        elapsed = int(time.time() - start)

        if state == "done":
            markdown_url = result["data"]["markdown_url"]
            print(f"[{elapsed}s] 解析完成, Markdown 下载链接: {markdown_url}")
            md_resp = requests.get(markdown_url)
            return md_resp.text

        if state == "failed":
            print(f"[{elapsed}s] 解析失败: {result['data'].get('err_msg', '未知错误')}")
            return None

        print(f"[{elapsed}s] {state_labels.get(state, state)}...")
        time.sleep(interval)

    print(f"轮询超时 ({timeout}s)，请稍后手动查询 task_id: {task_id}")
    return None


# 使用示例
content = parse_by_file("./document.pdf")

---

PaddleOCR-VL compatible HTTP API sketch

Tool name: paddleocr_vl_parse
Scope: parser
Cost: midium
Required env var: PADDLEOCR_VL_API_KEY
Required flag: --path /path/to/file.pdf

Upload local file:

POST `https://ocr-provider.example/v1/files`
Authorization: `Bearer $PADDLEOCR_VL_API_KEY`
Content-Type: `multipart/form-data`

Field:
- `file`: local PDF or image file

Parse uploaded file:

POST `https://ocr-provider.example/v1/parse`
Authorization: `Bearer $PADDLEOCR_VL_API_KEY`
Content-Type: `application/json`

Example request body:
{
  "file_id": "<uploaded-file-id>",
  "output_format": "markdown",
  "ocr": true,
  "table": true,
  "formula": true
}

Return the parsed markdown text from the provider response.
