Skip to content
Context docs
Build

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 APIAgent API
Base URLhttps://api.context.ai/api/v1/evalshttps://api.context.ai/v1
HeaderAuthorization: Bearer <key> or X-API-Key: <key>x-api-key: <key> or Authorization: Bearer <key>
CapabilitiesEvals API capabilitiesAgent API capabilities

Key types

TypeUse it forWho can create itWhat it can read with the Agent API
PersonalCalling your own agents and reading evals from your own code.Any member, for themselves.Sessions you own and the agents you can run.
Service accountAutomations, 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

StepWhat to do
1In the app, open Settings > API > Task keys and choose New key.
2Name the key after where you use it, for example ci-nightly-evals.
3Set Agent scope. Leave it at Any allowed agent for a key that reads Evals data.
4Check 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.
5Optionally set Expires. A key with no expiry works until it is revoked.
6Choose 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

APIHeader
Evals APIAuthorization: Bearer <task-api-key> or X-API-Key: <task-api-key>
Evals CLIReads the key from CONTEXT_API_KEY.
Agent APIx-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.

TerminalCode
curl -sS "$CONTEXT_BASE_URL/v1/agents" -H "x-api-key: $CONTEXT_API_KEY"

Evals API capabilities

CapabilityLabel in the appWhat it allows
evals:readRead evalsEvery 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:writeChange evalsEvery 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

CapabilityEndpointsDefaultKey types
tasks:readEvery GET, including the event stream, except the file and skill endpoints.OnBoth
tasks:createCreate, rename and archive sessions, and send events.OnBoth
tasks:approveSend user.tool_confirmation.OffPersonal only
agents:writeCreate and update agents.OffPersonal only
sessions:deleteDelete sessions. A service account key deletes only the sessions it created.OffBoth
files:readList, get and download files, including the files a session produced.OnBoth
files:writeUpload and delete files.OnBoth
skills:readList, get and download skills and their versions.OnBoth
skills:writeCreate skills and their versions, and delete skills.OffPersonal only

Session ownership

KeyWho owns the sessions it creates
PersonalThe key’s owner.
Service accountThe 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 scopeEvals APIAgent API
Any allowed agentReads Evals data the owner can read.Reads the agents and sessions the key type allows.
One agentReads only traces, for that agent.Reads only that agent and its sessions.

Write access

RequestResult
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

PracticeWhy
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

StepWhat to do
1Create a new key with the same capabilities.
2Deploy the new key to every system that uses the old one, and check that requests succeed.
3Revoke 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.