Skip to content
Context docs
Context Agent API

A session is a task you start over the API.

A session is a task you start over the API, and it shows in the Context app like any other task. The owner of the key that created it owns the task. A service account key can name another member as the owner with the x-context-owner-user-id or x-context-owner-user-email header. The task has the same transcript and tool permissions as a task started in the app. A session ends when you archive it, and its history stays readable. Nothing deletes a session for you: your deployment keeps it until you delete it. To remove a session and its data permanently, delete it with a key that has sessions:delete, which keys don't have by default (see Choosing a key). To send messages to a session and stream the agent's replies, see Events.

Not every task is a session. A task is a session only when it is a top-level task (not a subagent's), runs on Context's own agent engine and was started over an API: by this API, by the Task API (POST /api/v1/tasks) or by a schedule. A task someone started in the app is not a session, even though it is the same kind of task: GET /v1/sessions/{session_id} returns 404 for it, and List sessions leaves it out. So a session you create here can also be read with the Task API, under the same ID, but a task started in the app can't be picked up with this API.

Status

statusMeaning
idleThe session is waiting for a message or a tool approval, or hasn't started.
runningA turn is in progress.
terminatedThe session is archived. Nothing else terminates a session.
reschedulingThis status is never returned. List sessions accepts it as a statuses filter, which then matches nothing.

The session object

FieldTypeDescription
idstringThe session's ID, a UUID. It is also the task's ID in the app.
typestringAlways session.
statusstringThe session's status. One of idle, running or terminated. See Status.
titlestring | nullThe session's title. The maximum length is 280 characters.
agentobjectThe agent the session runs, as in Agents without its timestamps and metadata.
environment_idstringWhere the session runs: env_default. See Environments.
max_step_minutesinteger | nullA Context extension. The longest one step of this session may run, in minutes, set when the session was created. See Create a session. null means no step limit runs: a session on a paired computer, or one created before this field existed.
resourcesarray<object>The files attached when the session was created, each {id, type: "file", file_id, mount_path, created_at, updated_at}. If you sent a mount_path, this is the file's absolute path on the agent's disk. Otherwise it is inputs/<filename>, in the session's inputs/ folder. id equals file_id.
usageobjectThe totals for the whole session, subagents included: input_tokens, output_tokens, cache_read_input_tokens, cache_creation, active_seconds and list_cost.
usage.cache_creationobjectCache-write tokens, as {ephemeral_5m_input_tokens, ephemeral_1h_input_tokens}. ephemeral_1h_input_tokens is always 0, because every cache write counts as a 5-minute write.
usage.active_secondsnumberThe seconds the session spent working, to the millisecond. Time spent waiting for a tool approval isn't counted. While a turn runs, the value grows on every read.
usage.list_costobject | nullThe session's cost at list price, as {amount, currency: "USD"}. amount is a whole number of cents, as a string. It covers model calls plus web search, image search and media generation, priced for the session's owner. See the list below the table for when it is null.
created_atstringWhen the session was created, as an RFC 3339 timestamp.
updated_atstringWhen the session last changed, as an RFC 3339 timestamp.
archived_atstring | nullFor an archived session, the time it last changed, as an RFC 3339 timestamp. That is when it was archived, unless it was renamed after, which sets it to the time of the rename. null for a session that isn't archived.

usage.list_cost is null in these cases:

  • A turn is running. A cost shown earlier returns to null while a later turn runs.
  • Billing hasn't settled, which takes about 12 minutes after the session goes idle.
  • No model call was made.
  • Your organization counts usage in tokens.

Once it appears, usage.list_cost can still rise. A model call made outside a turn, such as one by a background job the agent started, is added when billing records it.

Some fields always hold the same value: budget is null, metadata and stats are {}, and outcome_evaluations and vault_ids are empty.

Example

JSONCode
{ "id": "dd13d728-93e3-440a-874c-4efeb58c97e0", "agent": { "id": "6f1c2a9e-0d4b-4c57-9a3e-2b7d8e1f4c60", "description": "Answers questions about the sales pipeline", "execution_identity": { "type": "service_account" }, "mcp_servers": [], "model": { "id": "default" }, "multiagent": null, "name": "Research Assistant", "skills": [], "system": null, "tools": [], "type": "agent", "version": 1 }, "archived_at": null, "budget": null, "created_at": "2026-10-21T01:42:16.079Z", "environment_id": "env_default", "max_step_minutes": 240, "metadata": {}, "outcome_evaluations": [], "resources": [ { "id": "329409ba-f288-4b44-9c73-14a18150edee", "created_at": "2026-10-21T01:41:11.028Z", "file_id": "329409ba-f288-4b44-9c73-14a18150edee", "mount_path": "inputs/cities.csv", "type": "file", "updated_at": "2026-10-21T01:41:11.028Z" } ], "stats": {}, "status": "idle", "title": "Quarterly city report", "type": "session", "updated_at": "2026-10-21T01:42:29.719Z", "usage": { "input_tokens": 12, "output_tokens": 318, "cache_read_input_tokens": 133496, "cache_creation": { "ephemeral_5m_input_tokens": 2210, "ephemeral_1h_input_tokens": 0 }, "active_seconds": 7.331, "list_cost": { "amount": "6", "currency": "USD" } }, "vault_ids": [] }

Differences from Anthropic's API

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

  • Deleting a session needs the sessions:delete capability, which keys don't have by default. Deleting a session while a turn runs returns 409: interrupt the turn, wait for idle, then delete it. The delete response lists what was removed and what was kept. See Delete a session.
  • POST /v1/sessions takes x-context-owner-user-id or x-context-owner-user-email, so a service account key can create a session for another member. Anthropic's API has no such headers.
  • POST /v1/sessions returns 400 if the request overrides an agent field (any field in the agent object besides type, id and version), or sends a non-empty metadata, a non-empty vault_ids or a non-null budget.
  • initial_events takes at most one event, a user.message. Anthropic's API takes up to 50 events of different types.
  • Only file resources are supported. Any other type returns 400.
  • A file sent without mount_path isn't placed on the agent's disk. Anthropic's API copies it to /mnt/session/uploads/<file_id>. Here it stays in the session's inputs/ folder in Drive, where the agent reads it, and its mount_path reads inputs/<filename>.
  • mount_path takes a path under /workspace/ or /mnt/session/uploads/. Any other absolute path is placed under /mnt/session/uploads: /data/a.csv becomes /mnt/session/uploads/data/a.csv, and mount_path reports the new path.
  • usage.server_tool_use isn't sent.
  • title takes up to 280 characters, and a session takes up to 50 files. Anthropic's API allows 500 of each.
  • A list response holds at most 100 sessions per page. Anthropic's API allows up to 1,000.
  • On list, order=asc and the agent_version, deployment_id and memory_store_id filters return 400.

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


List sessions

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

Lists the sessions this key can see, newest first.

A personal key reads its owner's sessions, including sessions a service account key created for its owner. A service account key reads only the sessions it created, whoever owns them. If the key is limited to specific agents (its Agent scope), it reads only those agents' sessions.

The statuses filter applies after the server reads each page.

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

Response

Returns 200 with the matching sessions in data, newest first. next_page is the value to pass as page for the next page. A page can hold fewer sessions than limit, or none, and still have a next_page value. Keep requesting pages until next_page is null. prev_page is always null.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errororder is any value other than desc. Omit order.
400invalid_request_errorstatuses contains an unknown value. Send only idle, running, terminated or rescheduling.
400invalid_request_errorThe request includes agent_version, deployment_id or memory_store_id, which this API does not take. Remove them.

List sessions › query Parameters

limit
​integer · min: 1 · max: 100

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

The maximum number of sessions 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.

created_at[gt]
​string · date-time

Only sessions created after this RFC 3339 timestamp.

Only sessions created after this RFC 3339 timestamp.

created_at[gte]
​string · date-time

Only sessions created at or after this RFC 3339 timestamp.

Only sessions created at or after this RFC 3339 timestamp.

created_at[lt]
​string · date-time

Only sessions created before this RFC 3339 timestamp.

Only sessions created before this RFC 3339 timestamp.

created_at[lte]
​string · date-time

Only sessions created at or before this RFC 3339 timestamp.

Only sessions created at or before this RFC 3339 timestamp.

agent_id
​string

The ID of the agent whose sessions to return.

The ID of the agent whose sessions to return.

include_archived
​boolean

Whether to include archived sessions.

Whether to include archived sessions.

Default: false
order
​string · enum

Not supported. Omit it or send desc. Any other value returns 400.

Not supported. Omit it or send desc. Any other value returns 400.

Enum values:
desc
Default: desc
statuses
​string[]

The statuses to return: idle, running or terminated. rescheduling is accepted for compatibility but never matches a session. To pass more than one, repeat the parameter: statuses=idle&statuses=running.

The statuses to return: idle, running or terminated. rescheduling is accepted for compatibility but never matches a session. To pass more than one, repeat the parameter: statuses=idle&statuses=running.

Enum values:
rescheduling
running
idle
terminated
statuses[]
​string[]

The same filter as statuses, in the bracketed form the SDKs send: statuses[]=idle&statuses[]=running.

The same filter as statuses, in the bracketed form the SDKs send: statuses[]=idle&statuses[]=running.

Enum values:
rescheduling
running
idle
terminated

List sessions › 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 sessions › Responses

Returns 200 with the matching sessions in data, newest first. next_page is the value to pass as page for the next page. A page can hold fewer sessions than limit, or none, and still have a next_page value. Keep requesting pages until next_page is null. prev_page is always null.

​object[] · required
next_page
​string | null · required
prev_page
​null · required

Create a session

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

Creates a session for an agent, optionally with files and a first message.

Without initial_events the session is idle until you send its first message. With one message it starts at once and is running. If the request fails, it returns an error and no session. If the server already created the session's task in the Context app, it archives it.

Files sent with a mount_path are copied to the agent's disk, read-only, before the first turn. If a file can't be copied, the session still runs and the file stays in the session's inputs/ folder.

The key must have the tasks:create capability. For what each capability allows, see Keys.

Response

Returns 200 with the session object. For every field, see Sessions.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorA resource isn't a file. Send each resource as {type: "file", file_id}, with an optional mount_path.
400invalid_request_errorA mount_path is empty, relative, ends in /, holds ., .., a repeated / or a control character, or is too long. Send a normalized absolute path.
400invalid_request_errorMore than 100 files have a mount_path, two files name the same path, a path sits below another mounted file, or a mounted file is listed twice. Give each mounted file its own path, and list it once.
400invalid_request_errorAn owner header is empty, or the request sends both x-context-owner-user-id and x-context-owner-user-email. Send one header with a member's ID or email, or omit both so the key's owner owns the session.
400invalid_request_errorThe named owner isn't an active member of this key's organization. Check the ID or email.
400invalid_request_errorinitial_events holds more than one event, or one that isn't a user.message. Send at most one user.message, then send the rest with Send events.
400invalid_request_errorThe title is over 280 characters. Shorten it.
400invalid_request_errormax_step_minutes: <n> is above this deployment's maximum of <max> minutes (NATIVE_MAX_TURN_BUDGET_MINUTES). Send <max> or less, or ask your administrator to raise the maximum. A value that isn't a whole number above 0 also returns 400.
400invalid_request_errorThe body sends non-empty metadata or vault_ids, a non-null budget, or agent overrides (any field in the agent object besides type, id and version). Remove them.
400invalid_request_errorA file_id names a file a session produced, which can't be attached. Download it and upload it, then attach the upload.
400invalid_request_errorAgent "<name>" (<id>) is not in a workspace this session can run in. The agent isn't in a workspace the session's owner works in. Create the agent with metadata.workspace_id set to a workspace the owner works in, or pick an agent that is in one.
403permission_errorThe key lacks tasks:create, or isn't allowed to run this agent. An unknown agent ID returns the same 403. Check the agent ID and the key's capabilities.
403permission_errorA personal key names a member other than its owner. Use a service account key to create sessions for other members, or omit the header.
403permission_errorThe named owner can't run this agent. Pick an agent the member can run, or name another member.
404not_found_errorenvironment_id isn't env_default. Check the ID with List environments.
404not_found_errorA file_id isn't a file this key can read. Check the ID with List files.

Create a session › Headers

x-context-owner-user-id
​string

The ID of the member who owns the session. A service account key can name any active member of its organization. The member owns the session, sees it in the Context app, and must be able to run the agent. A service account key reads and writes only the sessions it created, including those it created for other members. A personal key can name only its own owner. Send this header or x-context-owner-user-email, not both. Without either, the key's owner owns the session. Only this endpoint takes the owner headers.

The ID of the member who owns the session. A service account key can name any active member of its organization. The member owns the session, sees it in the Context app, and must be able to run the agent. A service account key reads and writes only the sessions it created, including those it created for other members. A personal key can name only its own owner. Send this header or x-context-owner-user-email, not both. Without either, the key's owner owns the session. Only this endpoint takes the owner headers.

x-context-owner-user-email
​string

The email of the member who owns the session. The same rules apply as for x-context-owner-user-id. Send this header or x-context-owner-user-id, not both.

The email of the member who owns the session. The same rules apply as for x-context-owner-user-id. Send this header or x-context-owner-user-id, not both.

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.

Create a session › Request Body

​required

An agent ID from List agents. The object form is also accepted. Each agent has one version, so version must be 1 or left out. Any other field in the object returns 400. An unknown agent ID returns 403, not 404.

environment_id
​string · minLength: 1 · required

The environment to run the session in: env_default. Any other ID returns 404. See Environments.

working_directory
​string

Leave it out. With env_default, any value returns 400.

​object[] · maxItems: 1

The events to start the session with. The array can hold at most one event, and it must be a user.message. See Send events. The response can return before the first turn starts. Before you send another message, wait for session.status_running on the event stream.

​object

Not supported. Omit it or send {}. Any other value returns 400.

​object[]

The files to give the agent. Each is a {type: "file", file_id, mount_path} object, with a file_id from Upload a file. Up to 50 files. A request with more than 50 files returns 500 instead of a named 400, which is a known defect.

title
​string | null

The session's title. The maximum length is 280 characters. Default: The first 80 characters of the first message, or API session.

vault_ids
​string[]

Not supported. Omit it or send []. Any other value returns 400.

budget
​null

Not supported. Omit it or send null. Any other value returns 400.

max_step_minutes
​integer · min: 1

A Context extension. The longest one step may run, in minutes. A step is everything the agent does to answer one message. When a step runs past it, the step is stopped and the session goes back to idle, so you can send another message. The maximum is your deployment's limit, which is 720 (12 hours) unless your administrator changed it. A larger value returns 400 with the maximum in the message. It is never lowered for you. The value is set when the session is created and applies to every step. The session object returns it. Default: 240, or your deployment's maximum if that is lower.

Create a session › Responses

Returns 200 with the session object. For every field, see Sessions.

id
​string · required
​object · required
archived_at
​string | null · date-time · required
budget
​null · required
created_at
​string · date-time · required
environment_id
​string · required
max_step_minutes
​integer | null · min: 1 · required
metadata
​object · required
​array · maxItems: 0 · required
​object[] · required
stats
​object · required
status
​string · enum · required
Enum values:
running
idle
terminated
title
​string | null · required
type
​string · enum · required
Enum values:
session
updated_at
​string · date-time · required
​object · required
​array · maxItems: 0 · required

Get a session

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

Returns a session with its status and token totals.

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

Response

Returns 200 with the session object. For every field, see Sessions.

Errors

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

Statuserror.typeCause and fix
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID and the key you are using.
404not_found_errorThe ID is a task that isn't a session, such as one started in the app (see Sessions). Read it with the Task API, GET /api/v1/tasks/roots/{taskId}.
503api_errorThe session's history is still being indexed. Retry the request shortly.

Get a session › path Parameters

session_id
​string · required

The ID of the session to retrieve.

The ID of the session to retrieve.

Get a session › 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 session › Responses

Returns 200 with the session object. For every field, see Sessions.

id
​string · required
​object · required
archived_at
​string | null · date-time · required
budget
​null · required
created_at
​string · date-time · required
environment_id
​string · required
max_step_minutes
​integer | null · min: 1 · required
metadata
​object · required
​array · maxItems: 0 · required
​object[] · required
stats
​object · required
status
​string · enum · required
Enum values:
running
idle
terminated
title
​string | null · required
type
​string · enum · required
Enum values:
session
updated_at
​string · date-time · required
​object · required
​array · maxItems: 0 · required

Rename a session

POST
https://api.context.ai
/v1/sessions/{session_id}
x-api-key (header)

Changes a session's title and returns the updated session.

Only the title can change. Sending agent, vault_ids, budget or a non-empty metadata returns 400. An empty body, or metadata: {}, returns 200 and changes nothing.

The key must have the tasks:create capability. For what each capability allows, see Keys.

Response

Returns 200 with the session object. For every field, see Sessions.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorThe title is empty, contains only whitespace or is longer than 280 characters. Send a title of 1 to 280 characters, or null to clear it.
400invalid_request_errorThe body includes agent, vault_ids, budget or a non-empty metadata. Send only title.
403permission_errorThe key does not act for the session's owner, or the owner is no longer an active member. Use the owner's personal key or the service account key that created the session.
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID.

Rename a session › path Parameters

session_id
​string · required

The ID of the session to rename.

The ID of the session to rename.

Rename a session › 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.

Rename a session › Request Body

title
​string | null · minLength: 1 · maxLength: 280

The new title. Must be between 1 and 280 characters after trimming (Anthropic: 500). Send null to clear the title.

​object

Not supported. Omit it or send {}. Any other value returns 400.

​

Not supported. Any value returns 400.

vault_ids
​string[]

Not supported. Any value returns 400.

Rename a session › Responses

Returns 200 with the session object. For every field, see Sessions.

id
​string · required
​object · required
archived_at
​string | null · date-time · required
budget
​null · required
created_at
​string · date-time · required
environment_id
​string · required
max_step_minutes
​integer | null · min: 1 · required
metadata
​object · required
​array · maxItems: 0 · required
​object[] · required
stats
​object · required
status
​string · enum · required
Enum values:
running
idle
terminated
title
​string | null · required
type
​string · enum · required
Enum values:
session
updated_at
​string · date-time · required
​object · required
​array · maxItems: 0 · required

Delete a session

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

Permanently deletes a session and its data.

Deleting removes the session's task in the Context app and the tasks of its subagents, with their events and transcripts. It also removes the session's inputs/ copies and outputs, its sandbox and saved workspace, its LLM traces, and the memories its runs saved. The session no longer appears in the task history in the Context app, and any open stream on the session ends. Response lists what stays.

Delete a session with the owner's personal key or with the service account key that created it. Keys don't have sessions:delete by default. The key's owner must grant it when creating the key, and an existing key can't gain it.

Nothing deletes a session for you. Your deployment keeps a session and its history until you delete it with this request, and archiving a session keeps its history too.

If a turn is running, the request returns 409 and the turn keeps running. Send a user.interrupt, wait for the session to go idle, then delete it. A session waiting for a tool approval counts as idle. If another change to the session is in progress, for example an event you sent, the delete can return 409. The session still exists, but its traces, saved workspace and recordings may already be deleted. Retry the delete. Files you uploaded with Upload a file are kept. Delete them with Delete a file.

The key must have the sessions:delete capability. For what each capability allows, see Keys.

Response

Returns 200 with a receipt whose type is session_deleted.

removed counts what was deleted:

FieldWhat it counts
tasksThe session's task and its subagents' tasks.
runsThe runs of those tasks, with their events, transcripts and state.
sandboxesThe sandboxes the runs still held, now shut down.
dispatch_rows_scrubbedDispatch history rows whose prompt, title and output text were cleared.
approval_previews_purgedApproval cards whose preview of the action's content was cleared.
billing_events_unlinkedBilling usage rows whose link to the session's runs was cleared.
agent_memories_deletedMemories the session's runs saved.
tracesdeleted, or no_trace_store when your deployment keeps no traces.

kept lists each store that stays, with a store and a reason:

storeWhat stays
billing_meter_eventsBilling usage and each run's billed cost, kept for invoicing. They hold counts and prices, not conversation content.
audit_logAudit records of who did what, when, and with what outcome.
dispatch_ledger_rowsDispatch history, with its prompt, title and output text cleared and its task link removed.
uploaded_filesFiles uploaded with Upload a file. The session's own copy in its inputs/ folder is deleted.
agent_memory_notesNotes in the agent's own .memory folder in Drive. They belong to the agent and aren't linked to any run. Memories the session's runs saved are deleted.
storage_residueDeleted data that storage keeps for a while: trace rows until the trace store's next merge, and earlier versions of removed files on storage that keeps versions, until they expire. No API returns them.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorThe request sends a query parameter. Remove it.
403permission_errorThe key lacks sessions:delete. Create a key that has sessions:delete. Only the key's owner can grant it.
403permission_errorThe key doesn't act for the session's owner. Use the owner's personal key or the service account key that created the session.
403permission_errorThe session's owner doesn't have permission to delete it in the Context app, or is no longer an active member. No key can delete the session in that case.
404not_found_errorNo session with this ID exists, it is already deleted, or this key can't read it. Check the session ID.
409invalid_request_errorA turn is running. Send a user.interrupt, wait until the session is idle, then delete it.
409invalid_request_errorAnother change to the session was in progress. The session still exists, but its traces, saved workspace and recordings may already be deleted. Retry the delete.
500api_errorThe session's traces couldn't be removed, so the session wasn't deleted. Retry the delete.

Delete a session › path Parameters

session_id
​string · required

The ID of the session to delete.

The ID of the session to delete.

Delete a session › 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 session › Responses

Returns 200 with a receipt whose type is session_deleted.

id
​string · required
type
​string · enum · required
Enum values:
session_deleted
​object · required
​object[] · required

Archive a session

POST
https://api.context.ai
/v1/sessions/{session_id}/archive
x-api-key (header)

Ends a session permanently. Its history stays readable.

The status becomes terminated. After that, sending an event to the session returns 400, and an open stream ends with an invalid_request_error frame. Archiving an archived session returns it unchanged. To remove a session's data permanently, delete it instead. To list archived sessions, call List sessions with include_archived=true.

You can archive a running session. Its current turn is not cut short, and the run stops once the turn is over. To stop the turn at once, send a user.interrupt before you archive.

The key must have the tasks:create capability. For what each capability allows, see Keys.

Response

Returns 200 with the session object. For every field, see Sessions.

Errors

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

Statuserror.typeCause and fix
403permission_errorThe key does not act for the session's owner, or the owner is no longer an active member. Use the owner's personal key or the service account key that created the session.
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID.

Archive a session › path Parameters

session_id
​string · required

The ID of the session to archive.

The ID of the session to archive.

Archive a session › 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.

Archive a session › Responses

Returns 200 with the session object. For every field, see Sessions.

id
​string · required
​object · required
archived_at
​string | null · date-time · required
budget
​null · required
created_at
​string · date-time · required
environment_id
​string · required
max_step_minutes
​integer | null · min: 1 · required
metadata
​object · required
​array · maxItems: 0 · required
​object[] · required
stats
​object · required
status
​string · enum · required
Enum values:
running
idle
terminated
title
​string | null · required
type
​string · enum · required
Enum values:
session
updated_at
​string · date-time · required
​object · required
​array · maxItems: 0 · required