curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-o downloaded_file.csv
# Fetch the rest of the file from byte 1048576. If the file changed since the first
# response, the server ignores Range and returns the whole file with 200 instead of 206.
curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-H "Range: bytes=1048576-" \
-H 'If-Range: "<etag from the first response>"' \
-o downloaded_file.part
import requests
import os
api_key = os.environ.get("ATAI_API_KEY")
file_id = "file-abc123"
response = requests.get(
f"https://platform.u1.archetypeai.app/api/files/download/{file_id}",
headers={"Authorization": f"Bearer {api_key}"},
stream=True,
)
response.raise_for_status()
with open("downloaded_file.csv", "wb") as fh:
for chunk in response.iter_content(chunk_size=1 << 20):
fh.write(chunk)
print(f"Downloaded {file_id}")
import fs from "node:fs";
import { Readable } from "node:stream";
const fileId = "file-abc123";
const response = await fetch(
`https://platform.u1.archetypeai.app/api/files/download/${fileId}`,
{
headers: {
Authorization: `Bearer ${process.env.ATAI_API_KEY}`,
},
}
);
if (!response.ok) {
throw new Error(`Download failed: ${response.status}`);
}
const out = fs.createWriteStream("downloaded_file.csv");
Readable.fromWeb(response.body).pipe(out);
<binary file contents — Content-Type: application/octet-stream>
<the requested bytes; Content-Range: bytes 1048576-12483909/12483910>
{
"errors": [
{
"code": "unauthorized_request",
"message": "Unauthorized or invalid access.",
"suggestion": "Provide valid authentication credentials and ensure they have the required permissions.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_found",
"message": "No file with the given file_id was found for the organization.",
"suggestion": "Verify the file_id and that the file has not been deleted.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_available",
"message": "File is not available: status=UPLOADING",
"suggestion": null,
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "precondition_failed",
"message": "The file's current version does not match `If-Match`",
"suggestion": "Get the file's current `ETag` and retry with it",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "range_not_satisfiable",
"message": "The requested range selects no byte of the file, which is 12483910 bytes long",
"suggestion": "Request a non-empty range that starts before the end of the file",
"error_uid": "err-xxxxxxxx"
}
]
}
Files API
Download File
Download the raw bytes of a previously uploaded file
GET
/
api
/
files
/
download
/
{file_id}
curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-o downloaded_file.csv
# Fetch the rest of the file from byte 1048576. If the file changed since the first
# response, the server ignores Range and returns the whole file with 200 instead of 206.
curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-H "Range: bytes=1048576-" \
-H 'If-Range: "<etag from the first response>"' \
-o downloaded_file.part
import requests
import os
api_key = os.environ.get("ATAI_API_KEY")
file_id = "file-abc123"
response = requests.get(
f"https://platform.u1.archetypeai.app/api/files/download/{file_id}",
headers={"Authorization": f"Bearer {api_key}"},
stream=True,
)
response.raise_for_status()
with open("downloaded_file.csv", "wb") as fh:
for chunk in response.iter_content(chunk_size=1 << 20):
fh.write(chunk)
print(f"Downloaded {file_id}")
import fs from "node:fs";
import { Readable } from "node:stream";
const fileId = "file-abc123";
const response = await fetch(
`https://platform.u1.archetypeai.app/api/files/download/${fileId}`,
{
headers: {
Authorization: `Bearer ${process.env.ATAI_API_KEY}`,
},
}
);
if (!response.ok) {
throw new Error(`Download failed: ${response.status}`);
}
const out = fs.createWriteStream("downloaded_file.csv");
Readable.fromWeb(response.body).pipe(out);
<binary file contents — Content-Type: application/octet-stream>
<the requested bytes; Content-Range: bytes 1048576-12483909/12483910>
{
"errors": [
{
"code": "unauthorized_request",
"message": "Unauthorized or invalid access.",
"suggestion": "Provide valid authentication credentials and ensure they have the required permissions.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_found",
"message": "No file with the given file_id was found for the organization.",
"suggestion": "Verify the file_id and that the file has not been deleted.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_available",
"message": "File is not available: status=UPLOADING",
"suggestion": null,
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "precondition_failed",
"message": "The file's current version does not match `If-Match`",
"suggestion": "Get the file's current `ETag` and retry with it",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "range_not_satisfiable",
"message": "The requested range selects no byte of the file, which is 12483910 bytes long",
"suggestion": "Request a non-empty range that starts before the end of the file",
"error_uid": "err-xxxxxxxx"
}
]
}
Requires version 1.1.5 or later of the Archetype platform.
Overview
This endpoint streams the raw contents of a previously uploaded file. The response body isapplication/octet-stream — the file as it was uploaded.
The file must be in a downloadable state. A file that is still uploading or is corrupt returns an
HTTP 409 error with the code file_not_available. Files that are being deleted or are already deleted return an HTTP
404 error.
Prior to platform version 2.0.0, files that cannot be deleted caused an HTTP
400 error instead.file_uid instead of its filename, use Download File
Content.
Path Parameters
string
required
Identifier of the file to download
Header Parameters
string
A single byte range to download, as
bytes=first-last (both inclusive; a last past the end
of the file stops at the end), bytes=first- (to the end of the file) or bytes=-n (the last
n bytes). A Range header with several ranges, a unit other than bytes, or a malformed
value is ignored, and the whole file is returned with 200. v2.0.0+string
Serve
Range only if the file’s ETag is still exactly this value. Otherwise the range is
ignored and the whole current file is returned with 200. Dates and weak tags never
match. v2.0.0+string
Download only if the file’s
ETag is one of these comma-separated values, or this is *.
Otherwise the response is 412 with the code precondition_failed and carries no file
content. If-Match is checked before Range, so a failed If-Match returns 412 even when
the range can’t be satisfied. v2.0.0+Response
The response body is the raw file bytes withContent-Type: application/octet-stream.
A satisfiable Range is answered with 206 and only the requested bytes, plus a
Content-Range: bytes first-last/size header. A range that starts at or past the end of the
file, or bytes=-0, returns 416 with the code range_not_satisfiable and a
Content-Range: bytes */size header. v2.0.0+
Both 200 and 206 responses carry Accept-Ranges: bytes and an ETag that changes whenever
the file’s content does. Treat the ETag as opaque. To resume an interrupted download, send the
ETag from the first response in If-Range along with a Range that starts where you
stopped. v2.0.0+
curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-o downloaded_file.csv
# Fetch the rest of the file from byte 1048576. If the file changed since the first
# response, the server ignores Range and returns the whole file with 200 instead of 206.
curl https://platform.u1.archetypeai.app/api/files/download/file-abc123 \
-H "Authorization: Bearer $ATAI_API_KEY" \
-H "Range: bytes=1048576-" \
-H 'If-Range: "<etag from the first response>"' \
-o downloaded_file.part
import requests
import os
api_key = os.environ.get("ATAI_API_KEY")
file_id = "file-abc123"
response = requests.get(
f"https://platform.u1.archetypeai.app/api/files/download/{file_id}",
headers={"Authorization": f"Bearer {api_key}"},
stream=True,
)
response.raise_for_status()
with open("downloaded_file.csv", "wb") as fh:
for chunk in response.iter_content(chunk_size=1 << 20):
fh.write(chunk)
print(f"Downloaded {file_id}")
import fs from "node:fs";
import { Readable } from "node:stream";
const fileId = "file-abc123";
const response = await fetch(
`https://platform.u1.archetypeai.app/api/files/download/${fileId}`,
{
headers: {
Authorization: `Bearer ${process.env.ATAI_API_KEY}`,
},
}
);
if (!response.ok) {
throw new Error(`Download failed: ${response.status}`);
}
const out = fs.createWriteStream("downloaded_file.csv");
Readable.fromWeb(response.body).pipe(out);
<binary file contents — Content-Type: application/octet-stream>
<the requested bytes; Content-Range: bytes 1048576-12483909/12483910>
{
"errors": [
{
"code": "unauthorized_request",
"message": "Unauthorized or invalid access.",
"suggestion": "Provide valid authentication credentials and ensure they have the required permissions.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_found",
"message": "No file with the given file_id was found for the organization.",
"suggestion": "Verify the file_id and that the file has not been deleted.",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "file_not_available",
"message": "File is not available: status=UPLOADING",
"suggestion": null,
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "precondition_failed",
"message": "The file's current version does not match `If-Match`",
"suggestion": "Get the file's current `ETag` and retry with it",
"error_uid": "err-xxxxxxxx"
}
]
}
{
"errors": [
{
"code": "range_not_satisfiable",
"message": "The requested range selects no byte of the file, which is 12483910 bytes long",
"suggestion": "Request a non-empty range that starts before the end of the file",
"error_uid": "err-xxxxxxxx"
}
]
}
Was this page helpful?