Skip to content

List files

GET /v1/files

Lists the files this key or its owner uploaded, or the files a session produced, newest first.

Without scope_id, the list holds files uploaded with a Task API key: the files this key uploaded, and the files that this key’s owner owns. With scope_id set to a session ID, the list holds the files that session’s agent produced, each with a scope field that names the session. That list leaves out the session’s attached files, the files the platform stores for the session (such as its transcript), and large tool results saved during the session. The list stays the same after the session is archived.

Send at most one of page, after_id and before_id. Both SDKs paginate with page.

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

Query parameters

NameTypeRequiredDefaultDescription
limitintegerNo20The maximum number of files to return. Must be between 1 and 100.
pagestringNoThe next_page value from the previous response. Leave it out to get the first page.
after_idstringNoThe ID of a file. Returns files older than that file. Pass last_id from the previous page.
before_idstringNoThe ID of a file. Returns files newer than that file. Pass first_id from the previous page.
scope_idstringNoA session ID. Returns the files that session’s agent produced instead of the default list.

Response

Returns 200 with a list of file objects, newest first.

FieldDescription
dataThe files on this page.
first_idThe ID of the first file on the page.
last_idThe ID of the last file on the page.
has_moretrue when more files remain in the direction you are paging: older files for page and after_id, newer files for before_id.
next_pageThe value to pass as page for the next page. It is null on the last page and on a before_id page.
{
"data": [
{
"id": "329409ba-f288-4b44-9c73-14a18150edee",
"created_at": "2026-10-21T01:41:11.028Z",
"filename": "cities.csv",
"mime_type": "text/csv",
"size_bytes": 46,
"type": "file",
"downloadable": true
}
],
"next_page": null,
"has_more": false,
"first_id": "329409ba-f288-4b44-9c73-14a18150edee",
"last_id": "329409ba-f288-4b44-9c73-14a18150edee"
}

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorlimit is outside 1 to 100. Send a value from 1 to 100.
400invalid_request_errorThe request sends more than one of page, after_id and before_id. Send only one of them.
400invalid_request_errorThe request sends ids, which this API doesn’t take. Remove it.
404not_found_errorafter_id or before_id names a file that isn’t on this list. Pass first_id or last_id from a previous page of this list.
404not_found_errorscope_id names a session this key can’t read. Pass the ID of a session this key can read.

Example

cURL
curl -sS "$CONTEXT_BASE_URL/v1/files?limit=20" -H "x-api-key: $CONTEXT_API_KEY"
# The files a session produced
curl -sS "$CONTEXT_BASE_URL/v1/files?scope_id=dd13d728-93e3-440a-874c-4efeb58c97e0" -H "x-api-key: $CONTEXT_API_KEY"
Python
for file in client.beta.files.list(limit=20): # auto-paginates
print(file.id, file.filename, file.size_bytes)
# The files a session produced
for file in client.beta.files.list(scope_id="dd13d728-93e3-440a-874c-4efeb58c97e0"):
print(file.id, file.filename)
TypeScript
for await (const file of client.beta.files.list({ limit: 20 })) console.log(file.id, file.filename)
// The files a session produced
for await (const file of client.beta.files.list({ scope_id: "dd13d728-93e3-440a-874c-4efeb58c97e0" })) console.log(file.id, file.filename)