# API keys and scopes

> Create keys, pick scopes, use read-only keys, and what a key can never do.

Source: https://docs.ligament.ai/developers/api-keys/

Every API, MCP and CLI call authenticates with an API key. Create one key per integration, give it only the scopes that integration needs, and revoke it when the integration goes away. A read-only key for a reporting tool can’t change anything even if it leaks.

## Create a key

1.  In the app, open **Settings › API keys** and select **New key**.
2.  Give the key a name that says what uses it, for example “Service desk dashboard”. The name is how you’ll recognise the key in the list later, and it appears in the audit trail next to everything the key does.
3.  Pick the scopes (see below). A new key starts with **Read records** only.
4.  Select **Create key**, then copy the key from the banner above the list. It’s shown once. If you lose it, revoke the key and create a new one.

\[Screenshot: The New API key panel in Settings › API keys: name "Service desk dashboard", Read records ticked, Write records set to specific entities with Incident selected, and the admin scopes section below\]

The list shows each key’s name, the last four characters of the key, its scopes, when it was last used and when it was created. Admin scopes are highlighted.

Anyone in the workspace can create keys for themselves. Only workspace admins and owners can create keys with admin scopes.

## Scopes

A key holds a list of scopes. Each endpoint declares the scope it needs, and a request with a key that lacks it gets `403 insufficient_scope`, which names the missing scope.

