# Authentication

> Authenticate API requests with a workspace API key, a personal access token, or OAuth.

To call the API, send a **workspace API key** in the `Authorization` header:

```http
Authorization: Bearer YOUR_API_KEY
```

```bash
curl \
  -H "Authorization: Bearer YOUR_API_KEY" \
  https://api.limitry.com/v1/workspace
```

The response tells you which workspace the key belongs to:

```json
{
  "id": "ws_9418b705-3720-48ca-b2bf-f726d1456684",
  "name": "Example Workspace",
  "slug": "example",
  "createdAt": "2026-08-19T12:00:00.000Z"
}
```

## API keys belong to a workspace

An API key acts for the workspace, not for a person. It keeps working when the person who created it leaves. Nobody can sign in with it, because it never carries a user session.

## Test and live keys

Every key also belongs to one environment, and its prefix says which: `lim_test_…` for test, `lim_live_…` for live. A test key reads and changes only test limits and counts, and a live key only live ones. The API paths are the same for both. See [Test and live](/docs/test-and-live/).

A test key can read workspace-wide things, such as members, webhook endpoints and the audit log, but can’t change them. Use a live key or a personal access token for that.

## Creating a key

Workspace owners and admins create keys in the app, under **Settings → Developers**, and members create test keys there. Each key belongs to test or live, and you choose which when you create it. The list shows both, each marked test or live.

