Skip to content
Context docs
Context Agent API

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.

The event object

FieldTypeDescription
idstringThe event's ID, in the form sevt_<seq>_<index>.
typestringOne of the types below.
processed_atstring | nullWhen the event was processed, as an RFC 3339 timestamp. It is null only on send receipts.

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: 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

JSONCode
{ "type": "agent.message", "id": "sevt_40_0", "processed_at": "2026-10-21T01:42:24.003Z", "content": [ { "type": "text", "text": "The output is `first`." } ] }

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

TypeFieldsDescription
user.messagecontent: text blocksStarts 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_confirmationtool_use_id, result (allow or deny), deny_messageAnswers 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_resultcustom_tool_use_id, content: text blocks, is_errorAnswers 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.interruptnoneStops the current turn. The session emits session.status_idle with end_turn.

Events the session emits

TypeFieldsDescription
agent.thinkingnoneThe agent reasoned before replying. The event has no content and arrives with the reply, so it isn't a live indicator.
agent.messagecontent: text blocksThe agent replied.
agent.tool_usename, inputThe agent called a tool.
agent.custom_tool_usename, inputThe 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_resulttool_use_id, content, is_errorA tool returned its result.
session.status_runningnoneA turn started.
session.status_idlestop_reason, stop_detailsA 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.errorerror.type, error.message, error.retry_statusA 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.usageusage: input_tokens, output_tokens, cache_read_input_tokens, cache_creation, active_secondsReports 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: When stop_reason.type is requires_action, answer every ID in event_ids. The session doesn't send a new session.status_idle for the IDs you haven't answered. It runs again only after you answer the last one.

Subagents 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 as agent.tool_use and a session.status_idle with requires_action.

Session errors

error.typeCause
model_rate_limited_errorThe model provider's rate limit, or your own usage limit, was reached.
model_overloaded_errorThe model provider is unavailable or overloaded.
model_request_failed_errorThe model call failed for another reason, for example a timeout, a network failure, a refused request or a context window overflow.
billing_errorCredits, a spend limit or a budget ran out, or the agent has no billing seat in its workspace.
unknown_errorAny 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_outcome or system.message returns 400.
  • 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-ID header to resume after an event. Anthropic's API does not.
  • retry_status.type is never terminal, and MCP, credential and repository error types are not sent.

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


List events

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

Returns a session's event history, oldest first by default.

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

Response

Returns 200 with a page of events in data, in the order order sets, and a next_page value to pass as page. next_page is null when no more events match.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorlimit is outside 1 to 1000. Send a value from 1 to 1000.
400invalid_request_errororder is not asc or desc. Send one of them, or omit it.
400invalid_request_errorpage is not an event ID this API issued. Send the next_page value from the previous response, unchanged.
400invalid_request_errorA created_at bound is not an RFC 3339 timestamp. Send a timestamp such as 2026-10-21T01:42:16Z.
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID.
503api_errorThe session's history is still being indexed. Retry the request shortly.

List events › path Parameters

session_id
​string · required

The ID of the session whose events to return.

The ID of the session whose events to return.

List events › query Parameters

limit
​integer · min: 1 · max: 1000

The maximum number of events to return on one page. Must be between 1 and 1000.

The maximum number of events to return on one page. Must be between 1 and 1000.

Default: 100
page
​string

The ID of the event to start from. To fetch the next page, pass the next_page value from the previous response. With asc, the page starts with the first event after this one. With desc, it starts with the first event before it. The event itself is not included.

The ID of the event to start from. To fetch the next page, pass the next_page value from the previous response. With asc, the page starts with the first event after this one. With desc, it starts with the first event before it. The event itself is not included.

created_at[gt]
​string · date-time

Only events whose processed_at is after this RFC 3339 timestamp.

Only events whose processed_at is after this RFC 3339 timestamp.

created_at[gte]
​string · date-time

Only events whose processed_at is at or after this RFC 3339 timestamp.

Only events whose processed_at is at or after this RFC 3339 timestamp.

created_at[lt]
​string · date-time

Only events whose processed_at is before this RFC 3339 timestamp.

Only events whose processed_at is before this RFC 3339 timestamp.

created_at[lte]
​string · date-time

Only events whose processed_at is at or before this RFC 3339 timestamp.

Only events whose processed_at is at or before this RFC 3339 timestamp.

order
​string · enum