| Scope | Lets the key |
| --- | --- |
| `records:read` | Read records of any entity, exports, search, attachments and reports |
| `records:write` | Create, update, transition, merge and delete records of any entity |
| `schema:read` / `schema:write` | Read or change entity definitions: fields, forms, views, lifecycle, rules |
| `apps:read` / `apps:write` | Read or build apps and their parts (scripts, connectors, pages, prompts, endpoints and so on). `apps:read` never reads the credentials among them: see [Credentials need an admin scope](#credentials-need-an-admin-scope) |
| `workflows:read` / `workflows:write` | Read or change workflow definitions and automations |
| `workflows:run` | Start, cancel and replay workflow runs |
| `spec:read` | Read the app spec and plan changes |
| `spec:propose` | Create and edit changesets for a person to review. Never applies anything |
| `spec:apply` | Apply spec changes, within the creator’s build permissions |
| `endpoints:invoke` | Call your workspace’s endpoints and API-key hooks, and its own tools on the MCP server |
| `ai:use` | Use AI models and agents, and run the local agent from the CLI |
| `import:write` | Run data imports |
| `audit:read` | Read and export the audit logs |
| `settings:read` | Read workspace settings: members, roles, access rules, invites, integrations, domains and so on. Never the credentials among them: see [Credentials need an admin scope](#credentials-need-an-admin-scope) |
| `*` | Every scope above. Shown as **Full access** in the app |

The [scopes reference](https://docs.ligament.ai/reference/scopes/index.md) has the full wording for each scope.

### Per-entity record scopes

`records:read` and `records:write` cover every entity. To narrow a key to some entities, add the entity key: `records:read:incident`, `records:write:incident`. In the **New key** panel, set **Write records** to **Specific entities…** and pick them.

The key in the screenshot above has `records:read` and `records:write:incident`. It can read anything the creator can read, but writing to another entity is refused:

```json
{
  "error": "This API key lacks the \"records:write:problem\" scope.",
  "code": "insufficient_scope",
  "message": "This API key lacks the \"records:write:problem\" scope.",
  "fix": "Use a key that has \"records:write:problem\" (or \"*\"). Create one in Settings → API keys; the scopes are listed at https://docs.ligament.ai/reference/scopes/.",
  "required": ["records:write:problem"],
  "route": "/api/records/[entityKey]",
  "doc_url": "https://docs.ligament.ai/reference/scopes/"
}
```

### Read-only keys

A key with only `records:read` reads records and nothing else. It’s the right key for dashboards, exports and BI tools. On the MCP server it sees the record and access tools that only read (`records_query`, `records_get`, `access_explain` and so on) and none that write.

### Admin scopes

Six scopes are admin scopes. `*` does **not** include them: a key has an admin scope only if it names it.

| Admin scope | Lets the key |
| --- | --- |
| `settings:write` | Change workspace settings: secrets, integrations, webhooks, embed tokens, portal, AI and notification settings, subsidiaries |
| `members:write` | Change who is in the workspace and what they can do: members, invites, roles, access rules |
| `sso:write` | Change identity provisioning: SCIM tokens and claimed email domains |
| `apps:install` | Install, upgrade, uninstall and delete apps, modules and plugins |
| `approvals:decide` | List and decide approvals |
| `components:approve` | Approve custom component versions and grant them data scopes. The creator also needs the “Approve custom components” role permission |

Anyone holding a key with an admin scope is effectively a workspace admin, so add only the admin scopes the key needs and store it like a password. A `*` key that calls an admin endpoint gets a `403` that says so:

```json
{
  "error": "This API key lacks the \"settings:write\" scope.",
  "code": "insufficient_scope",
  "fix": "\"settings:write\" is an admin scope: \"*\" does not grant it. A workspace admin must create a key that names \"settings:write\" explicitly (Settings → API keys → Admin scopes); see https://docs.ligament.ai/developers/api-keys/#admin-scopes.",
  "required": ["settings:write"],
  "route": "/api/settings/webhook",
  "doc_url": "https://docs.ligament.ai/developers/api-keys/#admin-scopes"
}
```

If someone who isn’t an admin tries to create a key with an admin scope, the request is refused with `403 admin_required`.

### Credentials need an admin scope

`settings:read`, `apps:read` and `*` read settings and app parts, but never the credentials among them. Reading a credential needs an admin scope:

| Credential | Needs | With `*` or `settings:read` |
| --- | --- | --- |
| Webhook signing secret (`GET /api/settings/webhook`) | `settings:write` | `403 insufficient_scope` |
| Integration config (`GET /api/integrations`) | `settings:write` | The integrations without their config: `"config": null, "configRedacted": true` |
| Pending invite and invite link tokens (`GET /api/invites`) | `members:write` | The invites with `"token": null, "tokenRedacted": true` |
| Domain verification tokens (`GET /api/domains`) | `settings:write` or `sso:write` | The domains with `"verificationToken": null, "tokenRedacted": true` |
| Plugin header values (`GET /api/plugins`) | `settings:write` | The header names with `"••••"` as each value, and `"headersRedacted": true` |
| Script endpoint tokens (`GET /api/scripts`, `GET /api/scripts/{key}`) | `settings:write` | The scripts with `"token": null, "tokenRedacted": true` |
| Connector endpoint tokens (`GET /api/connectors`, `GET /api/connectors/{key}`) | `settings:write` | The connectors with `"endpointToken": null, "endpointTokenRedacted": true` |

Passwords, API keys, private keys and auth headers stored in an integration are never returned at all, whatever the key or session: they show as `"••••"`.

A plugin’s OAuth connection is a credential too. Three requests change it, and each needs `settings:write` from a key (whose creator is an admin) and an admin from a browser session:

| Request | What it does |
| --- | --- |
| `POST /api/plugins/{key}/oauth/client` | Saves the OAuth app’s client ID, client secret and scopes |
| `DELETE /api/plugins/{key}/oauth/client` | Disconnects: removes the stored access and refresh tokens |
| `GET /api/plugins/{key}/oauth/start` | Connects an account: stores that account’s tokens for the workspace |

With `apps:write` or `*` these get `403 insufficient_scope`. People with Build but without admin rights get `403 capability_required`. `GET /api/plugins/{key}/oauth/client` returns only the connection status (configured, connected, client ID), never the secret or tokens, so `apps:read` and Build are enough for it. In **Build › Plugins** those people see the status, not the credential form or the **Connect** and **Disconnect** buttons.

A signed-in person who can open the page that edits a credential (an admin, or someone with Build for plugins, scripts and connectors) still sees it there. If you send a plugin’s config back with a header still set to `"••••"`, the stored value is kept.

### What no key can do

Some areas have no scope at all and only work from a signed-in browser session: creating and revoking API keys, SSO providers, the security policy, OIDC clients and moving a workspace in the hierarchy. A key gets `403 session_required` there. See [Areas no API key can reach](https://docs.ligament.ai/reference/scopes/index.md#session-only).

## A key is capped at its creator

A key acts for the person who created it. Every request is checked against that person’s **current** role in the workspace, so a key can never do more than its creator can do right now:

-   An owner’s or admin’s key keeps its scopes.
-   A member’s key (or a key made by someone with a custom role) loses any admin scope.
-   A viewer’s key keeps only read scopes. `*` on a viewer’s key means “read everything the viewer can read”.
-   Record access rules and hidden fields apply to the key as they apply to its creator. A rule that says “me” (for example “assigned to me”) means the creator, and the roles the creator holds through assignments and groups count too.
-   The Build, AI, Admin, Logs and App store areas need the same capability for a key as for its creator in the app. A member’s key can’t propose spec changes (`spec:propose`) unless the member’s role has the Build capability. Without it the key gets `403 capability_required` (see [Errors](https://docs.ligament.ai/developers/errors/index.md#capability_required)).

The cap is worked out on every request, not when the key is created. If you demote someone, their keys narrow straight away. Here a `*` key whose creator has the viewer role tries to create an incident:

```json
{
  "error": "This API key has \"records:write:incident\", but its creator is now \"viewer\" in this workspace, and a key is capped at its creator's current role.",
  "code": "insufficient_scope",
  "fix": "Use a key created by a workspace member with write access, or ask an admin to restore the creator's role.",
  "required": ["records:write:incident"],
  "route": "/api/records/[entityKey]"
}
```

Records a key creates or changes are attributed to its creator, and the activity history also names the key.

If the creator leaves the workspace or is removed, all their keys stop working with `403 key_owner_inactive`. Create integration keys as a person who will stay in the workspace, and replace them before that person leaves.

Admin areas also check the creator’s role, on top of the scope: a key created by someone who is no longer an owner or admin gets `403` there even when it names the scope.

## Revoke a key

In **Settings › API keys**, tick the key (or several), choose **Revoke** and confirm. The key leaves the list, and any client still using it fails on its next request:

```plaintext
HTTP/1.1 401 Unauthorized
{"error":"Invalid or revoked API key"}
```

Anyone can revoke their own keys. Admins can revoke anyone’s. Revoked keys stay on record, so audit entries and request logs still show which key did what.

## Keys and the CLI

`ligament login` creates a key for you through the browser, with full access (`*`) and any admin scopes you tick. See [CLI](https://docs.ligament.ai/developers/cli/index.md#sign-in).