1. Give the key a name that says where it’s used, such as `production-backend`.
2. Choose what the key can do. A new key starts at **Check limits**, which is what your app needs in production. A setup script or CI job that creates limits needs **Manage limits** ([Access](#access) lists the choices).
3. Copy the secret and put it in your secret manager straight away. We show it only once.

After that, the list of keys shows only the key’s name, its first few characters, its access, the day you created it, and when it was last used. If you lose a secret, create a new key and revoke the old one.

## Revoking and rotating

Owners and admins can revoke any key at any time under **Settings → Developers**, and members can revoke test keys. You can’t restore a revoked key. Most requests refuse a revoked key at once. Checks and reservations cache keys for speed, so they can accept a revoked key for up to 60 seconds.

To rotate a key without downtime:

1. Create a new key.
2. Switch your integration to it.
3. Revoke the old key.

## Access

When you create a key or a token, you choose what it may do:

| Choice            | What it gets                                                                                                            |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------- |
| **Check limits**  | Can make checks and read limits. A new API key starts here.                                                             |
| **Manage limits** | Can create and change limits, subjects, credits and webhooks, and make checks. A new personal access token starts here. |
| **Read only**     | Can view everything but change nothing. Permissions added to the API later aren’t included.                             |
| **Full access**   | Everything, including what the API adds later.                                                                          |
| **Custom**        | Only the permissions you pick.                                                                                          |

## Permissions

With **Custom**, you choose No access, View, or View and change for each permission. Each choice grants one or more **scopes**, which are what the API checks. The [API reference](/docs/reference/) shows the scope each endpoint needs.

**Limits and checks**

* **Limits:** View is `limits:read`. View and change adds `limits:write`.
* **Checks:** Use is `checks:write`.

**Workspace**

* **Workspace details:** View is `workspace:read`.
* **Members:** View is `workspace.members:read`.
* **Teams:** View is `workspace.teams:read`.
* **Audit log:** View is `workspace.audit:read`.
* **Approvals:** View is `workspace.approvals:read`. View and request adds `workspace.approvals:write`.

**Developers**

* **Webhooks:** View is `workspace.webhooks:read`. View and change adds `workspace.webhooks:write`.

**Check limits** is `checks:write` and `limits:read`. **Manage limits** is `limits:read`, `limits:write`, `checks:write`, `workspace:read`, `workspace.webhooks:read` and `workspace.webhooks:write`.

Give an integration only what it needs. If a credential calls an endpoint it doesn’t have the scope for, the API returns `403 forbidden`:

```json
{
  "error": {
    "code": "forbidden",
    "message": "This credential is not granted the workspace.audit:read scope",
    "requestId": "…",
    "docs": "https://limitry.com/docs/errors/#forbidden"
  }
}
```

You can change an API key’s access at any time with **Edit access** on its row under **Settings → Developers**. The key itself doesn’t change, so there’s nothing to update where you use it. The new access applies within a minute.

You can’t change a personal access token’s access. Create a new token and revoke the old one instead.

## Personal access tokens

A personal access token (`pat_…`) acts as **you**, not as a workspace. Use one for your own scripts, CI jobs and the CLI. Create one in the app under **Account → Personal access tokens**, with **Manage limits**. Or let the CLI make one: run `login`, approve in the browser window it opens, and the CLI creates a token for that computer and stores it.

A personal access token:

* works only in the workspaces you choose, either all of yours or specific ones
* can do only what its [access](#access) allows
* is also limited by your role in each workspace. For example, only owners and admins can call `GET /v1/workspace/audit-events`, just as only they can open the audit page in the app. An API key has no role, because it acts as the workspace itself.
* expires when you choose: after 30 days, 90 days, a year, or never.
* identifies you at `/v1/user/me`:

```bash
curl \
  -H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
  https://api.limitry.com/v1/user/me
```

```json
{
  "id": "…",
  "name": "Casey Customer",
  "email": "casey@example.com",
  "workspaces": [
    { "id": "…", "name": "Example", "slug": "example", "role": "owner" }
  ]
}
```

Everywhere else, tell the API which workspace you’re working in by setting the `X-Workspace` header to its slug. The request then runs with your role in that workspace and the token’s scopes:

```bash
curl \
  -H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
  -H "X-Workspace: example" \
  https://api.limitry.com/v1/workspace
```

A personal access token works in test unless the request says otherwise. To act in live, add `X-Environment: live`:

```bash
curl \
  -H "Authorization: Bearer YOUR_PERSONAL_ACCESS_TOKEN" \
  -H "X-Workspace: example" \
  -H "X-Environment: live" \
  https://api.limitry.com/v1/limits
```

The response’s `X-Environment` header names the environment the request used. An environment that doesn’t exist fails with `400`.

Without `X-Workspace`, the request fails with `400`. It fails with `403` if:

* you aren’t a member of the workspace
* the token wasn’t created for that workspace
* the token doesn’t have the scope

API keys ignore `X-Workspace`, because each one already belongs to a workspace. They don’t work on `/v1/user/*` at all. A key always works in its own environment, and an `X-Environment` header that names the other one fails with `403`.

As with an API key, we show a token only once. You can revoke it under **Account → Personal access tokens**. It also stops working the moment it expires, or if we suspend your account.

## Apps and AI agents (OAuth)

Apps and AI agents can act for a person without ever holding a key, because the API is an OAuth 2.1 authorization server. The app sends the person to sign in. They choose a workspace and approve what the app may do, and the app gets a short-lived access token for the API.

* **Discovery:** `https://api.limitry.com/.well-known/oauth-authorization-server/auth` lists every endpoint. Apps can register themselves with dynamic client registration, but registering grants nothing until a person approves.
* **Scopes:** an app asks for the same [scopes](#permissions), such as `workspace.audit:read`, and adds `offline_access` to get a refresh token. The person can give it fewer scopes than it asked for.
* **One person, one workspace:** a token acts for one person in one workspace and has that person’s role, so it needs no `X-Workspace` header. Request the token for the resource `https://api.limitry.com/v1`.
* **Environment:** like a personal access token, it works in test unless a request sends `X-Environment: live`.
* **Disconnecting:** the person can disconnect the app at any time under **Account → Apps and agents**. The app’s tokens stop working on the next request.

## When authentication fails

If a credential is missing, malformed, invalid or revoked, the API returns `401` with the standard [error envelope](/docs/errors/):

```json
{
  "error": {
    "code": "unauthorized",
    "message": "Unauthorized",
    "requestId": "…",
    "docs": "https://limitry.com/docs/errors/#unauthorized"
  }
}
```

The response is the same whatever the cause, so it gives nothing away to someone guessing keys. Keys made before test and live existed, which start with `sk_limitry_`, get this response too. Browser session cookies never work on the public API.
