跳转到主要内容

适用场景

同步解析适合小文件、需要立即返回结果的场景。
  • 接口:POST /parse/sync
  • 返回:任务结果会在本次请求响应中直接返回

请求示例

下面示例会上传文件并返回 md + json 两种结果。
curl -X POST https://somark.tech/api/v1/parse/sync \
  -F "file=@document.pdf" \
  -F "output_formats=markdown" \
  -F "output_formats=json" \
  -F "api_key=sk-your-api-key"

响应读取示例

{
  "code": 0,
  "message": "任务成功",
  "data": {
    "task_id": "a1b2c3d4e5f6",
    "error": null,
    "metadata": {
      "page_num": 10,
      "file_type": ".pdf"
    },
    "result": {
      "file_name": "document.pdf",
      "outputs": {
        "markdown": "# 第一章 引言\n\n本文档介绍了...",
        "json": {
          "pages": [
            {
              "page_num": 0,
              "blocks": [
                {
                  "idx": 0,
                  "type": "title",
                  "bbox": [72, 50, 540, 80],
                  "content": "第一章 引言",
                  "format": "text",
                  "captions": [],
                  "img_url": "",
                  "title_level": 1
                },
                {
                  "idx": 1,
                  "type": "text",
                  "bbox": [72, 100, 540, 200],
                  "content": "本文档介绍了...",
                  "format": "text",
                  "captions": [],
                  "img_url": ""
                }
              ],
              "page_size": { "h": 1684, "w": 1190 },
              "merge_content_from_pre_page": false
            }
          ]
        }
      }
    }
  }
}
code 不为 0 时,优先检查 api_key 是否有效、output_formats 是否使用 markdown/json/zip、以及文件是否为空。

进一步阅读

查看 同步解析接口 的完整请求参数与响应字段。