# Authentication

Source: https://openpanel.sh/docs/api/authentication

API keys for scripts, CI and agents, what a key may do, and the other ways a call is signed in.

Every call to the API sends a credential in the `Authorization` header:

```sh
curl https://openpanel.sh/api/v1/me \
  -H "Authorization: Bearer $OPENPANEL_TOKEN"
```

A call without one, or with one that has been revoked or has expired, answers `401`.

| Credential | Looks like | Made by | Works in |
|---|---|---|---|
| **API key** | `opk_` and 43 characters | A signed-in person, with `openpanel keys create` or the API | The organization it was made in |
| **CLI token** | `opc_…` | `openpanel login`, approved by a person in the browser | Every organization of that person; `OpenPanel-Organization` picks one |

The console's own session also works, from the console only: a change made with it must come from the console's own pages.

AI clients connect to the [MCP server](/docs/ai) instead of the API. They sign in with OAuth as the person who approves them, or send an API key the same way as above.

## API keys [#api-keys]

An API key is for a script, a CI pipeline or an AI agent: something that runs without a person at a browser.

- **It acts as the person who made it.** Each call reads that person's role and project access as they are at that moment. If their access is lowered, the key's is too; if they leave the organization, the key stops working and is revoked.
- **Its scope is a ceiling:** `view` reads, `deploy` also changes and deploys services, `admin` also deletes and manages access. A key never does more than its creator could, whatever its scope.
- **It can be limited to some projects.** Such a key sees only those projects, and cannot do anything that belongs to the whole organization, such as listing servers or reading the audit log.
- **It can expire** on a date you choose.
- **It is shown once.** OpenPanel keeps only a hash of it. If you lose a key, revoke it and make a new one.
- **A key cannot make or revoke keys.** Only a signed-in person can, so a leaked key cannot make itself a successor.

Each person can have 50 active keys in an organization.

### Make a key [#make-a-key]

In the console, open **Organization settings**, then **API keys**, and choose **Create key**: a name, a scope, optionally some projects and an end date. The key is shown once.

From the CLI, signed in as yourself with `openpanel login` (see [Sign in](/docs/cli/sign-in)):

```sh
openpanel keys create --name "GitHub Actions" --scope deploy --project shop --expires 2027-06-30
```

`--project` limits the key to that project (repeat it for more); leave it out for a key that reaches every project you can. The key is printed once; store it right away, for example as a secret of your CI.

The same from the API, with the CLI's token (`opc_…`, from `openpanel login`):

```sh
curl https://openpanel.sh/api/v1/api-keys \
  -H "Authorization: Bearer $OPENPANEL_CLI_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "name": "GitHub Actions", "scope": "deploy", "projectIds": ["0193b7a0-…"], "expiresAt": "2027-06-30T00:00:00Z" }'
```

The answer holds the key in `key`, the only time it is ever shown, and the key's record in `apiKey`:

```json
{
  "apiKey": {
    "id": "01a23325-b8ff-7007-81ee-6d86df4d57e3",
    "name": "GitHub Actions",
    "prefix": "opk_8JoAsdp1",
    "scope": "deploy",
    "projectIds": ["0193b7a0-…"],
    "expiresAt": "2027-06-30T00:00:00.000Z",
    "lastUsedAt": null,
    "revokedAt": null,
    "createdAt": "2026-12-01T19:47:19.929Z",
    "createdBy": "…",
    "creatorName": "Rūta Kazlauskė",
    "creatorEmail": "ruta@example.com"
  },
  "key": "opk_…"
}
```

### See and revoke keys [#see-and-revoke-keys]

```sh
openpanel keys
openpanel keys revoke 01a23325-b8ff-7007-81ee-6d86df4d57e3
```

`openpanel keys` lists your own keys with their scope, projects and when each was last used; the organization's owner and admins see everyone's, so they can revoke any of them. A revoked key stops working at once. In the API: [List API keys](/docs/api/api-keys/list-api-keys) and [Revoke an API key](/docs/api/api-keys/revoke-an-api-key).

Making and revoking a key are written to the [audit log](/docs/monitoring/audit-log), and every change a key makes is recorded with the person behind it.

## What a call may do [#what-a-call-may-do]

A call is allowed when the person's access to the project, capped by the key's scope, is enough:

| To | Needs |
|---|---|
| See projects, services, deployments, variables and domains | `view` |
| Create services, change their settings, set variables, deploy, roll back, add domains and volumes | `deploy` |
| Delete projects and services, remove volumes, rename a project or make it private, give people access | `admin` on that project |
| Create a project | `deploy` in the organization |
| Read the audit log, and see and revoke everyone's keys | Owner or admin of the organization |
| Make an API key | Any member, signed in as themselves |

A person's access to a project comes from their role, unless they were given their own access to that project; see [Per-project access](/docs/members/per-project-access). A project the caller cannot see at all answers `404`, as if it did not exist, so a private project's name does not leak. When the caller can see it but may not make the change, the answer is `403` with a sentence such as "This API key's scope is view; this needs deploy."

## Keep keys safe [#keep-keys-safe]

- Keep a key in your CI's secrets or a secret manager, never in a repository.
- Give each place its own key, with the lowest scope that does the job and only the projects it needs, so you can revoke one without touching the others.
- Set an expiry on keys you make for a one-off job.