Skip to content
Anlyon
Esc
↑↓navigate↵open⌘Jpreview
On this page

API keys and scopes

Create an API key for one environment, grant only the scopes its caller needs, require an end user on your app's key, and check a key at startup.

Your code authenticates to the Anlyon API with an API key. This page covers creating keys, scoping them and checking them.

Why it matters. The key your agent’s process holds decides what a prompt injection or a bug can reach. A key that can only invoke actions cannot raise its own limit, approve its own call, read a credential or switch to another environment. Getting the keys right is most of the work of keeping an agent contained, and it is a setting, not code you write.

Pick the keys you need

Most products need two or three keys per environment. Create each one in Settings → API Keys.

Key Who holds it Scopes Options
Operator key Your deploy script or CI actions:write, secrets:read, secrets:write, policies:write, impact-limits:write, as the setup needs None. Never give it to an agent.
App key Your product’s server, which acts for your users Standard preset plus end-users:write and end-users:approvals Require an end user on
Agent key A coding agent or an internal agent using your company’s own accounts actions:invoke, actions:read, approvals:read None
Read-only key Dashboards and exports Read only preset None

The quickstart creates the operator key and the app key and uses them end to end.

How a key decides what it can reach

The API endpoints in this documentation take an API key unless a page says otherwise. MCP clients sign in with OAuth, and the console uses a session. A key carries two things that decide what it can reach:

  • One environment. A key belongs to exactly one environment and resolves it on authentication. A staging key cannot read or write production data, because the environment is bound to the credential itself. This is logical isolation: rows in shared storage, filtered by an enforced column. It is not dedicated storage or compute. See Environments.
  • A set of scopes. Scopes decide which operations the key may perform, from actions:read to approvals:decide. See Scopes below.

Neither is something you remember to do correctly. A key that is missing a scope gets a 403 with the scope named, and a key pointed at the wrong environment simply does not find the data.

Recognize an API key

API keys follow this format:

anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
  • Prefix: every key starts with anlyon_live_. The prefix does not name an environment. A staging key carries it too.
  • Key: 32 random characters

Create an API key

Creating a key needs the admin role in the workspace.

Create a key in the console

Log in

Log in to your Anlyon account

Navigate to Settings

Navigate to Settings → API Keys

Create Key

Click Create API key and enter a descriptive name (for example “Support agent, staging”)

Choose the environment

Pick the environment this key belongs to. It cannot be changed later, and the key will never reach any other environment.

Choose the permissions

Standard is the default and is what an agent needs for ordinary work. Full access adds every privileged scope: secrets, approval decisions, budgets, policies, impact limits, halting the environment, changing an approval gate and resolving unknown outcomes. Grant it rarely. Read only is a good fit for observability. You can also pick individual scopes.

Require an end user (optional)

Turn on Require an end user for a key your product uses to act for its users. See Keys that act for your users.

Set an expiry (optional)

Optionally set an expiration date

Copy Key

Copy the key when it is shown. It is shown once.

Send the key with each request

Use the Authorization header

Include your API key in the Authorization header using the Bearer scheme:

curl -X POST https://api.anlyon.com/api/v2/actions/open-issue/invoke \
  -H "Authorization: Bearer anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \
  -H "Anlyon-End-User: alice" \
  -H "Content-Type: application/json" \
  -d '{ "input": { "title": "Hello from my agent", "body": "Opened by an agent, approved by its user." } }'

The example invokes the action the quickstart defines, for the end user alice. Leave out Anlyon-End-User for a call that uses your workspace’s own accounts. A key that requires an end user refuses that with 400 END_USER_REQUIRED.

Authenticate an MCP client

The hosted MCP server at https://api.anlyon.com/mcp takes either credential:

  • OAuth. Point the client at the URL and sign in with Anlyon in the browser. You choose the workspace, the environment and the permission groups on the consent screen. Nothing to paste.
  • An API key. Send Authorization: Bearer anlyon_live_.... With a key, Anlyon-End-User: <id> binds the connection to one of your users. An OAuth connection that sends that header is refused with END_USER_HEADER_NOT_ALLOWED.

See Claude Code, Cursor and Codex for the exact configuration.

Call the API with a key

