# Keys and authentication

Source: https://smartpdf.ru/en/developers/docs/auth

## Key in a header

Every API request must include the key in one of these headers:

```bash
curl https://api.smartpdf.ru/v1/api-keys/balance -H "X-API-Key: $SMARTPDF_API_KEY"
# or
curl https://api.smartpdf.ru/v1/api-keys/balance -H "Authorization: Bearer $SMARTPDF_API_KEY"
```

The response is the account balance:

```json
{
  "balance": "299.75",
  "spent_month": "0.25",
  "request_price": "0.25",
  "request_unit_mb": 10,
  "included_limit": 0,
  "included_used": 0,
  "included_remaining": 0,
  "included_resets_at": null
}
```

`included_*` are the requests included in the Business plan (500 a month from the purchase date); on other plans they’re 0.

Without a key or with an invalid key, the API responds with `401`.

## Managing keys

Keys are created and changed only in your dashboard, in the [“API and MCP”](https://smartpdf.ru/en/dashboard/api-keys) section: an API key can’t be used to manage keys, otherwise a key with a limit could remove that limit itself.

- **Create** — the secret is shown only once, so save it right away.
- **Regenerate** — you get a new secret, and the old one stops working immediately; the name, limit and operation history are kept.
- **Delete** — the key stops working; the account balance and history don’t change.

## Spending limit per key

Each key can have a limit in rubles and a reset period: never (a lifetime limit), daily, weekly or monthly, in UTC. When the limit is used up, requests with this key get `402` with an explanation, while other keys keep working. This makes it easy to give each integration or contractor a separate key.

## Keep your key secret

Store the key in an environment variable or a secrets manager, not in code. Don’t pass it in the request URL. If the key leaks, regenerate it in your dashboard.
