API keys
The Evals API, the Evals CLI and the Agent API all authenticate with a task API key, the app’s general-purpose API key. One key can call both APIs; its capabilities decide which endpoints it reaches. A key belongs to the person who created it and to their organization, and it can never do more than its owner can do in the app.
Where the APIs differ
| Evals API | Agent API | |
|---|---|---|
| Base URL | https://api.context.ai/api/v1/evals | https://api.context.ai/v1 |
| Header | Authorization: Bearer <key> or X-API-Key: <key> | x-api-key: <key> or Authorization: Bearer <key> |
| Capabilities | Evals API capabilities | Agent API capabilities |
Key types
| Type | Use it for | Who can create it | What it can read with the Agent API |
|---|---|---|---|
| Personal | Calling your own agents and reading evals from your own code. | Any member, for themselves. | Sessions you own and the agents you can run. |
| Service account | Automations, backends and CI. It can’t approve tool calls. | An organization administrator. | The agents in the organization and the sessions it created, including sessions it created for other members. |
Choose a key compares the two types in full.
A key stops working when its owner leaves the organization. The owner of a service account key is the administrator who created it, so automations that use a service account key stop when that administrator leaves.
Create a key
| Step | What to do |
|---|---|
| 1 | In the app, open Settings > API > Task keys and choose New key. |
| 2 | Name the key after where you use it, for example ci-nightly-evals. |
| 3 | Set Agent scope. Leave it at Any allowed agent for a key that reads Evals data. |
| 4 | Check the capabilities it needs. New keys start with most capabilities checked, including connectors:manage and workspaces:members:read, which only an organization administrator can grant. If you aren’t an administrator, clear both, or the key isn’t created. For a read-only Evals key, clear everything except Read evals. |
| 5 | Optionally set Expires. A key with no expiry works until it is revoked. |
| 6 | Choose Create key and copy the key. It is shown only once, and it starts with tsk_. |
You can’t add a capability to an existing key. To use a capability that is off by default, turn it on when you create the key, or create a new key.
Send the key
| API | Header |
|---|---|
| Evals API | Authorization: Bearer <task-api-key> or X-API-Key: <task-api-key> |
| Evals CLI | Reads the key from CONTEXT_API_KEY. |
| Agent API | x-api-key: <task-api-key> or Authorization: Bearer <task-api-key> |
Agent API base URL and authentication
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).
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.
The examples set CONTEXT_BASE_URL to your deployment’s host and CONTEXT_API_KEY to your key.
Code
Evals API capabilities
| Capability | Label in the app | What it allows |
|---|---|---|
evals:read | Read evals | Every HTTP GET, and every CLI command that only reads, except listing workflows (evals targets workflow, and --workflow on evals monitors list), which needs evals:write. |
evals:write | Change evals | Every HTTP request that changes data, and every CLI command that does: create, edit and delete datasets, tasks, criteria, evaluations and scorecards, and start and stop runs. |
A key for a dashboard or a report needs only evals:read. Give evals:write only to a key that builds or runs evaluations, such as a CI job. Only the key’s owner can grant evals:write, because the model calls its runs make are charged to them; an admin creating a key for someone else can’t include it.
If the owner loses Evals access, so does the key.
Agent API capabilities
| Capability | Endpoints | Default | Key types |
|---|---|---|---|
tasks:read | Every GET, including the event stream, except the file and skill endpoints. | On | Both |
tasks:create | Create, rename and archive sessions, and send events. | On | Both |
tasks:approve | Send user.tool_confirmation. | Off | Personal only |
agents:write | Create and update agents. | Off | Personal only |
sessions:delete | Delete sessions. A service account key deletes only the sessions it created. | Off | Both |
files:read | List, get and download files, including the files a session produced. | On | Both |
files:write | Upload and delete files. | On | Both |
skills:read | List, get and download skills and their versions. | On | Both |
skills:write | Create skills and their versions, and delete skills. | Off | Personal only |
Session ownership
| Key | Who owns the sessions it creates |
|---|---|
| Personal | The key’s owner. |
| Service account | The key’s owner, or any active member it names with the x-context-owner-user-id or x-context-owner-user-email header on Create a session. That member owns the session and sees it in the app. |
A session that a service account key starts on an agent with an Ask tool waits forever. In the app, each of an
agent’s tools has an approval setting, Ask or Allow. The session goes idle with
stop_reason.type: "requires_action" and stays there, because a service account key can’t approve tool calls. Set
those tools to Allow before you start sessions with a service account key.
Agent scope
| Agent scope | Evals API | Agent API |
|---|---|---|
| Any allowed agent | Reads Evals data the owner can read. | Reads the agents and sessions the key type allows. |
| One agent | Reads only traces, for that agent. | Reads only that agent and its sessions. |
Write access
| Request | Result |
|---|---|
| Rename, archive or delete a session, or send it events, with the owner’s personal key or the service account key that created it. | Allowed. |
| The same, with a key that can read the session but doesn’t act for its owner. | 403 |
| The same, with a key that can’t read the session. | 404 |
Keep it secret
| Practice | Why |
|---|---|
| Store the key in an environment variable or your secret manager, never in source code or a repository. | Anyone who has the key can act as its owner. |
| Use one key per system. | You can revoke one without breaking the others. |
| If a key leaks, revoke it at once. | Revoked keys get 401. |
Rotate a key
| Step | What to do |
|---|---|
| 1 | Create a new key with the same capabilities. |
| 2 | Deploy the new key to every system that uses the old one, and check that requests succeed. |
| 3 | Revoke the old key: open it in Settings > API > Task keys and choose Revoke key. |
The app has no rotate button; these steps keep the old key working until the new one is in place. After you revoke a key, requests with it get 401. For up to 60 seconds after you revoke it, a request that is also over the rate limit may get 429 rather than 401.
A key can’t read another organization’s data: the organization comes from the key, never from the request.