const response = await fetch('https://api.anlyon.com/api/v2/actions/open-issue/invoke', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Anlyon-End-User': 'alice',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    input: { title: 'Hello from my agent', body: 'Opened by an agent, approved by its user.' },
  }),
});

const { data } = await response.json();
console.log(data.status, data.grade);
import requests

headers = {
    'Authorization': f'Bearer {api_key}',
    'Anlyon-End-User': 'alice',
    'Content-Type': 'application/json'
}

response = requests.post(
    'https://api.anlyon.com/api/v2/actions/open-issue/invoke',
    headers=headers,
    json={
        'input': {'title': 'Hello from my agent', 'body': 'Opened by an agent, approved by its user.'}
    }
)

data = response.json()['data']
print(data['status'], data.get('grade'))

Keep keys safe

Store Keys Securely

Never commit API keys to version control!

Use environment variables:

# .env file (add to .gitignore)
ANLYON_API_KEY=anlyon_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// In your code
const apiKey = process.env.ANLYON_API_KEY;
One Key per Environment

You do not have to remember this one. It is enforced. Every key belongs to exactly one environment, chosen when you create it. A key cannot reach another environment’s actions, secrets, invocations, approvals, events, agents, runs or spans, or any other data scoped to it.

So a staging key running against production credentials does not quietly write to production. It finds nothing there. Create one key per environment per service, and name them so the environment is obvious.

Rotate Keys Regularly
  • Set expiration dates on API keys
  • Rotate keys every 90 days
  • Revoke unused or compromised keys
Use Least Privilege
  • Give each key only the scopes it uses. An agent that never touches the vault should not hold secrets:read.
  • Keep secrets:*, approvals:decide, budgets:write, actions:govern, actions:resolve, policies:write and environments:halt on separate operator keys. The agent must not be able to rewrite the policy that governs it. None of them is agent work, and none is granted by default.
  • Create separate keys for different services, so revoking one does not stop the others.
  • Use descriptive names, and monitor key usage in the dashboard.

List, rotate and delete keys

These endpoints take a console session, not an API key. Most people use Settings → API Keys instead.

List a workspace’s keys

Get the keys of a workspace. Hashes and full keys are never returned:

curl https://api.anlyon.com/api/v2/workspaces/{workspaceId}/api-keys \
  -H "Cookie: better-auth.session_token=YOUR_SESSION_TOKEN"
data (array)
id (string)
API key ID
name (string)
Descriptive name
keyPrefix (string)
Key prefix (full key only shown once)
isActive (boolean)
Whether the key is active
createdAt (string)
Creation timestamp
expiresAt (string | null)
Expiration timestamp
lastUsedAt (string | null)
Last usage timestamp

Rotate a key

POST /api/v2/workspaces/{workspaceId}/api-keys/{keyId}/regenerate returns a new key once and keeps the previous one working for 24 hours, so you can deploy the new key without downtime. During those 24 hours, POST .../api-keys/{keyId}/rollback restores the previous version. Both need the admin role.

Delete an API key

Delete a key. It stops working at once and cannot be restored. Needs the admin role:

curl -X DELETE https://api.anlyon.com/api/v2/workspaces/{workspaceId}/api-keys/{keyId} \
  -H "Cookie: better-auth.session_token=YOUR_SESSION_TOKEN"

Choose scopes

A scope is a resource:action pair, and a key holds a fixed set of them. They are enforced on every request: a call the key has no scope for is refused with 403 and the missing scope named, whatever the key is otherwise allowed to do.

Scopes are chosen when the key is created and cannot be changed afterwards. To widen or narrow a key, create a new one and retire the old one. That is deliberate, so a key’s authority cannot drift after you have reviewed it.

Start from a preset

Preset What it holds Use it for
Standard Every current scope except the privileged ones below. That includes reading, defining and invoking actions, requesting approvals, runs, events and reading impact limits Agent keys. This is the default.
Read only Every current :read scope, including the privileged read scopes Dashboards, monitoring, exports
Full access Every current scope, including the privileged ones below, except integrations:read, integrations:write and messages:ingest Rare. Prefer a Standard key plus a separate operator key.

