Download Document
Download a specified original document file. Usually, you first get the filepath and filename via the Document List, then call this endpoint.
Try It
GET
/documents/download_document?doc_file_path=%2Fdata%2Fuploads%2Ftenant_1%2Fhandbook.pdf&filename=handbook.pdfhttps://api-platform.ope.aiAuthentication
Uses Bearer Token authentication.
- Header:
Authorization: Bearer <token> - Example:
Authorization: Bearer sk-xxxxxx
Query Parameters
| Field | Type | Required | Description | Default / Range |
|---|---|---|---|---|
doc_file_path | string | Yes | The file path of the document, recommended to use the filepath returned by the document list | Requires URL encoding |
filename | string | Yes | The filename displayed when downloading | - |
Request Examples
- cURL
- JavaScript
curl -L "https://api-platform.ope.ai/documents/download_document?doc_file_path=%2Fdata%2Fuploads%2Ftenant_1%2Fhandbook.pdf&filename=handbook.pdf" \
-H "Authorization: Bearer $OPEAI_API_KEY" \
-o handbook.pdf
const url = new URL("https://api-platform.ope.ai/documents/download_document");
url.searchParams.set("doc_file_path", "/data/uploads/tenant_1/handbook.pdf");
url.searchParams.set("filename", "handbook.pdf");
const res = await fetch(url, {
headers: {
Authorization: `Bearer ${process.env.OPEAI_API_KEY}`,
},
});
const blob = await res.blob();
console.log(blob.size);
Response
Returns the file binary content on success. Returns error details on failure.
Error Responses
| Status Code | Scenario | Description |
|---|---|---|
401 | Authentication failed | API Key is missing, invalid, or has insufficient permissions |
422 | Validation failed | doc_file_path or filename is missing |
404 | File not found | Invalid file path or the file has been deleted |
500 | Download failed | File is inaccessible or server error occurred |