Document parsing (large model)
The Document Analysis (Large Model Edition) API provides general-purpose document extraction and understanding. It supports various common document formats, extracts rich layout information, and outputs content in Markdown format. This document explains how to call the API. Before you start, please read the API user guide.
Invocation
The Document Parser (Large Model Version) is an asynchronous interface. To use this service, submit an asynchronous task by calling SubmitDocParserJobAdvance or SubmitDocParserJob. Then, query the processing status by calling QueryDocParserStatus. Finally, call GetDocParserResult to retrieve the result. The following workflow diagram illustrates the process:
-
Document Parsing (Large Model Edition) includes a free monthly quota of 3,000 pages. If your free quota or resource package is exhausted, the service defaults to Pay-As-You-Go. Once an asynchronous task completes, you can query its results for up to 24 hours. After this period, the results are no longer available.
-
Supported formats include documents (PDF, Word, PPT, PPTX, XLS, XLSX, and XLSM), images (JPG, JPEG, PNG, BMP, and GIF), and other file types (Markdown, HTML, EPUB, MOBI, RTF, and TXT).
-
Supported audio and video formats include MP4, MKV, AVI, MOV, WMV, MP3, WAV, and AAC.
-
Document Parsing (Large Model Edition) can parse images and tables in documents. The
chart2tablecomponent processes images containing charts, converting the chart data into a table. -
For table parsing, Document Parsing (Large Model Edition) is the most accurate, followed by Intelligent Document Parsing and Electronic Document Parsing. Therefore, we recommend Document Parsing (Large Model Edition) for document analysis. In terms of overall processing speed, Electronic Document Parsing is the fastest, followed by Document Parsing (Large Model Edition) and Intelligent Document Parsing.
Step 1: Submit an asynchronous parsing job
The asynchronous submission service supports two submission methods: by local file or by file URL.
-
To submit a local file, call the
SubmitDocParserJobAdvanceAPI. -
To submit a file by URL, call the
SubmitDocParserJobAPI.
-
Asynchronous processing times can vary. After activating the Electronic Document Parsing service, you will receive a free quota for testing.
-
The service selects a parser based on the file extension in
FileNameorFileNameExtension. If you are unsure of the document type, you can omit the extension, and the service will route the file to a default parser to prevent unexpected results.
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
FileUrl |
string |
No |
The URL of the document to submit. Supports single documents, such as PDF and Word, up to 15,000 pages and 150 MB, or single images up to 20 MB. |
https://example.com/example.pdf |
|
FileUrlObject |
stream |
No |
The stream of the local file to submit. Supports single documents, such as PDF and Word, up to 15,000 pages and 150 MB, or single images up to 20 MB. |
A |
|
FileName |
string |
No |
The filename, which must include the file extension. You must specify either |
example.pdf |
|
FileNameExtension |
string |
No |
The file extension. You must specify either |
|
|
FormulaEnhancement |
bool |
No |
Specifies whether to enable enhanced formula recognition. The default value is |
True |
|
LlmEnhancement |
bool |
No |
Specifies whether to enable enhancement with a large language model. The default value is
|
False |
|
EnhancementMode |
string |
No |
The large model enhancement mode is empty (disabled) by default. This parameter takes effect only when The following option is supported:
Important: Enabling this option may significantly increase the API response time and will incur additional charges per page. Use it only when necessary. |
VLM |
|
Option |
string |
No |
Specifies the processing option for audio and video files. The default value is
|
Base |
|
OssBucket |
string |
No |
The name of your Object Storage Service (OSS) bucket. For more information, see OSS hosting support. |
docmind-trust |
|
OssEndpoint |
string |
No |
The endpoint of your OSS bucket. For more information, see OSS hosting support. |
oss-cn-hangzhou.aliyuncs.com |
|
PageIndex |
string |
No |
The page range to parse. Note: The format must be |
1-5 |
|
OutputHtmlTable |
bool |
No |
Specifies whether to return table content in HTML format. The default value is False. If this option is enabled, for a layout block of the table type, the parsed HTML content of the table is returned and stored in the ⚠️ Important: If you enable this parameter, you must also set the |
false |
|
EnableEventCallback |
bool |
No |
Specifies whether to enable event callbacks. The default value is false. For more information, see EventBridge support. |
false |
|
OutputFormat |
List<String> |
No |
The output format for the parsing results. |
markdown |
|
MultimediaParameters |
object |
No |
For audio or video files, use this field to configure optional features. If set, this parameter overrides the |
|
|
string |
No |
The prompt for frame parsing. (Supported since July 25). |
##Constraints:- Do not output long sentences. Adhere to the original image and capture only key information. |
-
The
PageIndexparameter is supported only for PDF, Word, and PPT files. -
The
OutputFormatparameter supports the following values:-
markdown: The response from the status query service includes the document content in Markdown format. -
visualLayoutInfo: TheQueryDocParserStatusresponse includes page image information, and theGetDocParserResultresponse includes layout coordinate information.
-
-
When VLM enhancement is enabled, 33 languages are supported:
-
Chinese, Japanese, Korean, Indonesian, Vietnamese, Thai, English, French, German, Russian, Portuguese, Spanish, Italian, Swedish, Danish, Czech, Norwegian, Dutch, Finnish, Turkish, Polish, Swahili, Romanian, Serbian, Greek, Kazakh, Uzbek, Cebuano, Arabic, Urdu, Persian, Hindi/Devanagari, and Hebrew.
-
Response parameters
|
Parameter |
Type |
Description |
Example |
|
RequestId |
string |
The unique ID for the request. |
43A29C77-405E-4DC0-BC55-EE694AD0**** |
|
Data |
object |
The returned data. |
{"Id": "docmind-20240712-b15f****"} |
|
Id |
string |
The job ID. Use this ID to query the job status. |
doc-mind-20220712-b15f**** |
|
Code |
string |
The status code. |
200 |
|
Message |
string |
Detailed status information. |
Message |
Examples
You can call this API in two ways: by uploading a local file or by providing a file URL.
-
Upload a local file: The following Java SDK example shows how to upload a local file by calling the
SubmitDocParserJobAdvanceAPI with thefileUrlObjectparameter.NoteFor information about how to obtain and use an AccessKey, see the SDK guide for your preferred language in SDK Overview.
import com.aliyun.docmind_api20220711.models.*; import com.aliyun.teaopenapi.models.Config; import com.aliyun.docmind_api20220711.Client; import com.aliyun.teautil.models.RuntimeOptions; import java.io.File; import java.io.FileInputStream; public static void main(String[] args) throws Exception { submit(); } public static void submit() throws Exception { // Initialize the Credentials client by using the default credential provider. com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client(); Config config = new Config() // Obtain the AccessKey ID from the credentials. .setAccessKeyId(credentialClient.getAccessKeyId()) // Obtain the AccessKey secret from the credentials. .setAccessKeySecret(credentialClient.getAccessKeySecret()); // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; Client client = new Client(config); // Create a RuntimeOptions instance and configure runtime parameters. RuntimeOptions runtime = new RuntimeOptions(); SubmitDocParserJobAdvanceRequest advanceRequest = new SubmitDocParserJobAdvanceRequest(); File file = new File("D:\\example.pdf"); advanceRequest.fileUrlObject = new FileInputStream(file); advanceRequest.fileName = "example.pdf"; // Send the request and handle the response or exceptions. SubmitDocParserJobResponse response = client.submitDocParserJobAdvance(advanceRequest, runtime); System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody())); }const Client = require('@alicloud/docmind-api20220711'); const Credential = require('@alicloud/credentials'); const Util = require('@alicloud/tea-util'); const fs = require('fs'); const getResult = async () => { // Initialize the Credentials client by using the default credential provider. const cred = new Credential.default(); const client = new Client.default({ // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com', // Obtain the AccessKey ID from the credentials. accessKeyId: cred.credential.accessKeyId, // Obtain the AccessKey secret from the credentials. accessKeySecret: cred.credential.accessKeySecret, type: 'access_key', regionId: 'cn-hangzhou' }); const advanceRequest = new Client.SubmitDocParserJobAdvanceRequest(); const file = fs.createReadStream('./example.pdf'); advanceRequest.fileUrlObject = file; advanceRequest.fileName = 'example.pdf'; const runtimeObject = new Util.RuntimeOptions({}); const response = await client.submitDocParserJobAdvance(advanceRequest, runtimeObject); return response.body; };from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models from alibabacloud_tea_util.client import Client as UtilClient from alibabacloud_credentials.client import Client as CredClient if __name__ == '__main__': # Initialize the Credentials client by using the default credential provider. cred=CredClient() config = open_api_models.Config( # Obtain the AccessKey ID from the credentials. access_key_id=cred.get_credential().get_access_key_id(), # Obtain the AccessKey secret from the credentials. access_key_secret=cred.get_credential().get_access_key_secret() ) # The endpoint of the service. config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com' client = docmind_api20220711Client(config) request = docmind_api20220711_models.SubmitDocParserJobAdvanceRequest( # file_url_object: The local file stream. file_url_object=open("./example.pdf", "rb"), # file_name: The name of the file. The name must include the file extension. file_name='123.pdf', # file_name_extension: The file extension. Specify either FileName or FileNameExtension. file_name_extension='pdf' ) runtime = util_models.RuntimeOptions() try: # Process the API response as needed. response = client.submit_doc_parser_job_advance(request, runtime) # The API response is structured as body -> data -> specific properties. You can print the results as needed. The following example shows how to print the returned job ID. # Property names of the returned values start with a lowercase letter. print(response.body) except Exception as error: # Print the error message if needed. UtilClient.assert_as_string(error.message)import ( "fmt" "os" openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client" "github.com/alibabacloud-go/docmind-api-20220711/client" "github.com/alibabacloud-go/tea-utils/v2/service" "github.com/aliyun/credentials-go/credentials" ) func submit(){ // Initialize the Credentials client by using the default credential provider. credential, err := credentials.NewCredential(nil) // Obtain the AccessKey ID from the credentials. accessKeyId, err := credential.GetAccessKeyId() // Obtain the AccessKey secret from the credentials. accessKeySecret, err := credential.GetAccessKeySecret() // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com" config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint} // Initialize the client. cli, err := client.NewClient(&config) if err != nil { panic(err) } // Call the API to upload a local document. filename := "D:\\example.pdf" f, err := os.Open(filename) if err != nil { panic(err) } // Initialize the API request. request := client.SubmitDocParserJobAdvanceRequest{ FileName: &filename, FileUrlObject: f, } // Create a RuntimeOptions instance and configure runtime parameters. options := service.RuntimeOptions{} response, err := cli.SubmitDocParserJobAdvance(&request, &options) if err != nil { panic(err) } // Print the result. fmt.Println(response.Body.String()) } -
Upload a file by URL: The following code provides an example of how to submit a file by URL by using the Java SDK. Call the
SubmitDocParserJobAPI and provide the document URL in thefileUrlparameter. The URL must be publicly accessible, free of cross-origin restrictions, and not contain any special escaped characters.NoteFor information about how to obtain and use an AccessKey, see the SDK guide for your preferred language in SDK Overview.
import com.aliyun.docmind_api20220711.models.*; import com.aliyun.teaopenapi.models.Config; import com.aliyun.docmind_api20220711.Client; public static void main(String[] args) throws Exception { submit(); } public static void submit() throws Exception { // Initialize the Credentials client by using the default credential provider. com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client(); Config config = new Config() // Obtain the AccessKey ID from the credentials. .setAccessKeyId(credentialClient.getAccessKeyId()) // Obtain the AccessKey secret from the credentials. .setAccessKeySecret(credentialClient.getAccessKeySecret()); // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; Client client = new Client(config); SubmitDocParserJobRequest request = new SubmitDocParserJobRequest(); request.fileName = "example.pdf"; request.fileUrl = "https://example.com/example.pdf"; SubmitDocParserJobResponse response = client.submitDocParserJob(request); System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody())); }const Client = require('@alicloud/docmind-api20220711'); const Credential = require('@alicloud/credentials'); const getResult = async () => { // Initialize the Credentials client by using the default credential provider. const cred = new Credential.default(); const client = new Client.default({ // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com', // Obtain the AccessKey ID from the credentials. accessKeyId: cred.credential.accessKeyId, // Obtain the AccessKey secret from the credentials. accessKeySecret: cred.credential.accessKeySecret, type: 'access_key', regionId: 'cn-hangzhou' }); const request = new Client.SubmitDocParserJobRequest(); request.fileName = 'example.pdf'; request.fileUrl = 'https://example.com/example.pdf'; const response = await client.submitDocParserJob(request); return response.body; }from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client from alibabacloud_tea_openapi import models as open_api_models from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models from alibabacloud_tea_util.client import Client as UtilClient from alibabacloud_credentials.client import Client as CredClient if __name__ == '__main__': # Initialize the Credentials client by using the default credential provider. cred=CredClient() config = open_api_models.Config( # Obtain the AccessKey ID from the credentials. access_key_id=cred.get_credential().get_access_key_id(), # Obtain the AccessKey secret from the credentials. access_key_secret=cred.get_credential().get_access_key_secret() ) # The endpoint of the service. config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com' client = docmind_api20220711Client(config) request = docmind_api20220711_models.SubmitDocParserJobRequest( # file_url: The URL of the file. file_url='https://example.com/example.pdf', # file_name: The name of the file. The name must include the file extension. file_name='123.pdf', # file_name_extension: The file extension. Specify either FileName or FileNameExtension. file_name_extension='pdf' ) try: # Process the API response as needed. response = client.submit_doc_parser_job(request) # The API response is structured as body -> data -> specific properties. You can print the results as needed. The following example shows how to print the returned job ID. # Property names of the returned values start with a lowercase letter. print(response.body) except Exception as error: # Print the error message if needed. UtilClient.assert_as_string(error.message)import ( "fmt" openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client" "github.com/alibabacloud-go/docmind-api-20220711/client" "github.com/aliyun/credentials-go/credentials" ) func submit(){ // Initialize the Credentials client by using the default credential provider. credential, err := credentials.NewCredential(nil) // Obtain the AccessKey ID from the credentials. accessKeyId, err := credential.GetAccessKeyId() // Obtain the AccessKey secret from the credentials. accessKeySecret, err := credential.GetAccessKeySecret() // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com" config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint} // Initialize the client. cli, err := client.NewClient(&config) if err != nil { panic(err) } // The file URL. fileURL := "https://example.com/example.pdf" // The filename. fileName := "example.pdf" // Initialize the API request. request := client.SubmitDocParserJobRequest{ FileUrl: &fileURL, FileName: &fileName, } response, err := cli.SubmitDocParserJob(&request) if err != nil { panic(err) } // Print the result. fmt.Println(response.Body.String()) }using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; using Tea; using Tea.Utils; public static void SubmitUrl() { // Initialize the Credentials client by using the default credential provider. var akCredential = new Aliyun.Credentials.Client(null); AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config { // Obtain the AccessKey ID from the credentials. AccessKeyId = akCredential.GetAccessKeyId(), // Obtain the AccessKey secret from the credentials. AccessKeySecret = akCredential.GetAccessKeySecret(), }; // The endpoint of the service. config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config); AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitDocParserJobRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.SubmitDocParserJobRequest { FileUrl = "https://example.pdf", FileNameExtension = "pdf" }; try { // Process the API response as needed. client.SubmitDocParserJob(request); } catch (TeaException error) { // Print the error message if needed. AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message); } catch (Exception _error) { TeaException error = new TeaException(new Dictionary<string, object> { { "message", _error.Message } }); // Print the error message if needed. AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message); } }use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi; use AlibabaCloud\SDK\Docmindapi\V20220711\Models\SubmitDocStructureJobRequest; use Darabonba\OpenApi\Models\Config; use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions; use AlibabaCloud\Tea\Exception\TeaUnableRetryError; use AlibabaCloud\Credentials\Credential; // Initialize the Credentials client by using the default credential provider. $bearerToken = new Credential(); $config = new Config(); // The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for IPv6. $config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com"; // Obtain the AccessKey ID from the credentials. $config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId(); // Obtain the AccessKey secret from the credentials. $config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret(); $config->type = "access_key"; $config->regionId = "cn-hangzhou"; $client = new Docmindapi($config); $request = new SubmitDocParserJobRequest(); $runtime = new RuntimeOptions(); $runtime->maxIdleConns = 3; $runtime->connectTimeout = 10000; $runtime->readTimeout = 10000; $request->fileName = "example.pdf"; $request->fileUrl = "https://example.com/example.pdf"; try { $response = $client->submitDocParserJob($request, $runtime); var_dump($response->toMap()); } catch (TeaUnableRetryError $e) { var_dump($e->getMessage()); var_dump($e->getErrorInfo()); var_dump($e->getLastException()); var_dump($e->getLastRequest()); }
Example response
{
"RequestId": "43A29C77-405E-4DC0-BC55-EE694AD0****",
"Data": {
"Id": "docmind-20240712-b15f****"
}
}
Step 2: Call the QueryDocParserStatus API
To call the query API, use the Id returned by the asynchronous task submission API. The query result includes the Status of the job and NumberOfSuccessfulParsing, which is the number of successfully parsed modules. The Status can be Processing, success, or Fail.
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
Id |
string |
Yes |
The ID of the job to query. This ID is returned in the response of the asynchronous task submission API. |
docmind-20220712-b15f**** |
Response parameters
|
Parameter |
Type |
Description |
Example |
|
RequestId |
string |
The unique identifier for the request. |
43A29C77-405E-4CC0-BC55-EE694AD0**** |
|
Data |
string |
The object that contains the detailed response data. |
- |
|
Status |
string |
The processing status of the job. For a list of possible values, see the note below. |
success |
|
NumberOfSuccessfulParsing |
integer |
The number of successfully parsed modules. |
166 |
|
Tokens |
long |
The total number of tokens. A token is equivalent to one English word or one Chinese character. |
4429 |
|
ParagraphCount |
integer |
The number of paragraphs. |
91 |
|
TableCount |
integer |
The number of tables. This parameter is returned only if the uploaded document contains tables. |
2 |
|
ImageCount |
integer |
The number of images. This parameter is returned only if the uploaded document contains images. |
0 |
|
PageCountEstimate |
integer |
The estimated page count. |
3 |
|
Processing |
float |
The processing progress of the file as a percentage. |
100.0 |
|
OutputFormatResult |
array |
The parsing results in the specified format. This parameter is returned only if the |
|
|
Code |
string |
The status code. |
200 |
|
Message |
string |
A detailed message about the response. |
Message |
The Status parameter can have the following values:
-
Init: The job is queued for processing. -
Processing: The job is being parsed. -
success: The job completed successfully. The value ofNumberOfSuccessfulParsingis now final. -
Fail: The job failed to process.
Examples
The following examples show how to query a document parsing result by using various SDKs. In each example, the job ID is passed to the Id parameter.
To learn how to obtain and use an AccessKey, see the SDK overview.
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void main(String[] args) throws Exception {
submit();
}
public static void submit() throws Exception {
// Initialize the Credentials client with default credentials.
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// Obtain the AccessKey ID from the credentials.
.setAccessKeyId(credentialClient.getAccessKeyId())
// Obtain the AccessKey secret from the credentials.
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for both IPv4 and IPv6.
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
QueryDocParserStatusRequest resultRequest = new QueryDocParserStatusRequest();
resultRequest.id = "docmind-20220902-824b****";
QueryDocParserStatusResponse response = client.queryDocParserStatus(resultRequest);
System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody()));
}const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// Initialize the Credentials client with default credentials.
const cred = new Credential.default();
const client = new Client.default({
// The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for both IPv4 and IPv6.
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// Obtain the AccessKey ID from the credentials.
accessKeyId: cred.credential.accessKeyId,
// Obtain the AccessKey secret from the credentials.
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const resultRequest = new Client.QueryDocParserStatusRequest();
resultRequest.id = "docmind-20220902-824b****";
const response = await client.queryDocParserStatus(resultRequest);
return response.body;
}from typing import List
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
if __name__ == '__main__':
# Initialize the Credentials client with default credentials.
cred=CredClient()
config = open_api_models.Config(
# Obtain the AccessKey ID from the credentials.
access_key_id=cred.get_credential().get_access_key_id(),
# Obtain the AccessKey secret from the credentials.
access_key_secret=cred.get_credential().get_access_key_secret()
)
# The endpoint of the service.
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.QueryDocParserStatusRequest(
# id: The job ID, which is returned by the asynchronous task submission API.
id='docmind-20220902-824b****'
)
try:
# If you copy this code, print the API response.
response = client.query_doc_parser_status(request)
# The API response is structured as body -> data -> specific properties. Property names start with a lowercase letter. You can print the results as needed.
# We recommend that you convert response.body.data to JSON and then retrieve the required values.
print(response.body)
except Exception as error:
# If needed, print the error.
UtilClient.assert_as_string(error.message) import (
"fmt"
openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/docmind-api-20220711/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit(){
// Initialize the Credentials client with default credentials.
credential, err := credentials.NewCredential(nil)
// Obtain the AccessKey ID from the credentials.
accessKeyId, err := credential.GetAccessKeyId()
// Obtain the AccessKey secret from the credentials.
accessKeySecret, err := credential.GetAccessKeySecret()
// The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for both IPv4 and IPv6.
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// Initialize the client.
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
id := "docmind-20220925-76b1****"
// Call the query API.
request := client.QueryDocParserStatusRequest{Id: &id}
response, err := cli.QueryDocParserStatus(&request)
if err != nil {
panic(err)
}
// Print the query result.
fmt.Println(response.Body.String())
}using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void GetResult()
{
// Initialize the Credentials client with default credentials.
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// Obtain the AccessKey ID from the credentials.
AccessKeyId = akCredential.GetAccessKeyId(),
// Obtain the AccessKey secret from the credentials.
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// The endpoint of the service.
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
AlibabaCloud.SDK.Docmind_api20220711.Models.QueryDocParserStatusRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.QueryDocParserStatusRequest
{
Id = "docmind-20240902-824b****"
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
// If you copy this code, print the API response.
client.QueryDocParserStatus(request);
}
catch (TeaException error)
{
// If needed, print the error.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// If needed, print the error.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\GetDocStructureResultRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// Initialize the Credentials client with default credentials.
$bearerToken = new Credential();
$config = new Config();
// The endpoint of the service. You can use docmind-api-dualstack.cn-hangzhou.aliyuncs.com for both IPv4 and IPv6.
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// Obtain the AccessKey ID from the credentials.
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// Obtain the AccessKey secret from the credentials.
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new QueryDocParserStatusRequest();
$request->id = "docmind-20220902-824b****";
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
try {
$response = $client->queryDocParserStatus($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}Sample success response:
{
"RequestId": "43A29C77-405E-4DC0-BC55-EE694AD0****",
"Data": {
"Status": "success",
"NumberOfSuccessfulParsing": 93,
"ImageCount": 0,
"PageCountEstimate": 8,
"ParagraphCount": 91,
"TableCount": 2,
"Tokens": 4429
}
}
Sample failure response:
{
"code": "FileUrlLegal",
"message": "File url is not legal.",
"RequestId": "E26AC4F5-F633-5468-8F6F-708D2B3FXXXX"
}
Step 3: Call the GetDocParserResult API
Request parameters
|
Parameter |
Type |
Required |
Description |
Example |
|
Id |
string |
Yes |
The business order ID to query. You can get this ID from the response of the submission API. |
docmind-20220712-b15f**** |
|
LayoutStepSize |
integer |
Yes |
|
100 |
|
LayoutNum |
integer |
Yes |
|
0 |
|
ExcludeFields |
List<String> |
No |
Fields to exclude from the response. Currently, only top-level fields can be filtered. For a list of excludable fields, refer to the top-level fields of the |
|
-
You can page through results from the
GetDocParserResultAPI by making multiple calls. For example, use a range like[LayoutNum, LayoutNum + LayoutStepSize]to fetch blocks in batches. This method lets you retrieve parsed content even while a long document parsing job is still running. -
If the value of
LayoutStepSizeis too large, an error may occur. Reduce the value if necessary.

Response parameters
|
Parameter |
Type |
Description |
Example |
|
RequestId |
string |
The unique request ID. |
43A29C77-405E-4CC0-BC55-EE694AD0**** |
|
Data |
string |
The parsing result from Document Parsing (Large Model Edition). |
- |
|
Code |
string |
The status code. |
200 |
|
Message |
string |
The response message. |
Message |
Examples
The following examples show how to use various SDKs to query the result of a document parsing job.
import com.aliyun.docmind_api20220711.models.*;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.docmind_api20220711.Client;
public static void main(String[] args) throws Exception {
submit();
}
public static void submit() throws Exception {
// Initialize the credential client by using the default credential provider.
com.aliyun.credentials.Client credentialClient = new com.aliyun.credentials.Client();
Config config = new Config()
// Obtain the AccessKey ID from the credential.
.setAccessKeyId(credentialClient.getAccessKeyId())
// Obtain the AccessKey Secret from the credential.
.setAccessKeySecret(credentialClient.getAccessKeySecret());
// The service endpoint. IPv4 and IPv6 are supported. For IPv6, use docmind-api-dualstack.cn-hangzhou.aliyuncs.com.
config.endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
Client client = new Client(config);
GetDocParserResultRequest resultRequest = new GetDocParserResultRequest();
// The job ID. This is the ID returned by the asynchronous SubmitDocParserJob API.
resultRequest.id = "docmind-20220902-824b****";
/**
* When you use the GetDocParserResult operation, you may need to make multiple queries.
* For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
* This allows you to retrieve the parsed content of a long document in advance.
*/
// The step size for querying layout blocks. Valid values: 1 to 3000.
resultRequest.layoutStepSize = 10;
// The starting position of the query. Minimum: 0.
resultRequest.layoutNum = 0;
GetDocParserResultResponse response = client.getDocParserResult(resultRequest);
System.out.println(com.alibaba.fastjson.JSON.toJSON(response.getBody()));
}const Client = require('@alicloud/docmind-api20220711');
const Credential = require('@alicloud/credentials');
const getResult = async () => {
// Initialize the credential client by using the default credential provider.
const cred = new Credential.default();
const client = new Client.default({
// The service endpoint. IPv4 and IPv6 are supported. For IPv6, use docmind-api-dualstack.cn-hangzhou.aliyuncs.com.
endpoint: 'docmind-api.cn-hangzhou.aliyuncs.com',
// Obtain the AccessKey ID from the credential.
accessKeyId: cred.credential.accessKeyId,
// Obtain the AccessKey Secret from the credential.
accessKeySecret: cred.credential.accessKeySecret,
type: 'access_key',
regionId: 'cn-hangzhou'
});
const resultRequest = new Client.GetDocParserResultRequest();
resultRequest.id = "docmind-20220902-824b****";
/**
* When you use the GetDocParserResult operation, you may need to make multiple queries.
* For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
* This allows you to retrieve the parsed content of a long document in advance.
*/
// The step size for querying layout blocks. Valid values: 1 to 3000.
resultRequest.layoutStepSize = 10;
// The starting position of the query. Minimum: 0.
resultRequest.layoutNum = 0;
const response = await client.getDocParserResult(resultRequest);
return response.body;
}from typing import List
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_credentials.client import Client as CredClient
if __name__ == '__main__':
# Initialize the credential client by using the default credential provider.
cred = CredClient()
config = open_api_models.Config(
# Obtain the AccessKey ID from the credential.
access_key_id=cred.get_credential().get_access_key_id(),
# Obtain the AccessKey Secret from the credential.
access_key_secret=cred.get_credential().get_access_key_secret()
)
# The service endpoint.
config.endpoint = f'docmind-api.cn-hangzhou.aliyuncs.com'
client = docmind_api20220711Client(config)
request = docmind_api20220711_models.GetDocParserResultRequest(
# The job ID, returned by the SubmitDocParserJob operation.
id='docmind-20220902-824b****',
'''
When you use the GetDocParserResult operation, you may need to make multiple queries.
For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
This allows you to retrieve the parsed content of a long document in advance.
'''
# LayoutStepSize: The number of layout blocks to query. This is the step size. Minimum value: 1. Maximum value: 3000.
layout_step_size=10,
# LayoutNum: The starting position of the query. Minimum value: 0.
layout_num=0
)
try:
# Make sure to print the API response to see the output.
response = client.get_doc_parser_result(request)
# The API response is structured as body -> data -> specific properties. You can print the results as needed. The property values start with a lowercase letter.
# To retrieve specific values, convert response.body.data to JSON.
print(response.body)
except Exception as error:
# Print the error if necessary.
UtilClient.assert_as_string(error.message)
import (
"fmt"
openClient "github.com/alibabacloud-go/darabonba-openapi/v2/client"
"github.com/alibabacloud-go/docmind-api-20220711/client"
"github.com/aliyun/credentials-go/credentials"
)
func submit(){
// Initialize the credential client by using the default credential provider.
credential, err := credentials.NewCredential(nil)
// Obtain the AccessKey ID from the credential.
accessKeyId, err := credential.GetAccessKeyId()
// Obtain the AccessKey Secret from the credential.
accessKeySecret, err := credential.GetAccessKeySecret()
// The service endpoint. IPv4 and IPv6 are supported. For IPv6, use docmind-api-dualstack.cn-hangzhou.aliyuncs.com.
var endpoint string = "docmind-api.cn-hangzhou.aliyuncs.com"
config := openClient.Config{AccessKeyId: accessKeyId, AccessKeySecret: accessKeySecret, Endpoint: &endpoint}
// Initialize the client.
cli, err := client.NewClient(&config)
if err != nil {
panic(err)
}
id := "docmind-20220925-76b1****"
/**
* When you use the GetDocParserResult operation, you may need to make multiple queries.
* For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
* This allows you to retrieve the parsed content of a long document in advance.
*/
// LayoutStepSize: The number of layout blocks to query. This is the step size. Minimum value: 1. Maximum value: 3000.
layoutStepSize := 10
// LayoutNum: The starting position of the query. Minimum value: 0.
layoutNum := 0
// Call the operation.
request := client.GetDocParserResultRequest{Id: &id}
response, err := cli.GetDocParserResult(&request)
if err != nil {
panic(err)
}
// Print the result.
fmt.Println(response.Body.String())
}using Newtonsoft.Json;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Tea;
using Tea.Utils;
public static void GetResult()
{
// Initialize the credential client by using the default credential provider.
var akCredential = new Aliyun.Credentials.Client(null);
AlibabaCloud.OpenApiClient.Models.Config config = new AlibabaCloud.OpenApiClient.Models.Config
{
// Obtain the AccessKey ID from the credential.
AccessKeyId = akCredential.GetAccessKeyId(),
// Obtain the AccessKey Secret from the credential.
AccessKeySecret = akCredential.GetAccessKeySecret(),
};
// The service endpoint.
config.Endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
AlibabaCloud.SDK.Docmind_api20220711.Client client = new AlibabaCloud.SDK.Docmind_api20220711.Client(config);
AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocParserResultRequest request = new AlibabaCloud.SDK.Docmind_api20220711.Models.GetDocParserResultRequest
{
/**
* When you use the GetDocParserResult operation, you may need to make multiple queries.
* For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
* This allows you to retrieve the parsed content of a long document in advance.
*/
// The job ID. This is the ID returned by the asynchronous SubmitDocParserJob API.
Id = "docmind-20240902-824b****",
// The step size for querying layout blocks. Valid values: 1 to 3000.
LayoutStepSize = 10,
// The starting position of the query. Minimum: 0.
LayoutNum = 0
};
AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
try
{
// Make sure to print the API response to see the output.
client.GetDocParserResult(request);
}
catch (TeaException error)
{
// Print the error if necessary.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
// Print the error if necessary.
AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
}
}use AlibabaCloud\SDK\Docmindapi\V20220711\Docmindapi;
use AlibabaCloud\SDK\Docmindapi\V20220711\Models\GetDocStructureResultRequest;
use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use AlibabaCloud\Tea\Exception\TeaUnableRetryError;
use AlibabaCloud\Credentials\Credential;
// Initialize the credential client by using the default credential provider.
$bearerToken = new Credential();
$config = new Config();
// The service endpoint. IPv4 and IPv6 are supported. For IPv6, use docmind-api-dualstack.cn-hangzhou.aliyuncs.com.
$config->endpoint = "docmind-api.cn-hangzhou.aliyuncs.com";
// Obtain the AccessKey ID from the credential.
$config->accessKeyId = $bearerToken->getCredential()->getAccessKeyId();
// Obtain the AccessKey Secret from the credential.
$config->accessKeySecret = $bearerToken->getCredential()->getAccessKeySecret();
$config->type = "access_key";
$config->regionId = "cn-hangzhou";
$client = new Docmindapi($config);
$request = new GetDocParserResultRequest();
$request->id = "docmind-20220902-824b****";
/**
* When you use the GetDocParserResult operation, you may need to make multiple queries.
* For example, use [LayoutNum, LayoutNum + LayoutStepSize] to retrieve content blocks 0-100, 100-200, and so on.
* This allows you to retrieve the parsed content of a long document in advance.
*/
// The step size for querying layout blocks. Valid values: 1 to 3000.
$request->layoutStepSize = 10;
// The starting position of the query. Minimum: 0.
$request->layoutNum = 0;
$runtime = new RuntimeOptions();
$runtime->maxIdleConns = 3;
$runtime->connectTimeout = 10000;
$runtime->readTimeout = 10000;
try {
$response = $client->getDocParserResult($request, $runtime);
var_dump($response->toMap());
} catch (TeaUnableRetryError $e) {
var_dump($e->getMessage());
var_dump($e->getErrorInfo());
var_dump($e->getLastException());
var_dump($e->getLastRequest());
}For information about how to obtain and use an AccessKey, see the guides for different programming languages in SDK Overview.
Sample response
Failed response
{
"RequestId": "A8EF3A36-1380-1116-A39E-B377BE27****",
"Code": "UrlNotLegal",
"Message": "Failed to process the document. The document url you provided is not legal.",
"HostId": "docmind-api.cn-hangzhou.aliyuncs.com",
"Recommend": "https://next.api.aliyun.com/troubleshoot?q=IDP.UrlNotLegal&product=docmind-api"
}
If the request fails, the response includes an error code and a detailed message. For more information, see Error codes.
Successful response (file)
{
"Data": {
"layouts": [
{
"firstLinesChars": 0,
"level": 0,
"blocks": [
{
"text": "PRACTITIONERS’ SECTION"
}
],
"markdownContent": "# PRACTITIONERS’ SECTION \n\n",
"index": 2,
"subType": "doc_title",
"lineHeight": 0,
"text": "PRACTITIONERS’ SECTION",
"alignment": "center",
"type": "title",
"pageNum": 0,
"uniqueId": "3d8ded229371f879eac478dee2574a82"
},
{
"firstLinesChars": 0,
"level": 0,
"blocks": [
{
"text": "RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA"
}
],
"markdownContent": "# RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA \n\n",
"index": 3,
"subType": "doc_subtitle",
"lineHeight": 0,
"text": "RAGGING: A PUBLIC HEALTH PROBLEM IN INDIA",
"alignment": "center",
"type": "title",
"pageNum": 0,
"uniqueId": "44256f2d41419956ff30c6590683217b"
},
{
"firstLinesChars": 0,
"level": 1,
"blocks": [
{
"text": "RAJESH GARG"
}
],
"markdownContent": "RAJESH GARG \n\n",
"index": 4,
"subType": "para",
"lineHeight": 0,
"text": "RAJESH GARG",
"alignment": "center",
"type": "text",
"pageNum": 0,
"uniqueId": "d0d64505df8cb4d73f80e0f63007bf60"
}
]
},
"RequestId": "7B8CC68D-D498-5EDA-8352-FAF41591D97A"
}
Parameters
|
Parameter |
Type |
Description |
|
layouts |
array |
A list of layout blocks. |
|
text |
string |
The text content. |
|
markdownContent |
string |
The content in Markdown format. |
|
index |
int |
The reading order of the layout block. |
|
uniqueId |
string |
The unique ID of the layout block. |
|
alignment |
string |
The alignment of the content. |
|
pageNum |
int |
The page number of the layout block. |
|
level |
int |
The level of the layout block. A value of 0 indicates the root node. |
|
type |
string |
The type of the layout block. For more information, see the notes on layout types. |
|
subType |
string |
The subtype of the layout block. For more information, see the notes on layout types. |
|
llmResult |
string |
The result from the large language model. For details, see the
|
|
layoutConf |
float |
The confidence of the parsing result, ranging from 0 to 1. |
|
pos |
array |
The coordinates. |
|
x |
int |
The x-coordinate of the vertex. |
|
y |
int |
The y-coordinate of the vertex. |
Successful response (audio and video)
{
"Data": {
"segments": [
{
"audio_frames": [
{
"ASR_info": "Ne Zha is just a self-indulgent hype for Chinese netizens. It only has box office success in China; no one watches it anywhere else.",
"end_time": 5019.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/audio/request_1111_1.mp3?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645100&Signature=ioyj0ogA2pXSod1gPlM4KMCXLr4%3D",
"start_time": 0.0
}
],
"end_time": 5019.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/video/request_1111_0.mp4?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645176&Signature=RoMsrYsA%2B4jkuJTQA6Pjpv2knBY%3D",
"index": 0,
"start_time": 0.0,
"video_frames": [
{
"end_time": 4960.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/frame/request_1111-Scene-001-01.jpg?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645151&Signature=E8IsZesWrW%2B3i8VLs7ZXLqMFZYg%3D",
"start_time": 0.0,
"text_info": "A man wearing glasses holds a mobile phone in a circular frame. A bookshelf is in the background. A comment is displayed on the right: 'Ne Zha is just a self-indulgent hype for Chinese netizens. It only has box office success in China; no one watches it anywhere else.' Below are icons for like, dislike, share, and comment. The subtitle at the bottom reads: 'Only has box office success in China.'"
},
{
"end_time": 10600.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/frame/request_1111-Scene-002-01.jpg?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645151&Signature=ZDOgHjs0iKmYCPcmsxTPk6fhg64%3D",
"start_time": 4960.0,
"text_info": "A man wearing glasses stands in front of a bookshelf that holds books and two Minion figurines. He is wearing a brown shirt and speaking. The subtitle at the bottom reads: 'So why would anyone say that?'"
}
]
},
{
"audio_frames": [
{
"ASR_info": "Because this statement hides a very deep chain of discrimination. Let's consider a few questions. First, is Ne Zha's low foreign box office because foreign audiences don't like it or because they can't see it?",
"end_time": 19900.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/audio/request_1111_3.mp3?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645101&Signature=7QwfDASrWywOA%2FmlZ64r%2FMcu0b4%3D",
"start_time": 10577.0
}
],
"end_time": 19900.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/video/request_1111_2.mp4?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645181&Signature=m03c5oHyqY88mmtPLdSgMpi8Ul4%3D",
"index": 2,
"start_time": 10577.0,
"video_frames": [
{
"end_time": 14080.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/frame/request_1111-Scene-003-01.jpg?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645151&Signature=NCAM%2Bt1KLTNDt4jIFXOH%2B0m13Vs%3D",
"start_time": 10600.0,
"text_info": "A man wearing glasses stands in front of a bookshelf that holds books and two Minion figurines. He is wearing a brown shirt and has a serious expression. The subtitle at the bottom reads: 'hides a very deep chain of discrimination.'"
},
{
"end_time": 15600.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/frame/request_1111-Scene-004-01.jpg?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645151&Signature=%2FhmtuSNvtjwHI2Ho88tIv9keM3k%3D",
"start_time": 14080.0,
"text_info": "A man wearing glasses stands in front of a bookshelf that holds books and two Minion figurines. He is wearing a dark shirt and speaking. The text at the bottom of the screen reads: 'Let's consider a few questions.'"
},
{
"end_time": 52920.0,
"file_url": "http://doc-mind-video.oss-cn-hangzhou.aliyuncs.com/multimodal_data/20251125/frame/request_1111-Scene-005-01.jpg?OSSAccessKeyId=LTAI5tPtEwpyT4JR9XXXXX&Expires=1764645151&Signature=vfYhFendANuuzihVIlQAmq0YAuQ%3D",
"start_time": 15600.0,
"text_info": "A black background with a white box in the center containing the number '3'. Below it, white text reads: 'Is Captain America 4 'self-indulgent hype'?' The subtitle at the bottom reads: 'But it has such a high number of screenings in the US.'"
}
]
}
],
"synopsis_result": "### 0s - 5s\n**Frame parsing result**: A man wearing glasses stands in front of a bookshelf that holds books and two Minion figurines. He is wearing a brown shirt and speaking. The subtitle at the bottom reads: 'So why would anyone say that?'"
},
"RequestId": "7B8CC68D-D498-5EDA-8352-FAF41591D97A"
}
Parameters
|
Parameter |
Type |
Description |
|
segments |
array |
An array of parsed segments. |
|
start_time |
float |
The start time of the segment, in milliseconds (ms). |
|
end_time |
float |
The end time of the segment, in milliseconds (ms). |
|
index |
int |
The index of the segment, from 0 to n-1. |
|
file_url |
string |
The file URL of the segment. |
|
audio_frames |
array |
The parsing information for the audio frames in the segment. |
|
video_frames |
array |
The parsing information for the video frames in the segment. |
|
synopsis_result |
string |
The plot summary. This field is returned only when |
In responses from Document Parsing (LLM Edition), the audio_frames object contains the following fields:
|
Parameter |
Description |
Type |
|
start_time |
The start time of the audio, in milliseconds (ms). |
float |
|
end_time |
The end time of the audio, in milliseconds (ms). |
float |
|
file_url |
The URL of the audio file. |
string |
|
ASR_info |
The Automatic Speech Recognition (ASR) result. |
string |
In responses from Document Parsing (LLM Edition), the video_frames object contains the following fields:
|
Parameter |
Description |
Type |
|
start_time |
The start time of the video, in milliseconds (ms). |
float |
|
end_time |
The end time of the video, in milliseconds (ms). |
float |
|
file_url |
The URL of the video file. |
string |
|
text_info |
The parsing result for the video frame from the large language model. |
string |
The following examples show the llmResult field in the response from Document Parsing (LLM Edition).
-
For a PPT document:
{
"llmResult": "```markdown\n# Welcome to Capital Markets Day London 2015\n\n## HEXAGON\n### Shaping Smart Change\n```",
"layoutConf": 0.6
}
-
For a chart in a document:
{
"llmResult": "<|Category|>\nValuation chart\n<|Value|>\n| Protocol Followed | Time Required (Minutes) |\n|-------------------|-------------------------|\n| Standard | 80 |\n| Halifax | 80 |\n| Halifaster | 40 |",
"layoutConf": 0.4
}
Layout type
The following tables list the layout types (type) and subtypes (subType) returned by the document analysis large model.
|
Type |
Description |
Subtype |
Description |
|
title |
Title |
doc_name |
Document name |
|
doc_title |
Document title |
||
|
doc_subtitle |
Document subtitle |
||
|
para_title |
Paragraph title |
||
|
contents_title |
Table of contents title |
cate_title |
Table of contents title |
|
contents |
Table of contents |
cate |
Table of contents |
|
text |
Plain text |
para |
Paragraph |
|
figure |
Figure |
picture |
Picture |
|
logo |
Logo |
||
|
figure_name |
Figure title |
pic_title |
Picture title |
|
figure_note |
Figure caption |
pic_caption |
Picture caption |
|
foot |
Page footer |
page_footer |
Page footer |
|
head |
Page header |
page_header |
Page header |
|
head_pagenum |
Header page number |
page |
Page number |
|
foot_pagenum |
Footer page number |
page |
Page number |
|
corner_note |
Footnote |
footer_note |
Footnote |
|
end_note |
Endnote |
endnode |
Endnote |
|
side |
Sidebar |
sidebar |
Sidebar |
The table below lists additional layout types.
|
Type |
Description |
|
table_name |
Table title |
|
table_note |
Table note |
|
formula |
Formula |
The following types do not have a subtype:
|
Type |
Description |
|
multicolumn |
Multi-column text |
|
table |
Table |
|
foot_image |
Footer image |
|
head_image |
Header image |
The following table describes the properties of outputFormatResult.
|
Parameter |
Description |
|
outputType |
The output format of the result. |
|
outputFileUrl |
The URL of the output file. |
|
pages |
Contains details about the images on each page. |
The following table describes the values for outputType.
|
Value |
Description |
|
markdown |
Markdown format. |
|
pageImage |
Page image format. |
The following table describes the properties of pages.
|
Parameter |
Description |
|
imageUrl |
The URL of the image. |
|
imageWidth |
The width of the image. |
|
imageHeight |
The height of the image. |
|
pageIdCurDoc |
The current page number within the document. |
Reference example (Python)
Parsing to markdown (local file upload)
To disable VLM enhancement, set llm_enhancement=False.
Usage:
python3 docmind_example_parser.py input_file output_file.md
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
import json
from alibabacloud_docmind_api20220711.client import Client as docmind_api20220711Client
from alibabacloud_tea_openapi import models as open_api_models
from alibabacloud_docmind_api20220711 import models as docmind_api20220711_models
from alibabacloud_tea_util.client import Client as UtilClient
from alibabacloud_tea_util import models as util_models
from alibabacloud_credentials.client import Client as CredClient
class DocParser:
def __init__(self, endpoint="docmind-api.cn-hangzhou.aliyuncs.com"):
"""
Initializes the document parser.
Args:
endpoint (str): The API endpoint.
"""
self.endpoint = endpoint
self.client = self._init_client()
def _init_client(self):
"""
Initializes the API client.
Returns:
docmind_api20220711Client: The API client instance.
"""
# Initialize the `CredClient` with the default credential.
cred = CredClient()
config = open_api_models.Config(
# Get the AccessKey ID.
access_key_id=cred.get_credential().get_access_key_id(),
# Get the AccessKey Secret.
access_key_secret=cred.get_credential().get_access_key_secret()
)
# Set the endpoint.
config.endpoint = self.endpoint
return docmind_api20220711Client(config)
def submit_job(self, file_path, file_name=None):
"""
Submits a document parsing task.
Args:
file_path (str): The path to the local file.
file_name (str, optional): The name of the file.
Returns:
str: The task ID, or None if the submission fails.
"""
try:
# Extract the filename from the path if not provided.
if not file_name:
file_name = file_path.split('/')[-1]
# Build the request object.
# To disable VLM enhancement, set llm_enhancement=False.
request = docmind_api20220711_models.SubmitDocParserJobAdvanceRequest(
file_url_object=open(file_path, "rb"),
file_name=file_name,
file_name_extension=file_name.split('.')[-1] if '.' in file_name else None,
llm_enhancement=True,
enhancement_mode="VLM",
)
runtime = util_models.RuntimeOptions()
# Submit the task.
response = self.client.submit_doc_parser_job_advance(request, runtime)
task_id = response.body.data.id
print(f"Task submitted. Task ID: {task_id}")
return task_id
except Exception as error:
print(f"Error submitting the task: {error}")
return None
def query_status(self, task_id):
"""
Queries the task status.
Args:
task_id (str): The task ID.
Returns:
dict: The task status, or None if the query fails.
"""
try:
request = docmind_api20220711_models.QueryDocParserStatusRequest(id=task_id)
response = self.client.query_doc_parser_status(request)
return response.body.data.to_map() if response.body.data else None
except Exception as error:
print(f"Error querying task status: {error}")
return None
def get_result(self, task_id, layout_num=0, layout_step_size=10):
"""
Fetches the document parsing result. Supports incremental fetch.
Args:
task_id (str): The task ID.
layout_num (int): The starting layout number.
layout_step_size (int): The step size.
Returns:
dict: The parsing result, or None if the retrieval fails.
"""
try:
request = docmind_api20220711_models.GetDocParserResultRequest(
id=task_id,
layout_step_size=layout_step_size,
layout_num=layout_num
)
response = self.client.get_doc_parser_result(request)
return response.body.data if response.body.data else None
except Exception as error:
print(f"Error fetching the parsing result: {error}")
return None
def wait_for_completion(self, task_id, poll_interval=5):
"""
Waits for the task to complete by polling its status.
Args:
task_id (str): The task ID.
poll_interval (int): The polling interval in seconds.
Returns:
bool: True if the task completes successfully, False otherwise.
"""
print("Waiting for task completion...")
while True:
status_data = self.query_status(task_id)
if not status_data:
return False
print(status_data)
status = status_data.get('Status', '').lower()
# Check for task completion.
if status == 'success':
print("Task completed successfully.")
return True
elif status == 'failed':
print("Task failed.")
return False
else:
# The task is still processing.
print(".")
time.sleep(poll_interval)
def collect_results_incrementally(self, task_id, layout_step_size=10):
"""
Fetches parsing results incrementally.
Args:
task_id (str): The task ID.
layout_step_size (int): The step size.
Yields:
list: A list of layout blocks from each fetch.
"""
layout_num = 0
while True:
result_data = self.get_result(task_id, layout_num, layout_step_size)
if not result_data:
break
layouts = result_data.get('layouts', [])
if not layouts:
break
yield layouts
# Update the starting position for the next fetch.
layout_num += len(layouts)
# If the number of returned layouts is less than the step size, fetching is complete.
if len(layouts) < layout_step_size:
break
def table_to_html(self, table_layout):
"""
Converts a table layout to an HTML string.
Args:
table_layout (dict): The table layout data.
Returns:
str: The table in HTML format.
"""
cells = table_layout.get('cells', [])
if not cells:
return ""
# Create the HTML table.
html_parts = ['<table border="1" cellspacing="0" cellpadding="2">']
# Track processed cells to handle row and column spans.
processed_cells = set()
# Group cells by row.
rows = {}
for cell in cells:
row_start = cell.get('ysc', 0)
if row_start not in rows:
rows[row_start] = []
rows[row_start].append(cell)
# Process rows in order.
for row_idx in sorted(rows.keys()):
html_parts.append('<tr>')
# Sort cells in the row by column order.
row_cells = sorted(rows[row_idx], key=lambda x: x.get('xsc', 0))
for cell in row_cells:
cell_key = (cell.get('ysc', 0), cell.get('xsc', 0))
if cell_key in processed_cells:
continue
# Calculate row and column spans.
rowspan = cell.get('yec', 0) - cell.get('ysc', 0) + 1
colspan = cell.get('xec', 0) - cell.get('xsc', 0) + 1
# Mark cells as processed.
for i in range(rowspan):
for j in range(colspan):
processed_cells.add((cell.get('ysc', 0) + i, cell.get('xsc', 0) + j))
# Get the cell text.
cell_text = ""
cell_layouts = cell.get('layouts', [])
for layout in cell_layouts:
if 'text' in layout:
cell_text += layout['text']
# Clean up the text.
cell_text = cell_text.strip().replace('\n', '<br>')
# Add the cell HTML.
cell_attrs = []
if rowspan > 1:
cell_attrs.append(f'rowspan="{rowspan}"')
if colspan > 1:
cell_attrs.append(f'colspan="{colspan}"')
html_parts.append(f'<td {" ".join(cell_attrs)}>{cell_text}</td>')
html_parts.append('</tr>')
html_parts.append('</table>')
return ''.join(html_parts)
def generate_markdown(self, layouts):
"""
Converts layout blocks to Markdown content.
Args:
layouts (list): A list of layout blocks.
Returns:
str: The content in Markdown format.
"""
markdown_content = ""
for layout in layouts:
# Directly use the `markdownContent` field from the response.
if layout.get('type')=="table":
# For table types, convert to HTML format.
table_html = self.table_to_html(layout)
markdown_content += table_html + "\n\n"
else:
markdown_content += layout.get('markdownContent', '') + "\n"
return markdown_content
def process_document(self, file_path, output_path, layout_step_size=10, poll_interval=5):
"""
Processes a document by submitting a task, polling for completion,
fetching results incrementally, and generating a Markdown file.
Args:
file_path (str): The path to the local file.
output_path (str): The path for the output Markdown file.
layout_step_size (int): The step size for incremental fetch.
poll_interval (int): The polling interval in seconds.
Returns:
bool: True on success, False otherwise.
"""
# 1. Submit the task.
print("Submitting the document parsing task...")
task_id = self.submit_job(file_path)
if not task_id:
print("Failed to submit the task.")
return False
# 2. Wait for the task to complete.
if not self.wait_for_completion(task_id, poll_interval):
print("The task did not complete successfully.")
return False
# 3. Fetch results incrementally and write to the file.
print("Task complete. Fetching parsing results...")
with open(output_path, 'w', encoding='utf-8') as f:
# Fetch and write content incrementally.
for layouts in self.collect_results_incrementally(task_id, layout_step_size):
markdown_content = self.generate_markdown(layouts)
f.write(markdown_content)
f.flush() # Immediately flush to the file.
print(f"Document parsing complete. Results saved to: {output_path}")
return True
def main():
import argparse
parser = argparse.ArgumentParser(description='Document Parsing Tool')
parser.add_argument('input_file', help='Path to the input document file.')
parser.add_argument('output_file', help='Path for the output Markdown file.')
parser.add_argument('--step-size', type=int, default=10, help='Step size for incremental fetch. Default: 10.')
parser.add_argument('--poll-interval', type=int, default=5, help='Polling interval in seconds. Default: 5.')
args = parser.parse_args()
# Create a document parser instance.
parser = DocParser()
# Process the document.
success = parser.process_document(
args.input_file,
args.output_file,
layout_step_size=args.step_size,
poll_interval=args.poll_interval
)
if success:
print("Document processing completed.")
else:
print("Document processing failed.")
exit(1)
if __name__ == "__main__":
main()