# Authentication

Every customer route takes one credential in the `Authorization` header:

```http
Authorization: Bearer <credential>
```

There are four kinds. The prefix tells them apart; RiskPilot stores only a hash of each, so a lost key cannot be shown
again, only replaced.

<Figure name="auth-options" caption="Four credentials, one header. Each resolves to your account, its package and its limits." />

| Credential | Prefix | Use it for | Reaches |
| --- | --- | --- | --- |
| Live key | `rp_` | Your own servers and scripts | Every customer route |
| Named API key | `rpk_` | One integration each, least privilege | Data routes only, within its scopes |
| Sandbox key | `rpsb_` | Tests against the delayed public sample | `GET /signals` and `GET /signals/{filingId}` |
| Session | `rps_` | Apps and the portal, after a person signs in | Every customer route (team roles apply) |

A wrong, revoked or expired credential answers `401 { "error": "unauthorized" }`. RiskPilot never falls back to
another credential.

## Live key

Each account has exactly one live key. It can do everything a signed-in owner can do through the API: read data,
change the webhook URL, read the webhook signing secret, manage named keys and saved views.

- It is shown once: when the account is created, and when you rotate it.
- **Rotate** it on the portal's **Delivery** page or with `POST /api/v1/customer/delivery/rotate-key` (session or
  live key). The answer `{ "key": "rp_…" }` is the only time the new key is shown; the old one stops working at once.
  The sandbox key does not change.

Because it can change your delivery settings, keep the live key for your own back office and give integrations a
named key instead.

## Named API keys

Named keys (`rpk_…`) are for integrations: one key per system, each with a name, optional **scopes**, and its own
last-used time. A named key **reads data only**: the signals, companies, leaderboard and stream routes. On any
account, billing, delivery, key, usage or saved-view route it gets `403 key_not_allowed`, so a leaked integration key
cannot rotate keys, change the webhook or read the signing secret.

| Scope | Allows |
| --- | --- |
| `signals:read` | `GET /signals`, `GET /signals/{filingId}`, `GET /leaderboard`, the live stream and its ticket |
| `companies:read` | `GET /companies`, `GET /companies/{issuerId}` |
| none ticked | every read scope |

Outside its scopes a key gets `403 key_scope`. The [API reference](/api) shows each operation's scope as
`x-scope`.

Manage keys on the portal's **API → API keys** page, or with a session or the live key:

<CodeTabs>

```bash title="Create"
curl -sS -X POST "$RISKPILOT_URL/api/v1/customer/api-keys" \
  -H "Authorization: Bearer $RISKPILOT_LIVE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Research warehouse", "scopes": ["signals:read"] }'
# 201 { "key": "rpk_…", "item": { "id": "7", "name": "Research warehouse", "prefix": "rpk_1a2b3c4d", "scopes": ["signals:read"], … } }
```

```bash title="List"
curl -sS "$RISKPILOT_URL/api/v1/customer/api-keys" -H "Authorization: Bearer $RISKPILOT_LIVE_KEY"
# 200 { "liveKeyPrefix": "rp_…", "scopes": ["signals:read", "companies:read"], "max": 20, "items": [ … ] }
```

```bash title="Revoke"
curl -sS -X DELETE "$RISKPILOT_URL/api/v1/customer/api-keys/7" -H "Authorization: Bearer $RISKPILOT_LIVE_KEY"
# 200 { "revoked": true, "item": { …, "revokedAt": "2026-11-10T09:12:44.000Z" } }
```

</CodeTabs>

- The key is in the create answer only. Store it in your secret manager straight away.
- An account holds at most 20 active named keys (`409 api_key_limit` past that).
- Revoking works at once and for good; a stream opened with that key closes at its next heartbeat (close code 4401).

## Sandbox key

