# API keys

URL: https://doc.securepayapi.com/api-keys
Last updated: 2026-11-12

> How publishable and secret keys work, where to use each, and how to keep them safe.

Your account has two API keys. Find and manage them in the
[**Developer**](https://app.securepayapi.com/developer) section of your
dashboard.

| Key | Prefix | Use it | Where |
| --- | --- | --- | --- |
| Publishable (shown as **Client key** in the dashboard) | `sp_client_…` | Identify your account in the browser | Front-end / embed widget |
| Secret | `sp_secret_…` | Authenticate API calls — create and read Payment Intents, manage subscription plans and agreements, read transactions | Server only |

A new account has no keys until you click **Generate API keys**; that creates
both. Each key is 42 characters: the prefix and 32 letters and digits
(`A–Z`, `a–z`, `0–9`). The same
pair serves **live and sandbox**: there are no separate test keys — the
environment is chosen by the `mode` of each Payment Intent or by the product.
Keys stop working while the account is not active: the Payment Intents and
subscriptions API answers `401 invalid_api_key`, the transactions API `403`.

## Publishable key

The publishable key is safe to include in client-side code. It tells the
checkout widget which account a payment belongs to:

```html
<iframe src="https://checkout.securepayapi.com/embed?pk=sp_client_…"></iframe>
```

## Secret key

The secret key authorizes server-side API calls, such as creating a payment.
Send it as a Bearer token (the word `Bearer` is matched case-insensitively):

```bash
curl https://checkout.securepayapi.com/api/v1/payment-intents \
  -H "Authorization: Bearer sp_secret_…" \
  -H "Content-Type: application/json" \
  -d '{ "amount": 2000, "currency": "USD" }'
```

> **Warning:**
Never expose your secret key in front-end code, a public repository, or a mobile
app. Anyone with it can create payments on your account. Keep it in server-side
environment variables only.

A missing header answers `401` with code `missing_api_key`; a key that is
wrong, rotated away or belongs to an inactive account answers `401`
`invalid_api_key` (see [Errors](https://doc.securepayapi.com/api-reference#errors)).

Unlike the webhook signing secret, the secret key stays readable in the
Developer section — you can copy it again later.

## Rotating keys

You can regenerate either key from the
[Developer section](https://app.securepayapi.com/developer) at any time. Regenerating
immediately invalidates the old key, so update your integration before rotating
in production. Regenerating the **publishable** key also breaks every embedded
widget still loading `/embed?pk=<old key>` — it answers 404 until your pages
carry the new key.

## Keeping keys safe

- Store the secret key in environment variables, not in code.
- Keep it out of version control, logs and client-side bundles.
- Rotate a key right away if you suspect it has leaked.