No console preset grants dlq:*, the dead-letter list’s scopes. A key created through the API with no scopes named receives every scope that is not privileged, those included.

Privileged scopes

These are not granted by default. None of them is a way to use Anlyon. Each one either reads credentials or changes what Anlyon will stop you doing.

An OAuth consent screen offers four of them as separate groups that are off unless you turn them on: approval decisions, notification channels, secrets and budgets. It does not offer actions:govern, actions:resolve, environments:halt, policies:read, policies:write, impact-limits:write, secret-stores:read, secret-stores:write, audit:read, the end-users:* scopes or the functions:* scopes.

Scope What it allows
secrets:read, secrets:write Manage vault secrets, and reference them from an action definition
approvals:decide Approve or deny pending approvals without a human clicking approve
budgets:read, budgets:write Read and change a key’s monthly caps on Anlyon operations. A budget does not cap model tokens or the money an action moves
integrations:read, integrations:write Connect and change Slack and Discord channels, which redirect the workspace’s alerts
notifications:manage Change the workspace’s notification settings: which channels and alert types are on, which email addresses and which webhook URL receive alerts. Also send a test webhook. A console session or an OAuth connection also needs the admin role. An ordinary credential must not be able to redirect an alert
actions:govern Change whether an action requires approval, and change or remove what a governed action declares
actions:resolve Record the confirmed outcome of an invocation whose outcome is unknown. The key that made the call cannot resolve it. See Receipts and grades
policies:read, policies:write Read, create, change, disable and delete the approval policies for the key’s own environment. See Policy as code
environments:halt Halt and resume the key’s own environment
messages:ingest Keep publishing messages while the environment is halted
impact-limits:write Create, change and archive the shared impact limits for the key’s own environment. An agent must not be able to raise the cap that bounds it
secret-stores:read, secret-stores:write Read, add, change, check and delete the environment’s secret stores: your own AWS Secrets Manager or Vault, and the credential Anlyon reads them with. A store’s credential reaches every secret its policy allows. Secrets that point into a store use secrets:*
audit:read Read the stored audit records of the key’s own environment and export them as JSON or CSV. See Audit records. The records name every key, decider and policy change
end-users:read List end users and their connections. See End-user scopes
end-users:write Make connect links and confirm them, store an end user’s key, delete a connection, erase an end user
end-users:approvals List and decide the approvals an end user decides in your app
functions:read, functions:write, functions:run Hosted functions: list functions and read their runs, publish versions, start runs. Starting a run also needs actions:invoke

Every scope

logs:read billing:read notifications:read feedback:write analytics:read events:read events:write secrets:read secrets:write actions:read actions:write actions:invoke approvals:read approvals:write approvals:decide budgets:read budgets:write runs:read runs:write actions:govern actions:resolve environments:halt policies:read policies:write impact-limits:read impact-limits:write notifications:write notifications:manage secret-stores:read secret-stores:write audit:read end-users:read end-users:write end-users:approvals functions:read functions:write functions:run

Scopes for notification channels, the dead-letter list and publishing during a halt, which no console preset grants:

integrations:read integrations:write dlq:read dlq:write messages:ingest

The scopes of the retired namespaces (messages, schedules, queues, workflows, flow control, URL groups, memory, files, cache, sessions and context) were removed with them, and existing keys no longer hold them. Creating a key with one, or with any other string that is not a scope, is refused with 400 INVALID_SCOPE, which names it. The same goes for OAuth: a sign-in or token request that asks for one of those scopes, or for the retired memory or files consent group (or any other scope Anlyon does not issue), is refused with 400 invalid_scope.

Give your app key the end-user scopes

For a product that acts for its users. See Workspace connections and end-user connections. All three are privileged: the server key your product uses needs them added, since neither the Standard preset nor a key created with no scopes named holds them.

Scope What it allows
end-users:read List end users and their connections
end-users:write Make connect links and confirm them, store an end user’s key, delete a connection, erase an end user
end-users:approvals List and decide the approvals an end user decides in your app

Invoking an action for an end user still needs actions:invoke, as any invocation does.

Check the key you were given

