Skip to content
Context docs
Context Agent API

A file is either a document you upload for an agent to read during a session, or an output an agent writes during a session. Upload a file, then attach it when you create a session. Each upload is stored in the Context app, in the Drive of the user who owns the API key.

The agent writes the files it produces to /mnt/session/outputs/, as on Anthropic's API. To get them, list files with scope_id set to the session's ID, then download each one. They stay listed after you archive the session.

Deleting a file is permanent: it can't be restored through this API or the app. You can delete only files you uploaded. Files a session produced can't be deleted or attached to another session. You can't delete a file attached to a session that isn't archived. The request returns 400. Archive the session first.

The file object

FieldTypeDescription
idstringThe file's ID. An uploaded file's ID is a UUID. A file a session produced has an ID that starts with sesnfile_. Treat both as opaque.
typestringAlways file.
filenamestringThe name sent with the upload. For a file a session produced, this is its path in the session's output folder, such as charts/q3.csv.
mime_typestringThe media type sent with the upload, or application/octet-stream if none was sent.
size_bytesintegerThe size in bytes, or 0 if the size wasn't recorded.
created_atstringWhen the file was uploaded or written, as an RFC 3339 timestamp.
downloadablebooleanAlways true.
scopeobjectThe session that produced the file, as {type: "session", id}, where id is the session's ID. Uploaded files have no scope field.

Example

