# Authentication

Server-to-server calls use an API key as a bearer token. Its scopes are fixed when it is created and never exceed the permissions of the person who created it.


## API keys

Send the whole secret as a bearer token:

```http
GET /v1/me HTTP/1.1
Host: sandbox-api.payezy.io
Authorization: Bearer pz_test_pk9xk2m4_4f1c...
```

A key looks like `pz_test_<id>_<secret>` in the sandbox and `pz_live_<id>_<secret>` in production. Payezy stores only an HMAC of the secret, so it is shown once.

- **Created by a person.** A signed-in member with `api_keys:manage` creates keys on the Developer page, with a second factor. An API key can never create, roll or revoke keys.
- **Scopes.** Omit `scopes` and the key gets the read-only scopes its creator holds. A scope the creator does not hold is rejected, and `platform:view_as` can never go on a key. See [roles and permissions](/concepts/roles-and-permissions/) for the list.
- **Expiry.** Keys with a write scope default to 90 days, read-only keys to 365. None lasts more than a year.
- **IP allowlist.** Up to 20 CIDR ranges. Empty means any address. Use one for every production key.
- **Rotation.** Roll a key to mint a replacement; the old secret keeps working for the overlap you choose, at most 72 hours. Revoke ends a key immediately.

> **A key replaces step-up**
In the app, moving money needs a recent second factor. A key with the right scope replaces that step, which is why keys belong only on servers.

## Keys a platform mints for its customers

A platform with `platform:customer_keys` mints an ordinary customer key for each linked customer, then calls the customer API with that key alone. Money, team and approval scopes are opt-in. These keys record `source=platform_api` and your platform id on every action, and are revoked if you unlink the customer. See [customer keys](/guides/customer-keys/).

## Other credentials

| Credential | Who uses it | Notes |
| --- | --- | --- |
| `payezy_session` cookie | The Payezy app in a browser | Not an API key. Pasting a key into the cookie field returns 401. |
| View-as token | A platform or staff member acting for a customer | Short-lived JWT from `POST /v1/platforms/{orgId}/customers/{customerId}/view-as` (Start a view-as session). API keys cannot open view-as. |

## Status codes

`401` means no valid credential. `403` means the credential is valid but not allowed: a missing scope (`scope_not_held`), a revoked production grant (`api_access_revoked`) or an IP outside the allowlist (`ip_not_allowed`). `404` also covers "not yours", so ids cannot be probed.
