# Keys and security (/docs/keys)

## Secret keys [#secret-keys]

Every API request is authenticated with a secret key as a bearer token:

```http
Authorization: Bearer sk_test_...
```

- `sk_test_…` keys use test mode and `sk_live_…` keys use live mode. See [Testing](/docs/testing).
- Create and revoke keys in the dashboard under **Developers → API keys**. A key is shown once, when you create it; RunePay stores only a hash.
- A missing, unknown or revoked key gets `401 invalid_api_key`.

## Keep them on your server [#keep-them-on-your-server]

A secret key can create checkouts, issue refunds and read your payments and payouts. Treat it like a password:

- **Never put it in a browser, mobile app or public repository.** The API sends no CORS headers, so browsers can't call it anyway: create checkout sessions from your server and redirect the buyer to the hosted page.
- Store it in your platform's secret manager or an environment variable, not in code.
- Give each system its own key, so you can revoke one without touching the others.

## Rotate a key [#rotate-a-key]

There is no in-place roll. To rotate: create a new secret key, deploy it, check that requests succeed with it (the dashboard shows each key's last use), then revoke the old one. Revoking is immediate.

If a key leaks, revoke it straight away and create a new one.

## Publishable keys [#publishable-keys]

The dashboard can still create publishable keys (`pk_test_…`, `pk_live_…`), but nothing uses them: every API endpoint refuses them with `403 secret_key_required`. They are kept for a future embedded checkout. You don't need one.

<Callout title="Planned" type="warn">
**Restricted keys** (`rk_test_…`, `rk_live_…`) limited to scopes such as `checkout_sessions:write` or `payments:read` are planned, with a preset for e-commerce plugins. Each endpoint's scope is already in the [OpenAPI spec](/openapi/runepay-v1.json) as `x-runepay-scope`. Until they ship, every secret key has full access to its mode.
</Callout>

## Webhook secrets [#webhook-secrets]

Each webhook endpoint has its own signing secret (`whsec_…`), separate from API keys. See [verifying signatures](/docs/webhooks#verify-the-signature) and [rotating the secret](/docs/webhooks#rotate-the-secret).