# Authentication and key safety

Send API keys as bearer tokens\:

```http
Authorization: Bearer sk_...
```

## Get a key

Keys are minted in the Mayarin dashboard, one per environment\:

| Environment | Dashboard                            | API base URL                       |
| ----------- | ------------------------------------ | ---------------------------------- |
| Testnet     | https\://dashboard-testnet.mayarin.xyz | `https://api-testnet.mayarin.xyz` |
| Mainnet     | https\://dashboard.mayarin.xyz         | `https://api.mayarin.xyz`         |

A testnet key is rejected by the mainnet API and vice versa, so an integration keeps two sets of credentials and switches both the key and the base URL together.

1. Sign in to the dashboard for the environment you are integrating against.
2. Open **API keys** in the sidebar. It needs the `settings:manage` permission, so an account without it will not see the menu.
3. Choose **Create key**, name it after the integration that will hold it — one key per integration keeps revocation from taking down everything else.
4. Pick the **Kind**\:
   * **Secret — server-side** (`sk_…`), then tick the permissions it may use. A secret key grants a subset of your own\: `payments:read`, `catalog:manage`, `settings:manage`, `users:manage`, `admin:access`, `refunds:manage`, `disputes:manage`. Grant the fewest that the integration needs. Creating and changing products, payment links, invoices and subscriptions needs `catalog:manage`. Answering a buyer's dispute needs `disputes:manage`, which is separate from `refunds:manage`\: a key that replies cannot move money.
   * **Publishable — browser-safe** (`pk_…`). It carries no permission checkboxes; its surface is fixed.
5. Copy the secret from the dialog and store it in your secret manager or `.env`.

The secret is shown **once**, at creation. Mayarin stores only a hash and cannot recover it — a lost secret means minting a new key and deactivating the old one, which you do from the same page.

Webhook signing secrets are separate and live under **Webhooks**; see [verify webhooks](/guides/webhooks).

## Secret keys

An `sk_` key belongs on a server. It can carry merchant permissions such as catalog management and must never enter HTML, JavaScript bundles, logs, analytics, or source control.

## Publishable keys

A `pk_` key may ship in browser code. It identifies a merchant and reaches only the publishable commerce surface\: the merchant's catalog read and cart checkout. It cannot manage catalog data or authenticate to the dashboard.

The SDK makes the separation explicit\: `@mayarin/sdk` accepts a secret key, while `@mayarin/sdk/browser` has no secret-key field.

## Alert keys

An `ak_` key is read-only and narrower than a publishable key\: it opens one thing, the live [feed of your finished payments](/sdk/typescript/feed), and reaches nothing else. It exists for a livestream overlay, which is a page in a browser source that cannot hold a secret and often cannot set a header, so an alert key may be sent in the URL as `?key=`. Because it can only read that feed, a leak shows an attacker what your overlay already shows, and **deactivating it ends the feed** on its next reconnect. Mint one per overlay, so you can revoke one without touching the others.

A secret key is never accepted in the URL.

If you hand an overlay URL to a streamer, put the key in the URL **fragment**, `https://example.com/overlay#key=ak_…`, and have the page read `location.hash`. A fragment is never sent to a server, so it cannot end up in your own or a CDN's access logs, which a `?key=` in the query can.

## Platform keys

A secret key that holds `merchants:provision` can create merchants of its own and act for them (see [Platforms](/guides/platforms)). Any merchant may grant the permission to its own key, and it is worth a key of its own\: it can create up to 1000 merchants and, as one of them, anything the key's other permissions allow. Keep it on a server, and never in a place a creator can read.

## If a key leaks

Deactivate it from **API keys** in the dashboard and mint a replacement. Every request is checked against the key's active flag, so deactivation takes effect on the next call — mint and deploy the replacement first if the integration is live.

Deactivation is one-way\: a minted secret cannot be un-minted, so there is no reactivation. The replacement is always a new key.
