Parse File
curl --request POST \
--url https://api-prod.extend.app/parse \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file": {
"fileName": "<string>",
"fileUrl": "<string>",
"fileId": "<string>"
},
"config": {
"target": "<string>",
"chunkingStrategy": {
"type": "<string>",
"minCharacters": 123,
"maxCharacters": 123
},
"blockOptions": {
"figures": {
"enabled": true,
"figureImageClippingEnabled": true
},
"tables": {
"enabled": true,
"targetFormat": "<string>"
},
"text": {
"signatureDetectionEnabled": true
}
},
"advancedOptions": {
"pageRotationEnabled": true
}
}
}
'import requests
url = "https://api-prod.extend.app/parse"
payload = {
"file": {
"fileName": "<string>",
"fileUrl": "<string>",
"fileId": "<string>"
},
"config": {
"target": "<string>",
"chunkingStrategy": {
"type": "<string>",
"minCharacters": 123,
"maxCharacters": 123
},
"blockOptions": {
"figures": {
"enabled": True,
"figureImageClippingEnabled": True
},
"tables": {
"enabled": True,
"targetFormat": "<string>"
},
"text": { "signatureDetectionEnabled": True }
},
"advancedOptions": { "pageRotationEnabled": True }
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
file: {fileName: '<string>', fileUrl: '<string>', fileId: '<string>'},
config: {
target: '<string>',
chunkingStrategy: {type: '<string>', minCharacters: 123, maxCharacters: 123},
blockOptions: {
figures: {enabled: true, figureImageClippingEnabled: true},
tables: {enabled: true, targetFormat: '<string>'},
text: {signatureDetectionEnabled: true}
},
advancedOptions: {pageRotationEnabled: true}
}
})
};
fetch('https://api-prod.extend.app/parse', 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://api-prod.extend.app/parse",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file' => [
'fileName' => '<string>',
'fileUrl' => '<string>',
'fileId' => '<string>'
],
'config' => [
'target' => '<string>',
'chunkingStrategy' => [
'type' => '<string>',
'minCharacters' => 123,
'maxCharacters' => 123
],
'blockOptions' => [
'figures' => [
'enabled' => true,
'figureImageClippingEnabled' => true
],
'tables' => [
'enabled' => true,
'targetFormat' => '<string>'
],
'text' => [
'signatureDetectionEnabled' => true
]
],
'advancedOptions' => [
'pageRotationEnabled' => true
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api-prod.extend.app/parse"
payload := strings.NewReader("{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-prod.extend.app/parse")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-prod.extend.app/parse")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"object": "<string>",
"id": "<string>",
"fileId": "<string>",
"chunks": [
{
"object": "<string>",
"type": "<string>",
"content": "<string>",
"metadata": {
"pageRange": {
"start": 123,
"end": 123
}
},
"blocks": [
{
"object": "<string>",
"id": "<string>",
"type": "<string>",
"content": "<string>",
"details": {},
"metadata": {
"page": {
"number": 123,
"width": 123,
"height": 123
}
},
"polygon": [
{}
],
"boundingBox": {}
}
]
}
],
"status": "<string>",
"failureReason": "<string>",
"config": {},
"metrics": {
"processingTimeMs": 123,
"pageCount": 123
},
"code": "<string>",
"message": "<string>",
"requestId": "<string>",
"retryable": true
}Parse Endpoints
Parse File
Parse files to get cleaned, chunked target content (e.g. markdown).
Parse File
curl --request POST \
--url https://api-prod.extend.app/parse \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"file": {
"fileName": "<string>",
"fileUrl": "<string>",
"fileId": "<string>"
},
"config": {
"target": "<string>",
"chunkingStrategy": {
"type": "<string>",
"minCharacters": 123,
"maxCharacters": 123
},
"blockOptions": {
"figures": {
"enabled": true,
"figureImageClippingEnabled": true
},
"tables": {
"enabled": true,
"targetFormat": "<string>"
},
"text": {
"signatureDetectionEnabled": true
}
},
"advancedOptions": {
"pageRotationEnabled": true
}
}
}
'import requests
url = "https://api-prod.extend.app/parse"
payload = {
"file": {
"fileName": "<string>",
"fileUrl": "<string>",
"fileId": "<string>"
},
"config": {
"target": "<string>",
"chunkingStrategy": {
"type": "<string>",
"minCharacters": 123,
"maxCharacters": 123
},
"blockOptions": {
"figures": {
"enabled": True,
"figureImageClippingEnabled": True
},
"tables": {
"enabled": True,
"targetFormat": "<string>"
},
"text": { "signatureDetectionEnabled": True }
},
"advancedOptions": { "pageRotationEnabled": True }
}
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
file: {fileName: '<string>', fileUrl: '<string>', fileId: '<string>'},
config: {
target: '<string>',
chunkingStrategy: {type: '<string>', minCharacters: 123, maxCharacters: 123},
blockOptions: {
figures: {enabled: true, figureImageClippingEnabled: true},
tables: {enabled: true, targetFormat: '<string>'},
text: {signatureDetectionEnabled: true}
},
advancedOptions: {pageRotationEnabled: true}
}
})
};
fetch('https://api-prod.extend.app/parse', 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://api-prod.extend.app/parse",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'file' => [
'fileName' => '<string>',
'fileUrl' => '<string>',
'fileId' => '<string>'
],
'config' => [
'target' => '<string>',
'chunkingStrategy' => [
'type' => '<string>',
'minCharacters' => 123,
'maxCharacters' => 123
],
'blockOptions' => [
'figures' => [
'enabled' => true,
'figureImageClippingEnabled' => true
],
'tables' => [
'enabled' => true,
'targetFormat' => '<string>'
],
'text' => [
'signatureDetectionEnabled' => true
]
],
'advancedOptions' => [
'pageRotationEnabled' => true
]
]
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$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://api-prod.extend.app/parse"
payload := strings.NewReader("{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api-prod.extend.app/parse")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api-prod.extend.app/parse")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"file\": {\n \"fileName\": \"<string>\",\n \"fileUrl\": \"<string>\",\n \"fileId\": \"<string>\"\n },\n \"config\": {\n \"target\": \"<string>\",\n \"chunkingStrategy\": {\n \"type\": \"<string>\",\n \"minCharacters\": 123,\n \"maxCharacters\": 123\n },\n \"blockOptions\": {\n \"figures\": {\n \"enabled\": true,\n \"figureImageClippingEnabled\": true\n },\n \"tables\": {\n \"enabled\": true,\n \"targetFormat\": \"<string>\"\n },\n \"text\": {\n \"signatureDetectionEnabled\": true\n }\n },\n \"advancedOptions\": {\n \"pageRotationEnabled\": true\n }\n }\n}"
response = http.request(request)
puts response.read_body{
"object": "<string>",
"id": "<string>",
"fileId": "<string>",
"chunks": [
{
"object": "<string>",
"type": "<string>",
"content": "<string>",
"metadata": {
"pageRange": {
"start": 123,
"end": 123
}
},
"blocks": [
{
"object": "<string>",
"id": "<string>",
"type": "<string>",
"content": "<string>",
"details": {},
"metadata": {
"page": {
"number": 123,
"width": 123,
"height": 123
}
},
"polygon": [
{}
],
"boundingBox": {}
}
]
}
],
"status": "<string>",
"failureReason": "<string>",
"config": {},
"metrics": {
"processingTimeMs": 123,
"pageCount": 123
},
"code": "<string>",
"message": "<string>",
"requestId": "<string>",
"retryable": true
}The Parse endpoint allows you to convert documents into structured, machine-readable formats with fine-grained control over the parsing process. This endpoint is ideal for extracting cleaned document content to be used as context for downstream processing, e.g. RAG pipelines, custom ingestion pipelines, embeddings classification, etc.
Unlike processor and workflow runs, parsing is a synchronous endpoint and returns the parsed content in the response. Expected latency depends primarily on file size. This makes it suitable for workflows where you need immediate access to document content without waiting for asynchronous processing.
For a deeper guide on how to use the output of this endpoint, jump to Using Parsed Output.
When to use
By leveraging both the formatted content and the structured block information, you can build powerful document processing workflows that combine the convenience of formatted text with the precision of block-level access.
Body
object
required
A file object containing either a URL or base64 encoded content. Must contain
either fileUrl or fileId.
Hide properties
Hide properties
string
The name of the file. If not set, the file name is taken from the url or generated in case of raw upload.
string
A URL for the file. For production use cases, we recommend using presigned URLs with
a 5-15 minute expiration time.
object
required
Configuration options for the parsing process.
Show properties
Show properties
string
default:"markdown"
The target format for the parsed content. Supported values:
markdown: Convert document to Markdown formatspatial: Preserve spatial information in the output
object
Strategy for dividing the document into chunks.
Show properties
Show properties
string
default:"page"
The type of chunking strategy. Supported values:
page: Chunk document by pages.document: Entire document is a single chunk. Essentially no chunking.section: Split by logical sections. Not support for target=spatial.
number
Specify a minimum number of characters per chunk.
number
Specify a maximum number of characters per chunk.
object
Options for controlling how different block types are processed.
Show properties
Show properties
object
object
Response
string
The type of object. Will always be “parser_run”.
string
A unique identifier for the parser run.
string
The identifier of the file that was parsed. This can be used as a parameter to other Extend endpoints, such as processor runs. This allows downstream processing to reuse a cache of the parsed file content to reduce your usage costs.
array
An array of chunks extracted from the document.
Hide properties
Hide properties
string
The type of object. Will be “chunk”.
string
The type of chunk (e.g., “page”).
string
The textual content of the chunk in the specified target format.
object
array
An array of block objects that make up the chunk. See the Block object documentation for more detailed information about block structure and types.
Hide properties
Hide properties
string
The type of object. Will be “block”.
string
A unique identifier for the block.
string
The type of block. Possible values include:
text: Regular text contentheading: Section or document headingssection_heading: Subsection headingstable: Tabular data with rows and columnsfigure: Images, charts, or diagrams
string
The textual content of the block.
object
Additional details specific to the block type.
object
array
An array of points defining the polygon that bounds the block.
object
A simplified bounding box for the block.
string
The status of the parser run. Possible values:
PROCESSED: The file was successfully processedFAILED: The processing failed (see failureReason for details)
string
The reason for failure if status is “FAILED”. Will be null for successful runs.
object
The configuration used for the parsing process, including any default values that were applied.
object
const axios = require("axios");
const parseDocument = async () => {
try {
const response = await axios.post(
"https://api-prod.extend.app/parse",
{
file: {
fileName: "example.pdf",
fileUrl: "https://example.com/documents/example.pdf",
},
config: {
target: "markdown",
chunkingStrategy: {
type: "page",
},
blockOptions: {
figures: {
enabled: true,
figureImageClippingEnabled: true,
},
tables: {
enabled: true,
},
text: {
enabled: true,
styleFormattingEnabled: true,
},
},
},
},
{
headers: {
Authorization: "Bearer <API_TOKEN>",
"Content-Type": "application/json",
},
}
);
console.log("Document parsed successfully:", response.data);
} catch (error) {
console.error("Error:", error.response?.data || error.message);
}
};
parseDocument();
Using Parsed Output
The Parse API returns document content in a structured format that provides both high-level formatted content and detailed block-level information. Understanding how to work with this output will help you get the most value from the parsing service.Working with Chunks
Each chunk (currently only page-level chunks are supported) contains two key properties:-
content: A fully formatted representation of the entire chunk in the target format (e.g., markdown). This is ready to use as-is if you need the complete formatted content of a page. -
blocks: An array of individual content blocks that make up the chunk, each with its own formatting, position information, and metadata.
When to use chunk.content vs. chunk.blocks
-
Use
chunk.contentwhen:- You need the complete, properly formatted content of a page, already doing the logical placement of blocks (e.g. grouping markdown sections and placing spatially, etc)
- You want to display or process the document content as a whole (and can just combine all chunk.content values)
- You’re integrating with systems that expect formatted text (e.g., markdown processors)
-
Use
chunk.blockswhen:- You need to work with specific elements of the document (e.g., only tables or figures)
- You need spatial information about where content appears on the page, perhaps to build citation systems
- You’re building a UI that shows or highlights specific document elements
Example: Extracting specific content types
// Extract all tables from a document
function extractTables(parseResult) {
const tables = [];
parseResult.chunks.forEach(chunk => {
chunk.blocks.forEach(block => {
if (block.type === 'table') {
tables.push({
content: block.content,
pageNumber: block.metadata.pageNumber,
position: block.boundingBox
});
}
});
});
return tables;
}
// Extract all figures with their images
function extractFigures(parseResult) {
const figures = [];
parseResult.chunks.forEach(chunk => {
chunk.blocks.forEach(block => {
if (block.type === 'figure' && block.details.imageUrl) {
figures.push({
caption: block.content,
imageUrl: block.details.imageUrl,
figureType: block.details.figureType,
pageNumber: block.metadata.pageNumber
});
}
});
});
return figures;
}
Example: Reconstructing content with custom formatting
// Extract headings and their content to create a table of contents
function createTableOfContents(parseResult) {
const toc = [];
parseResult.chunks.forEach(chunk => {
chunk.blocks.forEach(block => {
if (block.type === 'heading' || block.type === 'section_heading') {
toc.push({
title: block.content,
pageNumber: block.metadata.pageNumber
});
}
});
});
return toc;
}
Spatial Information
Each block contains spatial information in the form of apolygon (precise outline) and a simplified boundingBox. This information can be used to:
- Highlight specific content in a document viewer
- Create visual overlays on top of the original document
- Understand the reading order and layout of the document
// Create highlight coordinates for a document viewer
function createHighlights(parseResult, searchTerm) {
const highlights = [];
parseResult.chunks.forEach(chunk => {
chunk.blocks.forEach(block => {
if (block.type === 'text' && block.content.includes(searchTerm)) {
highlights.push({
pageNumber: block.metadata.pageNumber,
boundingBox: block.boundingBox
});
}
});
});
return highlights;
}
Error Response Format
When an error occurs, the API returns a structured error response with the following fields:string
A specific error code that identifies the type of error.
string
A human-readable description of the error.
string
A unique identifier for the request, useful for troubleshooting.
boolean
Indicates whether retrying the request might succeed.
Custom Error Codes
The API may return the following specific error codes:Custom Error Codes
We provide custom error codes to make it easier for your system to know what happened in case of a failure. There will also be aretryable=true|false field in the response body, but you can also find a breakdown below. Most errors are not retryable and are client errors related to the file provided for parsing.
| Error Code | Description | Retryable |
|---|---|---|
INVALID_CONFIG_OPTIONS | Invalid combination of options in the incoming config. | ❌ |
UNABLE_TO_DOWNLOAD_FILE | The system could not download the file from the provided URL, likely means your presigned url is expired, or malformed somehow. | ❌ |
FILE_TYPE_NOT_SUPPORTED | The file type is not supported for parsing. | ❌ |
FILE_SIZE_TOO_LARGE | The file exceeds the maximum allowed size. | ❌ |
CORRUPT_FILE | The file is corrupt and cannot be parsed. | ❌ |
OCR_ERROR | An error occurred in the OCR system. This is a rare error code and would indicate downtime, so requests can be retried. We’d suggest applying a retry with backoff for this error. | ✅ |
PASSWORD_PROTECTED_FILE | The file is password protected and cannot be parsed. | ❌ |
FAILED_TO_CONVERT_TO_PDF | The system could not convert the file to PDF format. | ❌ |
FAILED_TO_GENERATE_TARGET_FORMAT | The system could not generate the requested target format. | ❌ |
INTERNAL_ERROR | An unexpected internal error occurred. We’d suggest applying a retry with backoff for this error as it likely a result of some outage. | ✅ |
HTTP error codes
Corresponding http error codes for different types of failures. We generally recommend relying on our custom error codes for programmatic handling.Returned when:
- Required fields are missing (e.g.,
file) - Neither
fileUrlnorfileBase64is provided in the file object - The provided
fileUrlis invalid - The provided
fileBase64is invalid - The
configcontains invalid values (e.g., unsupported target format or chunking strategy) - The file type is not supported
- The file size is too large
Returned when:
- The API token is missing
- The API token is invalid
Returned when:
- The authenticated workspace doesn’t have permission to use the parse functionality
- The API token doesn’t have sufficient permissions
Returned when:
- The file is corrupt and cannot be parsed
- The file is password protected
- The file could not be converted to PDF
- The system failed to generate the target format
Returned when:
- An OCR error occurs
- A chunking error occurs
- Any other unexpected error occurs during parsing
Handling Errors
Here are examples of how to handle errors from the Parse API:const axios = require("axios");
const parseDocument = async () => {
try {
const response = await axios.post(
"https://api-prod.extend.app/parse",
{
file: {
fileName: "example.pdf",
fileUrl: "https://example.com/documents/example.pdf",
},
config: {
target: "markdown",
},
},
{
headers: {
Authorization: "Bearer <API_TOKEN>",
"Content-Type": "application/json",
},
}
);
console.log("Document parsed successfully:", response.data);
return response.data;
} catch (error) {
if (error.response) {
const { code, message, requestId, retryable } = error.response.data;
// Handle specific error codes
switch (code) {
case "FILE_TYPE_NOT_SUPPORTED":
console.error("Unsupported file type. Please use a supported format.");
break;
case "PASSWORD_PROTECTED_FILE":
console.error("The file is password protected. Please provide an unprotected file.");
break;
case "CORRUPT_FILE":
console.error("The file is corrupt and cannot be processed.");
break;
case "FILE_SIZE_TOO_LARGE":
console.error("The file is too large. Please reduce the file size.");
break;
default:
console.error(`Error (${code}): ${message}`);
}
// Log request ID for troubleshooting
console.error(`Request ID: ${requestId}`);
// Potentially retry if the error is retryable
if (retryable) {
console.log("This error is retryable. Consider retrying the request.");
}
} else {
console.error("Network error:", error.message);
}
throw error;
}
};
import requests
def parse_document(file_url, file_name, config=None):
if config is None:
config = {"target": "markdown"}
url = "https://api-prod.extend.app/parse"
headers = {
"Authorization": "Bearer <API_TOKEN>",
"Content-Type": "application/json"
}
payload = {
"file": {
"fileName": file_name,
"fileUrl": file_url
},
"config": config
}
try:
response = requests.post(url, json=payload, headers=headers)
response.raise_for_status() # Raise exception for 4XX/5XX responses
return response.json()
except requests.exceptions.HTTPError as e:
error_data = e.response.json()
code = error_data.get("code")
message = error_data.get("message")
request_id = error_data.get("requestId")
retryable = error_data.get("retryable", False)
# Handle specific error codes
if code == "FILE_TYPE_NOT_SUPPORTED":
print(f"Error: Unsupported file type. {message}")
elif code == "PASSWORD_PROTECTED_FILE":
print(f"Error: Password protected file. {message}")
elif code == "CORRUPT_FILE":
print(f"Error: Corrupt file. {message}")
elif code == "FILE_SIZE_TOO_LARGE":
print(f"Error: File too large. {message}")
else:
print(f"Error ({code}): {message}")
# Log request ID for troubleshooting
print(f"Request ID: {request_id}")
# Potentially retry if the error is retryable
if retryable:
print("This error is retryable. Consider retrying the request.")
raise
except requests.exceptions.RequestException as e:
print(f"Network error: {str(e)}")
raise