The sort order. One of asc (oldest first) or desc (newest first).

The sort order. One of asc (oldest first) or desc (newest first).

Enum values:
asc
desc
Default: asc
types
​string[]

The event types to return. To pass more than one, repeat the parameter: types=agent.message&types=session.status_idle.

The event types to return. To pass more than one, repeat the parameter: types=agent.message&types=session.status_idle.

types[]
​string[]

The same filter as types, in the bracketed form the SDKs send: types[]=agent.message&types[]=session.status_idle.

The same filter as types, in the bracketed form the SDKs send: types[]=agent.message&types[]=session.status_idle.

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

Returns 200 with a page of events in data, in the order order sets, and a next_page value to pass as page. next_page is null when no more events match.

​array · required
next_page
​string | null · required

Send events

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

Sends a message, a tool approval or an interrupt to a session.

Sends are not idempotent. If a send times out or its result is unknown, read the session's events before you send it again.

The server checks every event against the session before any of them acts, then applies them in order. If an event is refused while they are applied, because the session changed in the meantime, the earlier events stay accepted and the error message says how many were. Don't resend those.

Each event gets a receipt with a sevt_receipt_ ID and processed_at: null. The stored event, with its real ID, then appears on the stream and in the history. The receipt ID is not the stored event's ID, so match the stored event on the stream rather than by ID.

Before a session starts, it accepts exactly one user.message per request. Send more only after the stream shows session.status_running. A user.message sent while a turn runs is added to that turn instead of starting a new one.

A user.tool_confirmation also needs the tasks:approve capability and a personal key.

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

Response

Returns 200 with a data array that holds one receipt for each event you sent.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorAn event is malformed, or its text is empty or over 100,000 characters in all. Fix the event the message names.
400invalid_request_errorThe session is archived. Archived sessions take no events. Create a new session.
400invalid_request_errorThe session has not started and the request holds more than one user.message, or the first turn is still starting. Send one message, then wait for session.status_running before you send the next.
400invalid_request_errorA tool_use_id is unknown, repeated or already answered. Send only IDs from the latest stop_reason.event_ids that you have not answered.
400invalid_request_errorAn event has a type this endpoint does not accept: user.tool_result, user.define_outcome or system.message. Send only user.message, user.tool_confirmation, user.custom_tool_result or user.interrupt.
400invalid_request_errorA user.custom_tool_result names a custom_tool_use_id this session never showed. Send the ID of its agent.custom_tool_use event.
400invalid_request_errorAn event carries session_thread_id. Sessions have one thread. Remove session_thread_id and retry.
400invalid_request_errorA user.tool_confirmation follows a user.interrupt in the same request. Send the confirmation before the interrupt, or in a separate request.
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.
403permission_errorA user.tool_confirmation was sent with a key that is not personal, or that lacks tasks:approve. Use a personal key with tasks:approve.
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID.
409invalid_request_errorThe session's state changed while the request was processed. The tool call was already answered, or the session is stopping or moving. Read the events, then decide whether to send again.
503api_errorThe session's history is still being indexed. Retry the request shortly.

Send events › path Parameters

session_id
​string · required

The ID of the session to send events to.

The ID of the session to send events to.

Send events › 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.

Send events › Request Body

​array · minItems: 1 · required

The events to send, applied in order.

Send events › Responses

Returns 200 with a data array that holds one receipt for each event you sent.

​array · required

Stream events

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

Streams a session's events as server-sent events while they happen.

Without Last-Event-ID, the stream sends only events that happen after it opens, so open it before you send a message.

Each key can hold up to 24 open streams across all its sessions, unless your deployment sets a different limit. The limit applies on each server instance, so a key whose streams land on more than one instance can hold more in total. A stream counts until your client disconnects.

This endpoint takes no query parameters. Anthropic's event_deltas parameter isn't supported, and sending it returns 400.

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

Response

Returns 200 with the content type text/event-stream. Each event is one frame, described in Frames. The : open line is a comment, sent once when the stream opens, and SSE clients ignore it.

Errors

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

Statuserror.typeCause and fix
400invalid_request_errorLast-Event-ID is not an event ID of this session. Send an ID from this session's events, or omit the header.
400invalid_request_errorThe request includes the event_deltas query parameter. Remove it.
404not_found_errorNo session with this ID exists, or this key can't read it. Check the session ID.
429rate_limit_errorThis key already holds the most open streams allowed on the server instance that answered, 24 by default. Close a stream you no longer read, then retry.

