Endpoints
Async parsing — Submit Task
Submit a file parsing task and immediately receive a task_id; the document is processed in the background
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"
}
}Path change: This endpoint path has been changed from
/extract/async to /parse/async. The old path will be discontinued on December 31, 2026. Please migrate to the new path before then.
Parameter change: extract_config has been renamed to feature_config. Please replace extract_config with feature_config in your requests.Async parsing requires both endpoints. Calling the submit endpoint alone does not return the final parsing result.
- Call this endpoint to submit the task. It immediately returns a
task_id. - Use that
task_idto poll the result query endpoint. - Read the parsing result from the result query endpoint after the task status becomes successful. The recommended polling interval is 3~5 seconds.
output_formats, element_formats, and feature_config are the same as in Sync parsing; if you want the auth and limits summary, go back to the API overview.Body
multipart/form-data
API 密钥,格式 sk-***
待解析的文档文件(与 file_url 二选一)
待解析文档的下载链接(与 file 二选一)
输出格式,可多选。不传时默认为 ["markdown", "json"]。支持 json / markdown / zip,其中 zip 将所有输出文件打包为压缩包
Available options:
json, markdown, zip 元素格式配置,控制各类元素的输出格式
Show child attributes
Show child attributes
特色功能配置(参数已从 extract_config 更名为 feature_config)
Show child attributes
Show child attributes
⌘I

