Skip to content

Download a file

GET /v1/files/{file_id}/content

Returns a file’s content exactly as it was uploaded or as a session wrote it.

For an uploaded file, the file’s owner must be able to read it in Drive. For a file a session produced, the key must be able to read that session and the file in Drive. If a check fails, the request returns 404.

The server streams the content, so the response has no content-length header. To read the file’s name, size and media type without downloading it, see Get a file.

The key must have the files:read capability. For what each capability allows, see Keys.

Path parameters

NameTypeRequiredDefaultDescription
file_idstringYesThe ID of the file to download.

Response

Returns 200 with the file’s bytes. The content-type response header is the media type stored with the file, or application/octet-stream if none was sent.

Errors

This endpoint can return these errors as well as the common errors.

Statuserror.typeCause and fix
402billing_errorThe file is a session’s output, and your deployment requires a paid plan or credits before you can download session output. Add a plan or credits in the app, then retry.
404not_found_errorNo file with this ID exists, or this key can’t read the file or the session that produced it. Check the ID against the upload response or List files. If the ID is correct, check the access rules on this page.
404not_found_errorThe file’s content is no longer stored. If you uploaded the file, upload it again.

Example

cURL
curl -sS "$CONTEXT_BASE_URL/v1/files/329409ba-f288-4b44-9c73-14a18150edee/content" -H "x-api-key: $CONTEXT_API_KEY" -o cities.csv
Python
client.beta.files.download("329409ba-f288-4b44-9c73-14a18150edee").write_to_file("cities.csv")
TypeScript
import { writeFile } from "node:fs/promises"
const response = await client.beta.files.download("329409ba-f288-4b44-9c73-14a18150edee")
await writeFile("cities.csv", Buffer.from(await response.arrayBuffer()))