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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
file_id | string | Yes | The 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.
| Status | error.type | Cause and fix |
|---|---|---|
| 402 | billing_error | The 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. |
| 404 | not_found_error | No 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. |
| 404 | not_found_error | The file’s content is no longer stored. If you uploaded the file, upload it again. |
Example
curl -sS "$CONTEXT_BASE_URL/v1/files/329409ba-f288-4b44-9c73-14a18150edee/content" -H "x-api-key: $CONTEXT_API_KEY" -o cities.csvclient.beta.files.download("329409ba-f288-4b44-9c73-14a18150edee").write_to_file("cities.csv")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()))