Frames

Each event is one frame with id, event and data, and the frame's id is the event ID. Events arrive whole, without deltas, and agent.message carries the full reply. Every 20 seconds the server sends a ping frame with no id.

Event order in a turn

Stop reading when a session.status_idle arrives whose stop_reason.type is anything other than requires_action. A session.status_idle with requires_action means the agent is waiting for you. A session.error with retry_status.type: "retrying" doesn't end the turn, so keep reading. A session.error with retry_status.type: "exhausted" is followed by a session.status_idle with retries_exhausted.

A turn in which the agent asks to run a tool looks like this:

  1. The stream shows user.message, then session.status_running.
  2. The stream shows agent.tool_use for the call, then session.status_idle with stop_reason.type: "requires_action" and the call's ID in event_ids.
  3. To answer, send a user.tool_confirmation event with Send events for each call. The stream shows it, then session.status_running once every waiting call is answered. Until you answer every ID in event_ids, the session keeps waiting and the stream sends no further status event.
  4. The stream shows agent.tool_result, then agent.thinking if the agent reasoned, then agent.message. A session.usage event follows each model call.
  5. The stream shows session.usage, then session.status_idle with stop_reason.type: "end_turn". The turn is over.

How a stream ends

The server doesn't close the stream when a turn ends. Close it yourself when you stop reading, because an open stream counts against the key's limit.

A stream can end with an event: error frame, without an id, whose data is an error body. The server sends nothing after it, so close the connection yourself.

error.typeWhyWhat to do
api_errorThe connection has carried 8 MiB.Reconnect with Last-Event-ID.
invalid_request_errorThe session was archived.Stop. The history stays readable.
authentication_errorThe key was revoked or expired, or its owner left the organization.Stop. To keep reading, open a new stream with a valid key.
permission_error, not_found_errorThe key lost access to the session.Stop. To keep reading, open a new stream with a key that can read the session.

A stream can also close with no frame, for example when the server restarts. The SDKs do not reconnect for you.

Reconnecting

To resume a stream without missing events, follow these steps:

  1. Keep the id of the last event you received.
  2. Reopen the stream with a Last-Event-ID header set to that ID. The server replays every event after it, then continues live.

If you have not received any event yet, send sevt_0_0 to replay the whole history. To read the history first, list it with List events and stream from the last listed ID. You can also open the stream first, then list the history and skip any event IDs the stream has already delivered.

Stream events › path Parameters

session_id
​string · required

The ID of the session to stream.

The ID of the session to stream.

Stream events › Headers

Last-Event-ID
​string

The ID of the last event you received from this session. The stream replays every event after it, then continues live. sevt_0_0 replays from the start. A send receipt's ID (sevt_receipt_<uuid>, returned when you send an event) returns 400.

The ID of the last event you received from this session. The stream replays every event after it, then continues live. sevt_0_0 replays from the start. A send receipt's ID (sevt_receipt_<uuid>, returned when you send an event) returns 400.

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.

Stream events › Responses

Returns 200 with the content type text/event-stream. Each event is one frame, described in Frames. The : open line is a comment, sent once when the stream opens, and SSE clients ignore it.

anyOf
At least one variant must match. Multiple variants may match simultaneously.

Decision Table

VariantMatching Criteria
No specific criteria
type = object · requires: type
type = object · requires: type, error, request_id
Properties for Variant 1:
anyOf
At least one variant must match. Multiple variants may match simultaneously.

Decision Table

VariantMatching Criteria
type = object · requires: id, processed_at, type +1 more
type = object · requires: id, processed_at, type
type = object · requires: id, processed_at, type +2 more
type = object · requires: id, processed_at, type +1 more
type = object · requires: id, processed_at, type
type = object · requires: id, processed_at, type +2 more
type = object · requires: id, processed_at, type +2 more
type = object · requires: id, processed_at, type +3 more
type = object · requires: id, processed_at, type +3 more
type = object · requires: id, processed_at, type
type = object · requires: id, processed_at, type +2 more
type = object · requires: id, processed_at, type +1 more
type = object · requires: id, processed_at, type +1 more
Properties for Variant 1:
id
​string · pattern: ^sevt_(0|[1-9][0-9]*… · required
processed_at
​string · date-time · required
type
​string · enum · required
Enum values:
user.message
​object[] · required