# Authentication and keys

Every call to the API carries a key in the `Authorization` header:

```plaintext
Authorization: Bearer wt15ak_…
```

A key is sent only in that header — never in a URL or a query string.

## The key

-   **Format.** `wt15ak_`, then 64 hexadecimal characters and a 6-character checksum. The fixed prefix lets secret scanners recognise a leaked key; a malformed string is refused before any lookup.
-   **Shown once.** The full key appears once, when it is created. WatchTower15 keeps only a one-way hash of it and a few of its characters. The console lists a key by name and `redacted_key`: `wt15ak_…` and the key’s real last four characters (for example `wt15ak_…Qz3x`). A key made before those were kept shows the four characters it kept followed by six dots for the hidden checksum (`wt15ak_…a1b2••••••`). `last_four` is not the key’s last four: it is four characters kept to tell keys apart.
-   **One organisation.** A key belongs to the organisation you create it in, and acts as you there.

## Create a key

You can create a key when your role holds the **API access** permission, `api_access.view`. Admins hold it; another role holds it only when your organisation grants it (see [roles & permissions](https://docs.watchtower15.com/platform/roles-and-permissions/)).

1.  Open your **Profile** and go to its **API Keys** tab.
2.  Choose the organisation, name the key, tick the areas it may read or change and set how long it lives (the dialog suggests 90 days).
3.  Copy the key when it is shown. **It is shown once**, and WatchTower15 keeps only a one-way hash of it, so a lost key is replaced, not recovered.

Keep it in a secret store — an environment variable in your CI, a secrets manager — never in source control.

## Scopes

A key carries **scopes**, which are permission names such as `servers.view` or `logs.view`. A member’s key needs the scope **and** the member’s role to hold the same permission, so it never sees more than the member who owns it: if the role loses a permission, the key loses it with the member, on its next call. A [service account](https://developer.watchtower15.com/api/authentication/#service-accounts)’s key follows the same rule with the account’s roles: the scope **and** a role of the account granting it.

You choose the scopes when you create the key and can only choose ones you hold. Grant a key only the areas it needs; one key per job makes a leak small and a revocation clean.

Every scope that does not end in `.view` is a write scope. Ticking one needs the **API access** edit permission, `api_access.edit`, besides holding the permission itself, and a key made before they existed has neither.

| Area | Read scope | Write scopes |
| --- | --- | --- |
| Servers | `servers.view` | `servers.edit` (update, approve, archive, reactivate, revoke, ports, volumes), `servers.delete` |
| Security findings | `security.view` | `security.edit` (dismiss, restore, re-check), `security.policy` (indicator policies) |
| Server profiles | `server_profiles.view` | `server_profiles.edit` (also the alarm templates and their propagation), `server_profiles.delete` (also deleting an alarm template) |
| Domains | `domains.view` | `domains.edit` (create, update, verification, scans), `domains.delete` |
| Services | `services.view`, `service_evidence.view` (a step’s evidence in a run and a test run) | `services.edit`, `services.delete`, `services.parameters` |
| Databases | `database.view` | `database.edit`, `database.delete` |
| Custom metrics and metric sources | `custom_metrics.view` | `custom_metrics.edit`, `custom_metrics.delete` (also revoking a source’s token) |
| Log sources | `log_sources.view` | `log_sources.edit`, `log_sources.delete` |
| Tags and tag groups | `tags.view` | `tags.edit` (create, update), `tags.delete` |
| Alarm channels | `channels.view` | `channels.edit` (create, update, send a test message), `channels.delete` |
| Alarm policies | `policies.view` | `policies.edit` (create, update), `policies.delete` |
| Incidents | `incidents.view` | `incidents.edit` (acknowledge, resolve) |
| Alarms | `alarms.view` | `alarms.edit` (create, update, switch off), `alarms.delete` |
| Logs | `logs.view` | none |
| Audit trail | `audit.view` | none (reads the audit actions with their changed values, context, the actor’s email and the IP address, as the console’s Audit page shows them to a member holding `audit.view`, and the audit categories and actors that filter them) |
| Organisation billing details | `billing.view` | none |
| Your own API keys and AI clients | `api_access.view`, `ai_access.view` | none |

`api_access.view` and `ai_access.view` let a key list its owner’s own API keys (`GET /v1/user/api-keys`) and AI clients (`GET /v1/user/ai-clients`) in the key’s organisation, never another user’s and never another organisation’s; the key making the call is listed too. A key made before they existed holds neither.

A key made before `service_evidence.view` existed holds none: its owner adds it to the key to read a step’s evidence (without it every step answers `evidence: null` with `evidence_hidden: true`). A key made before the alarm channel and alarm policy scopes existed holds none of them: its owner adds the ones it needs to the key, and no other key changes. The same goes for `billing.view`, which only `GET /v1/organisation` reads: a key made before it existed holds none, so its owner adds it to the key, and until then the answer’s `billing` is `null`. `services.parameters` is carried by no operation of its own: a call that creates or changes a service with parameters, or with authentication other than none, needs it as well as `services.edit`, on the key and on the owner’s role (a member’s role, or a service account’s roles), as the console does. The tag-group operations carry the tag scopes: `tags.view` lists and reads groups, `tags.edit` creates and renames them, `tags.delete` deletes them. See [changing resources](https://developer.watchtower15.com/api/changing-resources/) for every operation and the scope it needs, [acting on incidents and scans](https://developer.watchtower15.com/api/acting-on-incidents-and-scans/), [route alarms to Slack](https://developer.watchtower15.com/api/route-alarms-to-slack/) for the channel and policy scopes at work, and [quiet a noisy alarm](https://developer.watchtower15.com/api/quiet-a-noisy-alarm/) for the alarm scopes.

## Service accounts

A key can belong to a **service account** instead of a person: an account an Admin makes under **Organisation → Users → Service accounts** for a script, a pipeline or a tool that should not depend on one member. It has a name and **roles**, the organisation’s own roles (never Admin), set on its **Edit** page. Its roles are its keys’ ceiling: a call is allowed when the key carries the scope **and** a role of the account grants it, the rule a member’s key follows. No **API access** permission is needed on the account. Until it has a role, its keys can do nothing.

-   **Taking a scope away from every key at once:** remove the permission from the account’s role, or the role from the account. Say a deploy pipeline’s key carries `servers.view` and `servers.edit`, and its account’s role holds both. Untick `servers.edit` on the role, and the key’s next write is refused with *This service account’s roles do not grant servers.edit*, its reads unchanged, with no key revoked or issued. Adding a permission to a role widens no key: a key only ever uses the scopes ticked when it was issued.
    
-   A key can be issued only with scopes the account’s roles grant, so it never holds a scope it cannot use. A scope a key already holds that no role grants any longer is listed apart, as refused, on the account’s **Scopes** tab.
    
-   Every change of an account’s roles, and of a role’s permissions, is in the audit trail, with the keys it affects.
    
-   **A new scope needs a role:** when WatchTower15 adds a scope and you want a service account’s key to use it, add the permission to the account’s role first, then issue the key with it.
    
-   A member holding **Service accounts: Edit** issues its keys, on the account’s **API Keys** tab, and the key is shown once as any other. They can tick only scopes they could put on a key of their own (**API access: View**, **API access: Edit** for a write scope, and each scope held by them) that the account’s roles also grant. Setting an account’s roles needs **Users: Edit** as well. A person cannot name a service account as the owner of a key from their own Profile.
    
-   It **cannot sign in**: no password, passkey, single sign-on or console access, and it never receives email. The three emails about a key (created, revoked, expiring) go to the organisation’s Admins instead, naming the account.
    
-   It is **not a member**: it takes no seat, appears in no member list and is never an alarm recipient.
    
-   Its keys end when the account is **suspended** or **deleted**; restoring it does not bring them back, so issue new ones.
    
-   The organisation’s switch **Allow members to use API keys** applies to its keys as to anyone’s; the SSO switch does not, because it is not a person who signs in with a provider.
    
-   `GET /v1/me` answers `user.account_type`: `person`, or `service_account`. For a service account’s key `user.email` is its undeliverable `.invalid` address, not a mailbox, and `user.roles` lists its roles (`null` for a person’s key). For every key, `key.effective_scopes` is the part of `key.scopes` its owner’s permissions allow now, so a call can see why a scope it holds is refused.
    

## Expiry

Every key expires. You choose how long it lives when you create it, from 1 day to 1 year (365 days). The console’s dialog suggests 90 days, and a key created with no choice also lives 90 days. Seven days before a key expires, WatchTower15 emails its owner. A key is never extended: create a new one and revoke the old.

## Emails about your keys

WatchTower15 emails a key’s owner, at the account’s own address:

-   **When a key is created**: *New API key “” created*, with its name and the key as the console shows it, the organisation, its scopes, when it expires, and the IP address and device it was created from. Never the key itself. If you did not create it, revoke it and reset your password.
-   **When keys are revoked**: one email per revocation, listing the keys it ended (up to 10, then how many more) and why: you revoked it, an administrator or an Admin of the organisation did, your membership ended or was suspended, your password was reset, or WatchTower15 revoked every key as a security measure. A revocation that ends keys in several organisations, such as a password reset, sends one email listing them all.
-   **Seven days before a key expires**, as above.

## What revokes a key

A revoked key answers `401 unauthorized` from then on. A key is revoked when:

-   its owner revokes it, from the **API Keys** tab of their Profile;
-   an Admin revokes it from **Organisation → Users**, or revokes every key of the organisation with **Revoke all keys** on **Organisation → Settings → Authentication**;
-   its owner’s membership of the organisation ends or is suspended — restoring the membership does not bring the key back;
-   its owner’s password is **reset**. Changing a password does not revoke keys.

A key also stops answering when its owner’s account is deleted, and when it expires.

## Turning keys off for an organisation

**Allow members to use API keys**, on the **API Keys** card of **Organisation → Settings → Authentication** (`settings.edit`), is on for every organisation unless you turn it off. While it is off, every key of the organisation answers `403 forbidden`, no key can be created for it, and the Profile no longer offers it. Turning it off revokes nothing: turning it on again brings every key back. See [Organisation settings](https://docs.watchtower15.com/platform/organisation-settings/#api-keys).

Two-factor authentication and password expiry do not affect keys: a key keeps working while its owner’s organisation requires two-factor authentication they have not set up, or while their password is expired.

## Single sign-on organisations

Members who must sign in with single sign-on can create and use API keys only while **Allow API keys for SSO-managed members** is on (off by default), on the same **API Keys** card. Switching it off revokes nothing: their keys simply stop answering until it is switched on again. See [single sign-on](https://docs.watchtower15.com/platform/sso/).

## What WatchTower15 records

Each revocation is emailed to the key’s owner ([above](https://developer.watchtower15.com/api/authentication/#emails-about-your-keys)).

For each key: its name, the areas it may read, the organisation it belongs to and the member it acts for, when it was created and when it expires, when it was last used and the IP address of that use, and, if it was revoked, when, why and by whom. It never keeps the key itself. For each key and day it also counts the calls made to each operation, how many failed or were refused for exceeding a limit, how much data they returned and when the last call was made. Key creation, revocation and expiry appear in the [audit trail](https://docs.watchtower15.com/platform/audit-trail/); the counts appear on **Organisation → Audit → API usage**. Key records are kept with your account data, revoked and expired keys included; the daily counts are deleted after 400 days.

**Authorization header**

```text
Authorization: Bearer wt15ak_…
```

**GET /v1/me**

curl:

```bash
curl https://rest.watchtower15.com/v1/me \
  -H "Authorization: Bearer $WT15_API_KEY"
```

PHP:

```php
// The client reads WT15_API_KEY from the environment.
$wt15 = WatchTower15\Client::fromEnvironment();

$me = $wt15->me();
echo $me->keyName, ' in ', $me->organisationName,
    ' (', implode(', ', $me->scopes), ')';
```

Node.js:

```ts
// The client reads WT15_API_KEY from the environment.
const wt15 = WatchTower15.fromEnvironment();

const me = await wt15.me();
console.log(me.key.name, 'in', me.organisation.name, `(${me.key.scopes.join(', ')})`);
```

Python:

```python
# The client reads WT15_API_KEY from the environment.
client = Client.from_environment()

me = client.me()
print(me.key.name, 'in', me.organisation.name, f"({', '.join(me.key.scopes)})")
```

**Response (200 OK)**

```json
{
  "data": {
    "key": {
      "uuid": "6b0e2c4f-1d3a-4c55-9e1b-7a2f0c8d4e91",
      "name": "CI deploy",
      "last_four": "9f2c",
      "redacted_key": "wt15ak_…Qz3x",
      "scopes": ["servers.view", "domains.view"],
      "created_at": 1794214800000,
      "expires_at": 1801990800000
    },
    "user": {
      "uuid": "0c7d5e1a-8b2f-4f3e-a6d4-2e9b1c0f7a53",
      "name": "Alex Morgan",
      "email": "alex@example.com",
      "account_type": "person"
    },
    "organisation": {
      "uuid": "f4a1b2c3-5d6e-4f70-8192-a3b4c5d6e7f8",
      "name": "Example Ltd"
    }
  }
}
```

**A revoked or expired key (401 Unauthorized)**

```http
HTTP/1.1 401 Unauthorized
Content-Type: application/problem+json
X-Request-Id: 3f9a7c2e-5b1d-4e8a-9c6f-0d2b4a7e1c95

{
  "type": "https://docs.watchtower15.com/api/errors/unauthorized/",
  "title": "Unauthorized",
  "status": 401,
  "code": "unauthorized",
  "detail": "The API key is missing, malformed, expired or revoked",
  "request_id": "3f9a7c2e-5b1d-4e8a-9c6f-0d2b4a7e1c95"
}
```

Source: https://developer.watchtower15.com/api/authentication/