GET /api/v2/auth/identity (client.auth.identity() in both SDKs) returns only the caller’s own credential: type, key id (API keys only), workspace and environment, effective scopes and expiry. It needs no scope beyond being authenticated, is never cached, and returns no secret, hash or other key. Call it at startup to fail fast if the key is missing a scope you need, or holds one you should not. Holding a scope does not prove a call will run: policies, budgets, environment halt and quotas still apply at request time.

Keys that act for your users

When your product acts in its users’ own accounts, your server names the user on each call with the Anlyon-End-User header. The SDKs do this with anlyon.forUser(id) in TypeScript and client.for_user(id) in Python.

A key can require an end user. Turn it on when you create the key: Require an end user in the console, or "endUserRequired": true in the API. It cannot be changed later. Such a key:

  • refuses any action call without the header, with 400 END_USER_REQUIRED
  • never uses one of your workspace’s own connections, even when the user has not connected an account

It is off by default. Turn it on for production keys in a product with many users, so a missing user id fails loudly instead of acting with your company’s account.

{
  "name": "App server, production",
  "environmentId": "env_…",
  "endUserRequired": true
}

The key’s list entry carries endUserRequired. See Act for your users.

Set an expiry

API keys can have optional expiration dates. When a key expires:

  • Requests using that key return 401
  • You’ll need to create a new key
  • Expired keys cannot be reactivated

Set expiration when creating a key:

{
  "name": "Temporary Integration",
  "expiresAt": "2027-12-31T23:59:59Z"
}

Handle authentication errors

A key that does not authenticate

An invalid, expired or revoked key gets the same answer, HTTP 401. The response does not say which of the three it was.

{
  "success": false,
  "error": { "code": "AUTHENTICATION_ERROR", "message": "Authentication failed" },
  "requestId": "..."
}

A key that lacks a scope

HTTP 403, with the scope named.

{
  "success": false,
  "error": { "code": "AUTHORIZATION_ERROR", "message": "API key is missing required scope: actions:invoke" },
  "requestId": "..."
}

A key that requires an end user, called without one

HTTP 400, before anything runs.

{
  "success": false,
  "error": { "code": "END_USER_REQUIRED", "message": "..." },
  "requestId": "..."
}

Build the client with anlyon.forUser(userId) on your server, or send Anlyon-End-User. An end-user id is 1 to 128 characters from A-Z a-z 0-9 . _ : @ -.

Troubleshoot a key

Authentication failed (401)
  1. Verify the key is copied correctly (no extra spaces)
  2. Check that you’re using the Bearer prefix
  3. Check in the dashboard that the key has not expired or been revoked
  4. Verify you’re using a key for the right workspace and environment
Missing required scope Error

The key authenticated fine but is not allowed to perform this operation. The message names the scope it needs, e.g. API key is missing required scope: actions:invoke.

  1. Check the key’s scopes in Settings → API Keys
  2. If the key should have it, create a new key with that scope. Scopes are fixed at creation
  3. If it should not, the caller is doing something the key was not meant to do
A resource you expected is missing

Most often the key belongs to a different environment than the data. A key resolves its environment on authentication, so it sees that environment and no other. A missing resource usually means “not in this environment” rather than “deleted”.

A key that expired or was revoked

The API answers 401 with Authentication failed in both cases.

  1. Check the expiration date and status in the dashboard
  2. Create a new API key
  3. Update your application with the new key

Check a key at startup

GET /api/v2/auth/identity reports the caller’s credential and scopes without returning a secret. Both SDKs also provide a startup check:

await client.auth.requireScopes(
  ['actions:invoke', 'runs:write'],
  { forbidden: ['policies:write', 'approvals:decide'] },
);
client.auth.require_scopes(
    ['actions:invoke', 'runs:write'],
    forbidden=['policies:write', 'approvals:decide'],
)
# With the async client, await client.auth.require_scopes(...).

Choose required scopes from the operations your application actually performs. A ScopeCheckError exposes missing and forbidden lists. The helper inspects permission. It does not grant scopes or change a key. Malformed identity responses fail the check. Session credentials use workspace roles instead of a scope list and cannot satisfy a nonempty required-scope list.

This is an early configuration check, not permission to bypass policies, budgets, quotas, environment boundaries or a later key revocation. Keep governance credentials separate from runtime agent credentials.

Was this page helpful?