Query the status and result of an async task by task_id
Python
import time import requests url = "https://somark.tech/api/v1/parse/async_check" task_id = "c5e6c983f28a4e6eb5d6c061343a8642" while True: response = requests.post(url, data={ "task_id": task_id, "api_key": "sk-***", }) result = response.json() status = result["data"]["status"] if status == "success": print(result["data"]["result"]) break elif status == "failed": print("解析失败") break time.sleep(3)
{ "code": 0, "message": "查询成功", "data": { "record_id": 12345, "task_id": "c5e6c983f28a4e6eb5d6c061343a8642", "status": "success", "file_name": "document.pdf", "metadata": { "page_num": 5, "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 } ] } } } } }
/extract/async_check
/parse/async_check
status
queuing
processing
success
result
failed
提交任务时返回的任务 ID
API 密钥,格式 sk-***
查询成功
状态码,0 为成功,非 0 见错误码
0
"查询成功"
Show child attributes