Context Agent API
Context Agent API
Run Context agents from your own code: start a session, follow it live, approve its tool calls and read the result.
Your deployment is the Context instance your organization signs in to. The base URL is its host plus /v1, for example https://api.context.ai/v1. Request and response bodies are JSON, except for file upload (multipart/form-data), file download (raw bytes) and the event stream (server-sent events).
Tags
Agents
An agent is the configured worker that a session runs. You can create and edit agents in the Context app or with this API, which follows Anthropic's Managed Agents API with the differences listed at the end of this page. An agent you create with the API appears in the Context app, and the owner of the API key owns it.
Each built-in tool maps to its approval setting in the app.
Note: To create or update an agent, you must use a personal key with the agents:write capability.
The agent object
| Field | Type | Description |
|---|---|---|
id | string | The agent's ID. Pass it as agent when you create a session. |
type | string | Always agent. |
name | string | The agent's name, as shown in the app. |
description | string | null | The agent's purpose. null when the agent has no description. |
model | object | The model the agent is set to, as an object with one field, id. The ID is default when the agent leaves the choice to your deployment, so this field does not name a model in that case. GET /v1/models lists the IDs you can set. |
effective_model | object | null | The model a session of this agent would start on now, as an object with one field, id. Read-only. This is what to show a person who asks which model an agent runs on. null when a session would be refused a model. |
system | string | null | The agent's instructions. They are returned only to a personal key with agents:write whose owner created the agent and still owns it. Any other key gets null. If the agent has no instructions, that key gets "". |
tools | array | The agent's built-in tools, as one agent_toolset_20260401 entry that lists all eight tools with their enabled and permission_policy. The list is empty when every built-in tool is off. |
skills | array | The agent's skills, each {type, skill_id, version}. A built-in skill has type anthropic and its slug as skill_id. A custom skill has type custom and its skill ID. version is always latest. |
created_at | string | When the agent was created, as an RFC 3339 timestamp. |
updated_at | string | When the agent was last changed, as an RFC 3339 timestamp. |
always_allow is Allow, always_ask is Ask
(each call waits for a person to approve it), and enabled: false is Deny. edit and write share one
setting in the app, so they always read the same. web_search is always off, because agents search the web with
your deployment's own search tool. A tool that is off reads always_ask.
model and effective_model answer two different questions, and both are needed. model is the stored choice,
which a write round-trips; effective_model is the resolution, which no write accepts. They differ whenever model
does not name the model that will run: an agent set to default, and an agent whose stored model your deployment no
longer serves.
effective_model is resolved the way a session resolves it, by taking the first of these your deployment can serve:
- the agent's own model, when it is still in the catalog;
- a model you connected through your own subscription, if you have one;
- your deployment's default model.
effective_model.id is usually one of the IDs
GET /v1/models lists but need not be — that list is your
deployment's and leaves out models reached through a person's own connected account. And it is the answer for a
session created through this API, which runs in your deployment's cloud; a session on a paired computer chooses from
that computer's own models.
null means a session would be refused a model rather than "no model configured": either the catalog serves nothing,
or the deployment's configured default is not in it.
Note:Some fields always hold the same value:effective_modelcannot be sent on a create or update. Posting a whole agent object back is refused with400naming it, along with the other read-only fields — so a client that round-trips an agent can never turn one that was following your deployment's default into a pinned one by accident.
version is 1, mcp_servers is empty, metadata is {} (the workspace_id sent on create is not stored), multiagent and archived_at are null, and execution_identity is {type: "service_account"}.
Example
Code
Differences from Anthropic's API
This API follows Anthropic's Managed Agents API, with these differences:- The agent version and archive endpoints return
404. Every agent has one version,1, and an update changes it in place, so a later update overwrites an earlier one without an error. In an update,versionmust be1. - The
modelobject has only anidfield.effort,inference_geoandspeedreturn400. systemisnullunless the key is a personal key withagents:writewhose owner created the agent and still owns it.toolstakes the built-in toolset and custom tools; a custom tool is answered by your client or by a paired computer that advertises it, whichever is first. MCP servers, theautopermission policy and the domain and location options of the web tools return400.web_searchis always off. To give an agent MCP servers or connected accounts, set them up in the Context app.- Skills take
latestas their only version. multiagentand anyexecution_identityother than{type: "service_account"}return400.- To create an agent in a workspace, send
metadata.workspace_idor theanthropic-workspace-idheader. If you send both, they must name the same workspace, or the request returns400.
Environments
An environment is where a session runs. You choose one rather than create one. The one environment is
Some fields always hold the same value:
env_default, which runs each session in the cloud, wherever the platform places it. Nothing about it can be configured over this API. Remote sandbox support is on the roadmap.
Pass env_default as environment_id when you create a session.
Anthropic compatibility
Anthropic's SDKs also haveenvironments.create, update, delete and archive. Code written for Anthropic's
API often creates an environment before its first session. This API handles those calls as follows:
POST /v1/environments(environments.create) creates nothing, so it has no page of its own here; the API reference the server serves lists it as Create an environment. It exists so that Anthropic SDK code runs unchanged. The key must havetasks:create. With noconfig, or acloudconfig with unrestricted networking and no packages, it returns200withenv_default. It ignoresname,descriptionandmetadata. Any otherconfigreturns400 invalid_request_error, as does any field this API doesn't accept, such asscope.- Updating, deleting or archiving an environment returns
404 not_found_error, because this API does not serve those paths.
env_default. Remote sandbox support is on the roadmap.
Network access
Every environment reportsnetworking.type as unrestricted, which is the only value the API accepts.
unrestricted means the session's sandbox can reach the public internet, unless your deployment restricts it (see
the note below). Model calls are separate. Context handles them, and the sandbox's network access doesn't govern them. Nothing you set
through the API changes network access.
Note: Self-hosted (KOTS) deployments can restrict sandbox outbound traffic to a list of allowed domains. It's a setting in the KOTS Admin Console, not in the API. Your administrator turns on Sandbox Egress Proxy (domain allowlist) and lists the domains in Sandbox Egress Proxy Allowlist, or turns off Sandbox Internet Access. With Sandbox Workload Identity on, the same choice is Sandbox Egress Posture, set to Open internet, Domain allowlist or Workspace only. The API'sA create withnetworkinglabel doesn't reflect this setting, so environments reportunrestrictedeven when the install is tighter. To set it up, ask your Context contact.
limited networking, packages or any other custom config returns 400:
Code
limited networking is on the Roadmap.
The environment object
| Field | Type | Description |
|---|---|---|
id | string | Always env_default. |
type | string | Always environment. |
name | string | Always default. |
description | string | A one-line description. |
config | object | An object whose type is cloud. It also holds networking, always unrestricted, and packages, always empty. |
created_at | string | When the environment was created, as an RFC 3339 timestamp. |
updated_at | string | When the environment last changed, as an RFC 3339 timestamp. |
metadata is {} and archived_at is null. Treat the following values on env_default as placeholders, because they don't describe the real environment. Its description is a fixed string. Its config always reports networking: unrestricted and empty packages. If a self-hosted install restricts sandbox network access in the KOTS Admin Console, config doesn't show that yet.
Example
Code
Sessions
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
status | Meaning |
|---|---|
idle | The session is waiting for a message or a tool approval, or hasn't started. |
running | A turn is in progress. |
terminated | The session is archived. Nothing else terminates a session. |
rescheduling | This status is never returned. List sessions accepts it as a statuses filter, which then matches nothing. |
The session object
| Field | Type | Description |
|---|---|---|
id | string | The session's ID, a UUID. It is also the task's ID in the app. |
type | string | Always session. |
status | string | The session's status. One of idle, running or terminated. See Status. |
title | string | null | The session's title. The maximum length is 280 characters. |
agent | object | The agent the session runs, as in Agents without its timestamps and metadata. |
environment_id | string | Where the session runs: env_default. See Environments. |
max_step_minutes | integer | null | A 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. |
resources | array<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. |
usage | object | The totals for the whole session, subagents included: input_tokens, output_tokens, cache_read_input_tokens, cache_creation, active_seconds and list_cost. |
usage.cache_creation | object | Cache-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_seconds | number | The 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_cost | object | null | The 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_at | string | When the session was created, as an RFC 3339 timestamp. |
updated_at | string | When the session last changed, as an RFC 3339 timestamp. |
archived_at | string | null | For 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
nullwhile 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.
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
Code
Differences from Anthropic's API
This API follows Anthropic's Managed Agents API, with these differences:- Deleting a session needs the
sessions:deletecapability, which keys don't have by default. Deleting a session while a turn runs returns409: interrupt the turn, wait foridle, then delete it. The delete response lists what was removed and what was kept. See Delete a session. POST /v1/sessionstakesx-context-owner-user-idorx-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/sessionsreturns400if the request overrides an agent field (any field in theagentobject besidestype,idandversion), or sends a non-emptymetadata, a non-emptyvault_idsor a non-nullbudget.initial_eventstakes at most one event, auser.message. Anthropic's API takes up to 50 events of different types.- Only
fileresources are supported. Any other type returns400. - A file sent without
mount_pathisn't placed on the agent's disk. Anthropic's API copies it to/mnt/session/uploads/<file_id>. Here it stays in the session'sinputs/folder in Drive, where the agent reads it, and itsmount_pathreadsinputs/<filename>. mount_pathtakes a path under/workspace/or/mnt/session/uploads/. Any other absolute path is placed under/mnt/session/uploads:/data/a.csvbecomes/mnt/session/uploads/data/a.csv, andmount_pathreports the new path.usage.server_tool_useisn't sent.titletakes 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=ascand theagent_version,deployment_idandmemory_store_idfilters return400.
Events
Everything that happens in a session is an event: your messages, the agent's replies and tool calls, and status changes. You send events to steer the session and read them from the history or a live stream. The events follow Anthropic's Managed Agents API, with the differences listed at the end of this page.
Each type adds its own fields, listed in Event types.
IDs sort in the order the events happened. Compare them by their numbers, not as strings:
The event object
| Field | Type | Description |
|---|---|---|
id | string | The event's ID, in the form sevt_<seq>_<index>. |
type | string | One of the types below. |
processed_at | string | null | When the event was processed, as an RFC 3339 timestamp. It is null only on send receipts. |
sevt_10_0 comes after
sevt_9_0. To resume after an event, pass its ID as page on List events
or as the Last-Event-ID header on the stream.
When you send an event, the response holds a send receipt: an event object with an ID of the form
sevt_receipt_<uuid> and a null processed_at. The receipt's ID is not the ID of the stored event. The stored
event, with its real ID, then appears on the stream and in the history.
Example
Code
Event types
Types are named<source>.<action>. The session uses the 13 types below. More types might be added, so skip any type you do not recognize.
Events you send
| Type | Fields | Description |
|---|---|---|
user.message | content: text blocks | Starts a turn. If a turn is already running, the message joins it, and one session.status_idle ends the combined turn. The first user.message also starts the session. |
user.tool_confirmation | tool_use_id, result (allow or deny), deny_message | Answers a tool call that waits for approval. allow approves that one call, and deny refuses it. The stored event carries deny_message only for a deny. |
user.custom_tool_result | custom_tool_use_id, content: text blocks, is_error | Answers an agent.custom_tool_use. The first answer counts, yours or that of the paired computer that serves the tool; a later answer is accepted and changes nothing. The session shows the answer that counted as a user.custom_tool_result, whoever sent it. |
user.interrupt | none | Stops the current turn. The session emits session.status_idle with end_turn. |
Events the session emits
| Type | Fields | Description |
|---|---|---|
agent.thinking | none | The agent reasoned before replying. The event has no content and arrives with the reply, so it isn't a live indicator. |
agent.message | content: text blocks | The agent replied. |
agent.tool_use | name, input | The agent called a tool. |
agent.custom_tool_use | name, input | The agent called one of its custom tools. A session.status_idle with requires_action naming it follows, until its user.custom_tool_result arrives: from you, or from your paired computer whose servers advertise a tool of exactly that name, whichever answers first. The call waits up to 12 minutes. |
agent.tool_result | tool_use_id, content, is_error | A tool returned its result. |
session.status_running | none | A turn started. |
session.status_idle | stop_reason, stop_details | A turn ended. stop_reason.type is end_turn, requires_action (with event_ids, the agent.tool_use IDs waiting for your approval) or retries_exhausted. stop_details is always null. |
session.error | error.type, error.message, error.retry_status | A step of the turn failed. error.type is one of the types in Session errors. With retry_status.type: "retrying", the session retries and stays running. With "exhausted", the turn failed, and a session.status_idle with retries_exhausted follows. |
session.usage | usage: input_tokens, output_tokens, cache_read_input_tokens, cache_creation, active_seconds | Reports the session's running totals, subagents included. The session sends it after each model call and before every session.status_idle. This event doesn't include cost. To read cost, retrieve the session and read its usage.list_cost. |
Warning: WhenSubagents that the agent starts do not emit events of their own. The one exception is a subagent tool call waiting for approval, which shows up asstop_reason.typeisrequires_action, answer every ID inevent_ids. The session doesn't send a newsession.status_idlefor the IDs you haven't answered. It runs again only after you answer the last one.
agent.tool_use and a session.status_idle with requires_action.
Session errors
error.type | Cause |
|---|---|
model_rate_limited_error | The model provider's rate limit, or your own usage limit, was reached. |
model_overloaded_error | The model provider is unavailable or overloaded. |
model_request_failed_error | The model call failed for another reason, for example a timeout, a network failure, a refused request or a context window overflow. |
billing_error | Credits, a spend limit or a budget ran out, or the agent has no billing seat in its workspace. |
unknown_error | Any other failure, including a step the platform retries on its own without a known cause. |
retry_status.type is retrying or exhausted. Any error.type can come with retrying: the platform retries on its own and the turn continues. With exhausted, the turn failed. Send a new user.message to start the next turn.
Differences from Anthropic's API
This API follows Anthropic's Managed Agents API, with these differences:- Event deltas and session threads are not supported.
- Sending
user.tool_result,user.define_outcomeorsystem.messagereturns400. - A custom tool can also be answered by a computer you paired with the Context app, and a call nobody answers ends after 12 minutes with an error result.
- Send receipts have their own ID form. See The event object.
- The stream accepts a
Last-Event-IDheader to resume after an event. Anthropic's API does not. retry_status.typeis neverterminal, and MCP, credential and repository error types are not sent.
Files
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
Example
/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
| Field | Type | Description |
|---|---|---|
id | string | The 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. |
type | string | Always file. |
filename | string | The 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_type | string | The media type sent with the upload, or application/octet-stream if none was sent. |
size_bytes | integer | The size in bytes, or 0 if the size wasn't recorded. |
created_at | string | When the file was uploaded or written, as an RFC 3339 timestamp. |
downloadable | boolean | Always true. |
scope | object | The session that produced the file, as {type: "session", id}, where id is the session's ID. Uploaded files have no scope field. |
Code
Differences from Anthropic's API
This API follows Anthropic's Managed Agents API, with these differences:- Upload accepts
expires_in_secondsfrom 3600 to 7776000, but doesn't apply it. Files don't expire, and the file object has noexpires_at. - List files doesn't support
ids. Sending it returns400. - 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_idandbefore_id, and returnshas_more,first_idandlast_id, which Anthropic's list response doesn't include. - Deleting a file that a session still uses returns
400. See Delete a file.
Skills
A skill is a folder of instructions and files that an agent loads when a task needs it. Its
A skill version describes one saved state of the skill's files:
Example
SKILL.md file names the skill and says when to use it. With this API you can upload a skill, list the skills your key can read and download any version.
A skill you create belongs to the key's owner and is private to them until they share it in the Context app.
Creating, versioning and deleting skills needs a personal key with skills:write, which the key's owner must
grant. A built-in skill (source.type is anthropic) is read-only.
What an upload contains
Send the skill's files asmultipart/form-data. Either send each file as a files[] part whose filename is its
path in the skill, or send one zip archive of the files.
SKILL.mdsits at the root of the upload, or at the root of its one top-level folder. That folder's name is dropped from every path.SKILL.mdis UTF-8 text with YAML front matter.namecan be at most 64 characters of lowercase letters, digits and hyphens. IfSKILL.mdhas noname, the skill takes the top-level folder's name, and an upload with neither returns400.descriptionis required and can be at most 1,024 characters, with no XML tags.- The files total at most 30 MiB (31,457,280 bytes) uncompressed. A single file has no limit of its own. The request itself can be up to 32 MiB.
- Paths are relative. A path returns
400if it starts with/, contains a backslash or has an empty,.or..segment. Sending the same path twice also returns400. A zip's__MACOSX/and.DS_Storeentries are skipped.
SKILL.md name, and every version of a skill keeps that name. You can't own two skills with
the same name. Creating a skill whose name you already use returns 409 with the existing skill's ID, so you can
upload a new version of it instead.
A skill keeps its latest 500 versions, not counting versions given a name in the Context app. Saving more deletes
the oldest unnamed versions.
The skill object
| Field | Type | Description |
|---|---|---|
id | string | The skill's ID. A built-in skill's ID is its slug, such as pptx. |
type | string | Always skill. |
display_name | string | The skill's name, the same as the name in its SKILL.md. |
source | object | Who made the skill. source.type is custom for a skill a user uploaded, or anthropic for one of your deployment's built-in skills. |
latest_version_id | string | The ID of the skill's newest version. An agent always runs a skill's newest version. |
created_at | string | When the skill was created, as an RFC 3339 timestamp. |
updated_at | string | When the skill last changed, as an RFC 3339 timestamp. |
| Field | Type | Description |
|---|---|---|
id | string | The version's ID. |
type | string | Always skill_version. |
skill_id | string | The ID of the skill the version belongs to. |
name | string | The name in SKILL.md. It is the same for every version of a skill. |
description | string | The description in SKILL.md at this version. |
created_at | string | When the version was saved, as an RFC 3339 timestamp. |
Code
Differences from Anthropic's API
This API follows Anthropic's Managed Agents API, with these differences:- A skill is personal to the key's owner and belongs to no workspace. If a request sends the
anthropic-workspace-idheader, Context checks that the key's owner works in that workspace, then ignores it. If the owner doesn't work there, the request returns404. display_namemust equal thenameinSKILL.md, or be left out. A different value returns400.- Deleting a skill version returns
400. Upload a new version, or delete the whole skill. - The built-in skills are this deployment's own, listed by slug (
pptx,xlsx,docxand others). The list has nopdfskill. - A list response holds at most 200 skills or 100 versions per page. Anthropic's API allows up to 1,000.
- Uploads are limited to 32 MiB per request and 2 in progress per key.
Security Schemes
ManagedAgentsKey
Authenticate with a task API key in the
x-api-key header. Authorization: Bearer <key> also works. anthropic-version and anthropic-beta are accepted and ignored.apiKey