接口端点
异步解析 — 提交任务
提交文件解析任务,立即返回 task_id,文档在后台处理
POST
/
parse
/
async
Python
import json
import requests
url = "https://somark.ai/api/v1/parse/async"
data = {
"output_formats": ["markdown", "json"],
"api_key": "sk-***",
"element_formats": json.dumps({
"image": "url",
"formula": "latex",
"table": "html",
"cs": "image",
}),
"feature_config": json.dumps({
"enable_text_cross_page": False,
"enable_table_cross_page": False,
"enable_title_level_recognition": False,
"enable_inline_image": False,
"enable_table_image": True,
"enable_image_understanding": True,
"keep_header_footer": False,
}),
}
files = {"file": ("example.pdf", open("example.pdf", "rb"))}
response = requests.post(url, data=data, files=files)
task_id = response.json()["data"]["task_id"]
print(f"任务已提交,task_id: {task_id}")curl -X POST https://somark.ai/api/v1/parse/async \
-F "file=@example.pdf" \
-F "output_formats=markdown" \
-F "output_formats=json" \
-F "api_key=sk-***" \
-F 'element_formats={"image":"url","formula":"latex","table":"html","cs":"image"}' \
-F 'feature_config={"enable_text_cross_page":false,"enable_table_cross_page":false,"enable_title_level_recognition":false,"enable_inline_image":false,"enable_table_image":true,"enable_image_understanding":true,"keep_header_footer":false}'const form = new FormData();
form.append('api_key', '<string>');
form.append('file', '<string>');
form.append('file_url', '<string>');
form.append('output_formats[0]', 'markdown');
form.append('output_formats[1]', 'json');
form.append('element_formats', '{
"image": "url",
"formula": "latex",
"table": "html",
"cs": "image"
}');
form.append('feature_config', '{
"enable_text_cross_page": false,
"enable_table_cross_page": false,
"enable_title_level_recognition": false,
"enable_inline_image": false,
"enable_table_image": true,
"enable_image_understanding": true,
"keep_header_footer": false
}');
const options = {method: 'POST'};
options.body = form;
fetch('https://somark.ai/api/v1/parse/async', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://somark.ai/api/v1/parse/async",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B0%5D\"\r\n\r\nmarkdown\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B1%5D\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"element_formats\"\r\n\r\n{\r\n \"image\": \"url\",\r\n \"formula\": \"latex\",\r\n \"table\": \"html\",\r\n \"cs\": \"image\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"feature_config\"\r\n\r\n{\r\n \"enable_text_cross_page\": false,\r\n \"enable_table_cross_page\": false,\r\n \"enable_title_level_recognition\": false,\r\n \"enable_inline_image\": false,\r\n \"enable_table_image\": true,\r\n \"enable_image_understanding\": true,\r\n \"keep_header_footer\": false\r\n}\r\n-----011000010111000001101001--",
CURLOPT_HTTPHEADER => [
"Content-Type: multipart/form-data; boundary=---011000010111000001101001"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://somark.ai/api/v1/parse/async"
payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B0%5D\"\r\n\r\nmarkdown\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B1%5D\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"element_formats\"\r\n\r\n{\r\n \"image\": \"url\",\r\n \"formula\": \"latex\",\r\n \"table\": \"html\",\r\n \"cs\": \"image\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"feature_config\"\r\n\r\n{\r\n \"enable_text_cross_page\": false,\r\n \"enable_table_cross_page\": false,\r\n \"enable_title_level_recognition\": false,\r\n \"enable_inline_image\": false,\r\n \"enable_table_image\": true,\r\n \"enable_image_understanding\": true,\r\n \"keep_header_footer\": false\r\n}\r\n-----011000010111000001101001--")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://somark.ai/api/v1/parse/async")
.header("Content-Type", "multipart/form-data; boundary=---011000010111000001101001")
.body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B0%5D\"\r\n\r\nmarkdown\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B1%5D\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"element_formats\"\r\n\r\n{\r\n \"image\": \"url\",\r\n \"formula\": \"latex\",\r\n \"table\": \"html\",\r\n \"cs\": \"image\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"feature_config\"\r\n\r\n{\r\n \"enable_text_cross_page\": false,\r\n \"enable_table_cross_page\": false,\r\n \"enable_title_level_recognition\": false,\r\n \"enable_inline_image\": false,\r\n \"enable_table_image\": true,\r\n \"enable_image_understanding\": true,\r\n \"keep_header_footer\": false\r\n}\r\n-----011000010111000001101001--")
.asString();require 'uri'
require 'net/http'
url = URI("https://somark.ai/api/v1/parse/async")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'multipart/form-data; boundary=---011000010111000001101001'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"api_key\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"example-file\"\r\nContent-Type: application/octet-stream\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file_url\"\r\n\r\n<string>\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B0%5D\"\r\n\r\nmarkdown\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"output_formats%5B1%5D\"\r\n\r\njson\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"element_formats\"\r\n\r\n{\r\n \"image\": \"url\",\r\n \"formula\": \"latex\",\r\n \"table\": \"html\",\r\n \"cs\": \"image\"\r\n}\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"feature_config\"\r\n\r\n{\r\n \"enable_text_cross_page\": false,\r\n \"enable_table_cross_page\": false,\r\n \"enable_title_level_recognition\": false,\r\n \"enable_inline_image\": false,\r\n \"enable_table_image\": true,\r\n \"enable_image_understanding\": true,\r\n \"keep_header_footer\": false\r\n}\r\n-----011000010111000001101001--"
response = http.request(request)
puts response.read_body{
"code": 0,
"message": "任务已提交",
"data": {
"task_id": "c5e6c983f28a4e6eb5d6c061343a8642",
"status": "queuing"
}
}路径变更:该接口路径已从
/extract/async 更改为 /parse/async。旧路径将于 2026-12-31 停用,请在此之前迁移至新路径。
参数变更:extract_config 已更名为 feature_config。请将请求中的 extract_config 字段替换为 feature_config。异步解析需要配合两个接口一起使用,单独调用提交任务接口不会直接返回解析结果。
- 调用当前接口提交任务,接口会立即返回
task_id。 - 使用这个
task_id调用结果查询接口轮询任务状态。 - 当状态变为成功后,再从结果查询接口读取解析结果。建议轮询间隔为 3~5 秒。
output_formats 、 element_formats 和 feature_config 的参数说明与同步解析相同;如果你要看鉴权、限制和模式选择,回到 API 概览。请求体
multipart/form-data
API 密钥,格式 sk-***
待解析的文档文件(与 file_url 二选一)
待解析文档的下载链接(与 file 二选一)
输出格式,可多选。不传时默认为 ["markdown", "json"]。支持 json / markdown / zip,其中 zip 将所有输出文件打包为压缩包
可用选项:
json, markdown, zip 元素格式配置,控制各类元素的输出格式
Show child attributes
Show child attributes
特色功能配置(参数已从 extract_config 更名为 feature_config)
Show child attributes
Show child attributes
⌘I

