# Authentication

Every request except the public documentation routes carries a credential in the `Authorization` header. Nothing else is accepted: a key in a web address or a form field is refused, and so is a request without a credential.

```bash
curl https://api.seemly.com/v1/whoami \
  -H "Authorization: Bearer $SEEMLY_API_KEY"
```

## API keys

A key looks like `seemly_live_<public id><secret><checksum>`. Test keys, which exist only in a [sandbox](/developers/md/guides/sandbox), start with `seemly_test_`. A live key never works on a sandbox and a test key never works on a live workspace; mixing them returns `sandbox_only`.

- A workspace owner creates, lists and revokes keys in Developers in the dashboard. There is no operation that creates or reads a key, so a leaked key cannot make more keys.
- The full key is shown once, at creation. Seemly stores only a keyed hash and the last four characters.
- A key belongs to exactly one workspace. No request parameter selects a workspace.
- A workspace can hold up to 25 active keys.

### Lifetime

| Kind of key | Expires |
| --- | --- |
| A key made by a person | After one year |
| An AI agent key (the Agent preset) | After 90 days |
| A key for an approved partner integration | Never, but only after Seemly approves it (see [partners](/developers/md/guides/partners)) |

The dashboard shows a reminder 14 days before a key expires. A revoked or expired key stops working within one request, and the answer is `credential_revoked` or `credential_expired`.

## Scopes

A key can only do what its scopes say. Add the fewest it needs. The dashboard offers presets you can edit before you create the key:

| Preset | For | Scopes |
| --- | --- | --- |
| Read only | A reporting tool | `account:read`, `lists:read`, `tags:read`, `mailings:read`, `sequences:read`, `magnets:read`, `promos:read`, `swaps:read`, `stats:read` |
| Integration | A store, a website or a no-code tool | `account:read`, `lists:read`, `tags:read`, `subscribers:write`, `tags:write` |
| AI agent | An assistant that drafts mailings | `account:read`, `lists:read`, `tags:read`, `audiences:read`, `design:read`, `mailings:read`, `mailings:write`, `sequences:read`, `magnets:read`, `stats:read` |
| Full access (no sending) | Your own scripts | Every scope except the three below |

Three scopes are never part of a preset, and each needs an explicit step when the owner grants it:

| Scope | What it allows | The owner must |
| --- | --- | --- |
| `mailings:send` | Send mailings without waiting for approval in the dashboard | Tick a plain-language acknowledgement. The plan must also include API sending. |
| `subscribers:write_confirmed` | Add readers as already confirmed | Declare where the readers come from and how they joined, and attest to their consent. |
| `subscribers:export` | Download the whole list as a CSV | Accept a warning that it exposes every address. |

Each operation page lists its required scopes, and `get_current_access` returns the scopes of the key you are using.

## OAuth for apps that act for many authors

An application that acts for several authors does not ask them to paste keys. It uses OAuth 2.1 with PKCE:

1. The app discovers the sign-in service from `/.well-known/oauth-protected-resource` (RFC 9728). A 401 response also carries a `WWW-Authenticate` header that points to it.
2. The author signs in. On first use by an app, the API answers `consent_required` with a link to the dashboard page where the author chooses the workspace and the scopes.
3. The app calls the API with the access token as a Bearer token, exactly like a key. The grant, not the token, decides what the app may do.
4. The author can revoke a connected app at any time in Developers. Revocation takes effect on the next request.

## Reading an authentication problem

| Status and code | Meaning | What to do |
| --- | --- | --- |
| 401 `unauthenticated` | No credential, or one that is malformed or unknown | Send `Authorization: Bearer <key>`. Check for a trailing space or a missing character. |
| 401 `credential_expired` | The key passed its expiry date | Ask the owner for a new key. |
| 401 `credential_revoked` | The owner revoked the key | Ask the owner for a new key. |
| 403 `insufficient_scope` | The key is valid but lacks a scope | The problem names the missing scope. Ask the owner for a key with it. |
| 403 `plan_does_not_include` | The plan has no API access, or not this feature | Upgrade, or stop using the feature. |
| 403 `workspace_paused` | The workspace is paused | Read `sending.sentence` from `get_current_access`; the author resolves it in the dashboard. |
| 403 `consent_required` | An OAuth app has no grant for a workspace yet | Send the author to the link in the problem. |

Failing to authenticate many times from one address in a short time makes that address wait before it is allowed to try again (`rate_limited`).

## Keep keys safe

- Store a key in your server's secret store, never in source control, a mobile app or browser code.
- Give each integration its own key so you can revoke one without breaking the others.
- If a key leaks, revoke it in Developers. Every request it made is listed on the API activity page.
