# 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.reminix.com/v1/scripts
```

The response lists the scripts in the key’s workspace, one page at a time (see [Pagination](/docs/pagination/)):

```json
{ "items": [{ "slug": "unlock-account", "…": "…" }], "nextCursor": null }
```

## 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. You can’t sign in with it, because it never carries a user session.

Some actions need a person, not an API key: uploading or publishing a version, and creating a schedule or trigger. For these, use a personal access token, an app you connected, or the Reminix app.

## Creating a key

The workspace’s owner and its admins create keys in the app, under **Settings → Developers**:

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 **Run scripts**, which is what your software needs ([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, its creation date and the date of its last use. If you lose a secret, create a new key and revoke the old one.

Members create keys too, in a workspace that has an environment besides production. A member’s key works in every environment except production. Keys that reach production are for the owner and admins to create. Members on a workspace with production alone ask an owner or admin for a key.

## Revoking and rotating

The workspace’s owner and its admins can revoke a key at any time under **Settings → Developers**. A member can revoke a key that can’t reach production. A revoked key stops working on the next request, and you can’t restore it.

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                                                                                    |
| --------------------------- | ----------------------------------------------------------------------------------------------- |
| **Run scripts**             | Runs published scripts and reads their results. New API keys start here.                        |
| **Publish and run scripts** | Publishes, runs and reads scripts. New personal access tokens and the CLI’s sign-in start 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.

**Scripts and runs**

* **Scripts:** View is `scripts:read`. Change adds `scripts:write`.
* **Runs:** View is `runs:read`. Change, which runs scripts, adds `runs:write`.

**Script settings**

* **Secrets:** View is `secrets:read`, which shows names, never values. Change adds `secrets:write`.
* **Environments:** View is `environments:read`. Change adds `environments: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`. Change, which requests approvals, adds `workspace.approvals:write`.

**Developers**

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

**Run scripts** grants `scripts:read`, `runs:read` and `runs:write`. **Publish and run scripts** also grants `scripts: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": "9f0c1c2e-6a4b-4d3e-8f2a-1b0c9d8e7f6a",
    "docs": "https://reminix.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**. 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.reminix.com/v1/user/me
```

```json
{
  "id": "usr_4f8a2c1e-7b3d-4e9f-a6c5-2d1b0e9f8a7c",
  "name": "Casey Customer",
  "email": "casey@example.com",
  "workspaces": [
    {
      "id": "ws_9418b705-3720-48ca-b2bf-f726d1456684",
      "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.reminix.com/v1/scripts
```

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.

Like an API key, a token appears only once. You can revoke it under **Account → Personal access tokens**. It also stops working the moment it expires or 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.reminix.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.reminix.com/v1`.
* **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": "9f0c1c2e-6a4b-4d3e-8f2a-1b0c9d8e7f6a",
    "docs": "https://reminix.com/docs/errors/#unauthorized"
  }
}
```

The response is the same whatever the cause, so it gives nothing away to someone guessing keys. Browser session cookies never work on the public API.
