Skip to content
Context docs
Build

Agent API

The Agent API runs your organization’s Context agents from your own code. Each session you start shows up as a task in the app, along with its transcript. The request and response shapes follow Anthropic’s Managed Agents API, so Anthropic’s Python, TypeScript and .NET SDKs can call it (see SDKs). If you are porting code written for Anthropic, read Coming from Anthropic’s API first.

Core concepts

ConceptWhat it is
AgentThe worker a session runs. Build agents in the Context app or create them with this API.
EnvironmentThe place a session runs: env_default, the platform’s cloud environment.
SessionA task you start over the API. Each message you send starts a turn.
EventsThe messages and approvals you send, and everything the session streams back.
FileA document you upload for a session to read, or a file a session produced.
SkillA folder of instructions and files that an agent loads when a task needs it.

How it works

  1. Pick an agent with List agents, or create one.
  2. Create a session for it in an environment, optionally with uploaded files.
  3. Open the event stream, then send a user.message.
  4. Approve or deny the tool calls the session waits on, until the turn ends. Then send another message, or archive the session.
  5. List the files the session produced, then download them.

Prerequisites

You need a task API key and an agent in your organization. Choose a key helps you pick between a personal key and a service account key, and Agent API capabilities lists what each key can call.

Where to start

Basics

Base URL and authentication

See Agent API base URL and authentication.

Keys

See API keys and Agent API capabilities.

Errors

See Agent API status codes.

Pagination

See Paging.

Limits

See Limits.

Network access

See Network access.

How long data is kept

Your deployment keeps sessions, their history, uploaded files and skills until you delete them. Nothing is deleted on a schedule, archiving a session deletes nothing, and a file’s expires_in_seconds isn’t applied. Delete data with Delete a session, Delete a file and Delete a skill. Each page says what the request deletes. What a delete leaves is storage residue: copies that no API returns and that the storage underneath removes on its own schedule. Deleted trace rows stay until the trace store’s next merge, and on storage that keeps versions, earlier versions of removed files stay until they expire. Data retention covers the rest of your organization’s data.

Streaming

See Agent API streams and Stream events.

Specification

The file openapi.json describes every endpoint that has a page here. Your deployment serves its own copy at GET /v1/openapi.json, with no key needed, and serves these pages at /docs, built from the same release as its server. GET /v1/docs sends you there. Your deployment’s file describes the release its server runs, so prefer it when your deployment runs a different release from the pages you are reading.