JSONCode
{ "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 }

Differences from Anthropic's API

This API follows Anthropic's Managed Agents API, with these differences:

  • Upload accepts expires_in_seconds from 3600 to 7776000, but doesn't apply it. Files don't expire, and the file object has no expires_at.
  • List files doesn't support ids. Sending it returns 400.
  • A list response holds at most 100 files per page. Anthropic's API allows up to 1,000.
  • An upload can be as large as your deployment's upload limit, which defaults to 5 GiB. Anthropic's limit is 500 MB.
  • The files a session produced can't be deleted or attached to another session through this API.
  • List files also accepts after_id and before_id, and returns has_more, first_id and last_id, which Anthropic's list response doesn't include.
  • Deleting a file that a session still uses returns 400. See Delete a file.

For every difference in one place, see Coming from Anthropic's API.


List files

GET
https://api.context.ai
/v1/files
x-api-key (header)

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.

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.

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.

List files › query Parameters

limit
​integer · min: 1 · max: 100

The maximum number of files to return. Must be between 1 and 100.

The maximum number of files to return. Must be between 1 and 100.

Default: 20
page
​string

The next_page value from the previous response. Leave it out to get the first page.

The next_page value from the previous response. Leave it out to get the first page.

after_id
​string · minLength: 1

The ID of a file. Returns files older than that file. Pass last_id from the previous page.

The ID of a file. Returns files older than that file. Pass last_id from the previous page.

before_id
​string · minLength: 1

The ID of a file. Returns files newer than that file. Pass first_id from the previous page.

The ID of a file. Returns files newer than that file. Pass first_id from the previous page.

scope_id
​string · minLength: 1

A session ID. Returns the files that session's agent produced instead of the default list.

A session ID. Returns the files that session's agent produced instead of the default list.

List files › Headers

anthropic-workspace-id
​string

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

List files › Responses

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

​object[] · required
next_page
​string | null · required
has_more
​boolean · required
first_id
​string | null · required
last_id
​string | null · required

Upload a file

POST
https://api.context.ai
/v1/files
x-api-key (header)

Uploads one file to the Drive of the user who owns the key.

Send multipart/form-data with one file field, whose part includes a filename, and optionally an expires_in_seconds field. The server accepts any file type. In a body over 10 MiB, expires_in_seconds must come before file. The Python and .NET SDKs send it first. With the TypeScript SDK, write expires_in_seconds before file in the object you pass to files.upload.

These limits apply:

  • A file can be up to your deployment's upload limit, which is 5 GiB unless your administrator set it lower.
  • Send a Content-Length header. cURL and the SDKs send one for you. A request without one must use chunked encoding and be 10 MiB or smaller.
  • Each key can have up to 4 uploads in progress on one server instance, and each instance takes up to 8 in total across all keys. Keep 4 or fewer uploads in progress, and retry on 429.

If the request fails partway, the server keeps nothing.

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

Response

Returns 200 with the file object. For every field, see Files.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorThe form has a field other than file and expires_in_seconds. Remove the other fields.
400invalid_request_errorexpires_in_seconds isn't a whole number between 3600 and 7776000. Send a value in that range, or omit it.
400invalid_request_errorexpires_in_seconds comes after file in a body over 10 MiB. Send expires_in_seconds before file, or omit it.
400invalid_request_errorThe form has no file field, or more than one, or the filename is empty. Send exactly one file field with a non-empty filename.
400invalid_request_errorThe body doesn't match its Content-Length: bytes follow the closing boundary, or the body ends early. The server keeps nothing. Send an exact Content-Length.
413request_too_largeThe file is over your deployment's upload limit (5 GiB unless your administrator set it lower), or a chunked request is over 10 MiB. The message gives the limit. If the file is over the upload limit, send a smaller file. If the request is chunked and over 10 MiB, send it again with a Content-Length header.
429rate_limit_errorThis key already has 4 uploads in progress on the server instance that answered, or 8 are in progress there for all keys. Wait for the time in Retry-After, then retry.

Upload a file › Headers

anthropic-workspace-id
​string

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

Upload a file › Request Body

file
​string · binary · required

The file, with a filename. If the part has no media type, the server stores the file as application/octet-stream.

expires_in_seconds
​integer · min: 3600 · max: 7776000

The number of seconds until the file expires on Anthropic's API. Must be a whole number between 3600 and 7776000. It isn't applied: the file is kept until you delete it, and the file object has no expires_at.

Upload a file › Responses

Returns 200 with the file object. For every field, see Files.

id
​string · required
created_at
​string · date-time · required
filename
​string · required
mime_type
​string · required
size_bytes
​number · required
type
​string · enum · required
Enum values:
file
downloadable
​boolean · enum · required
Enum values:
​object

Get a file

GET
https://api.context.ai
/v1/files/{file_id}
x-api-key (header)

Returns a file's metadata.

To get the file's content, see Download a file.

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

Response

Returns 200 with the file object. For every field, see Files.

Errors

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

Statuserror.typeCause and fix
404not_found_errorNo file with this ID exists, or this key can't read it or the session that produced it. Check the ID from the upload or from the list.

Get a file › path Parameters

file_id
​string · required

The ID of the file to retrieve.

The ID of the file to retrieve.

Get a file › Headers

anthropic-workspace-id
​string

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

Get a file › Responses

Returns 200 with the file object. For every field, see Files.

id
​string · required
created_at
​string · date-time · required
filename
​string · required
mime_type
​string · required
size_bytes
​number · required
type
​string · enum · required
Enum values:
file
downloadable
​boolean · enum · required
Enum values:
​object

Delete a file

DELETE
https://api.context.ai
/v1/files/{file_id}
x-api-key (header)

Permanently deletes an uploaded file.

The file doesn't go to the Drive trash, and it can't be restored through this API or the app. A later request for it returns 404. If the server can't delete the stored copy, the request returns 500 and the copy stays in the owner's Drive. See the errors below.

A service account key can delete only the files it uploaded. This endpoint can't delete files that a session produced, or a file that a session or run still uses. See the errors below.

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

Response

Returns 200 with an object that holds the file's id and a type of file_deleted.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorThe file is attached to a session that isn't archived, or is used by a run that hasn't finished. Archive the session, or wait for the run to finish, then retry.
400invalid_request_errorThe file was produced by a session. Download it with Download a file, or remove it from the session's folder in Drive.
403permission_errorThe key lacks files:write. Use a key that has files:write.
403permission_errorThe key's owner can't edit the Drive folder that holds the file. Use a key whose owner can edit that folder.
403permission_errorA service account key tried to delete a file it didn't upload. Use the personal key of the user who owns the file.
404not_found_errorNo file with this ID exists, or this key can't read it. Check the ID against List files. If the ID is correct, check that the key can read the file.
500api_errorThe API no longer returns the file, but its stored copy couldn't be deleted. The message says where the copy remains in the owner's Drive. Delete it there, or quote request_id when you contact support.

Delete a file › path Parameters

file_id
​string · required

The ID of the file to delete.

The ID of the file to delete.

Delete a file › Headers

anthropic-workspace-id
​string

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

Delete a file › Responses

Returns 200 with an object that holds the file's id and a type of file_deleted.

id
​string · required
type
​string · enum · required
Enum values:
file_deleted

Download a file

GET
https://api.context.ai
/v1/files/{file_id}/content
x-api-key (header)

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.

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.

Download a file › path Parameters

file_id
​string · required

The ID of the file to download.

The ID of the file to download.

Download a file › Headers

anthropic-workspace-id
​string

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

The ID of a workspace in the key's organization that the key's owner works in. Agent and session requests run in that workspace; other requests only check it. The response echoes it. If the owner doesn't work there, the request returns 404. Without it, a new session runs in the agent's workspace or the owner's private workspace: see Where a session runs.

Download a file › Responses

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.

string · binary