The sandbox key (`rpsb_…`) is made with your account and shown once, when RiskPilot sets the account up for you
together with the live key; if you do not have one, ask support. It reads only the
two signals routes, which then answer from the public sample (released ACTION and WATCH filed more than 24 hours ago;
see [Introduction](/introduction#the-delayed-sandbox-sample)). It needs no paid subscription, is never metered and
never causes a webhook. Every other route answers `403 sandbox_read_only`. It is not rotated with the live key.

## RSS feed token

Feed readers (and the RSS apps of Slack, Teams and the like) cannot send an `Authorization` header, so the RSS feed
`GET /api/v1/customer/feed.rss?token=…` takes a dedicated feed token (`rpf_…`) in the URL instead. It reads that
one feed and nothing else: it is not a bearer for any other route.

- `POST /customer/feed-token` makes it (`201`) or, when the account already has one, rotates it (`200`); the answer
  carries `token` and the ready `url`, only this once. Rotating stops the old URL at once (`401`).
- `GET /customer/feed-token` shows its `prefix`, `createdAt` and `lastUsedAt`, never the token.
- `DELETE /customer/feed-token` switches the feed off.
- One token per account, stored hashed. Making, rotating and deleting it need a session or the live key (a named key
  gets `403 key_not_allowed`).

The feed holds the same signals as `GET /customer/signals` for your package, newest first, at most 50, and takes the
optional filters `family` / `families`, `class` / `classes`, `minImpact` and `tag` (repeat `class` and `tag`, or give
a comma list). Each item's title is `TICKER · FORM · CLASS · Impact N/5`; the description is the summary with the SEC
link; `link` opens the signal in the portal and an `atom:link rel="related"` points to the filing on SEC EDGAR;
`pubDate` is when the signal was released; the class and the tags are `category` elements. Every fetch counts one
request against your per-minute limit and your daily and monthly quota, like the signal list, so poll every few
minutes at most. A paused or unpaid account gets `403` / `402`.

```bash
curl -sS "$RISKPILOT_URL/api/v1/customer/feed-token" -X POST -H "Authorization: Bearer $RISKPILOT_KEY"
# 201 { "token": "rpf_…", "url": "https://…/api/v1/customer/feed.rss?token=rpf_…", "item": { "prefix": "rpf_1a2b3c4d", … } }
curl -sS "$RISKPILOT_URL/api/v1/customer/feed.rss?token=$FEED_TOKEN&class=ACTION&tag=earnings&tag=m-and-a"
```

## Sessions: signing a person in

Apps that act for a person (the portal, a mobile app, an internal tool) sign the person in and use the returned
**session** (`rps_…`) as their bearer credential. A session lasts 30 days from sign-in; after that the API answers
401 and the person signs in again.

```bash
curl -sS -X POST "$RISKPILOT_URL/api/v1/customer/login" \
  -H "Content-Type: application/json" \
  -d '{ "email": "ops@acme.example", "password": "…" }'
# 200 { "session": "rps_…", "next": "signals" }
# 200 { "session": "rps_…", "next": "signals", "twoFactor": "required" }   when the person has 2FA
```

`next` says where the person should go: `signals`, or `billing` / `checkout` when the account has no paid access yet.

Refusals: `401` wrong email or password; `403 email_unverified` (right password, but the address has not been
confirmed from the mailed link; `POST /customer/verify/resend` sends a new one); `429 throttled` after 8 wrong
passwords for the same address from the same place within 15 minutes.

Sign out with `POST /api/v1/customer/logout` and the session as bearer: the session ends on the server.

### Two-factor sign-in

When the person has two-factor sign-in (TOTP) turned on, or the package requires it, the login answer carries
`"twoFactor": "required"`. That session works for one thing only, for 10 minutes: finishing the sign-in.

```bash
curl -sS -X POST "$RISKPILOT_URL/api/v1/customer/2fa/verify" \
  -H "Authorization: Bearer rps_…" -H "Content-Type: application/json" \
  -d '{ "code": "492817" }'
# 200 { "verified": true, "next": "signals" }   the same session now works for 30 days
```

`code` is the 6-digit code from the authenticator app or one of the person's recovery codes. A wrong code answers
`401 code_invalid`; after 5 wrong codes the session ends (`401 signed_out`) and the person signs in again. Any other
route called with a waiting session answers `401 two_factor_required`.

People turn 2FA on in the portal (**Security**) or with `POST /customer/2fa/setup` and `POST /customer/2fa/enable`
(session only). A package that requires 2FA answers `403 two_factor_setup_required` to a person without it on every
route except the account, sign-out, billing and 2FA set-up routes. Live and named keys are not affected.

### Team members and roles

People added to an account's team sign in at the same `POST /customer/login` with their own email and password and
get their own session. Every route checks the member's role: reading is open to every role; billing and plan routes
need `billing` or `owner`; other changes need `owner`. A refusal is `403 role_forbidden`. `GET /customer/me` tells the
app who is signed in and with which role.

### Sign-in with Google, Microsoft, GitHub and Apple

The portal and the website also sign people in with Google, Microsoft, GitHub and (when configured) Apple. Today that
is a browser flow that ends on the portal. Mobile and desktop apps use the native flow with PKCE through the system
browser and exchange a one-time code for a session at `POST /customer/oauth/native/token`; see
[Mobile apps](/mobile#sign-in-with-google-microsoft-github-or-apple).

### Device sessions for apps

An app turns a fresh sign-in into a device session (`POST /customer/sessions/device`): a 24-hour access token and a
rotating 90-day refresh token (`POST /customer/session/refresh`). People see and end their own sessions with
`GET /customer/sessions`, `DELETE /customer/sessions/{id}` and `POST /customer/sessions/revoke-others`. Details in
[Mobile apps](/mobile#stay-signed-in-device-sessions).

### Routes that need a session

Some account routes act for a person and refuse the live key with `403 session_required`: who is signed in
(`/customer/me`), two-factor sign-in, the team, the data export and account deletion, connecting or removing a
sign-in provider, and, for an account that already has an email or a connected sign-in, setting a first password.

## Which credential where

| Situation | Use |
| --- | --- |
| Nightly import into your warehouse | Named key with `signals:read` (and `companies:read` if you need profiles) |
| Webhook receiver | No credential: you verify the [signature](/webhooks#verify-the-signature) instead |
| Browser dashboard | A session, and a [stream ticket](/stream#from-a-browser) for live updates; never a key in the page |
| Mobile app | A session from `POST /customer/login` (see [Mobile apps](/mobile)), or a named key held by your backend |
| CI tests | The sandbox key |
| A feed reader, or an RSS app in Slack or Teams | The [RSS feed token](#rss-feed-token) in the feed URL |
| Rotating keys, changing the webhook | The live key or a signed-in owner |
