# Authentication

Authenticate REST API and MCP requests with FineProxy API keys, choose the right scopes and keep keys safe with least privilege, rotation and revocation.

- Canonical: https://fineproxy.org/developers/docs/authentication/

Every request to the FineProxy REST API and the MCP server is authenticated with an API key. This page explains how to create a key, how to send it, which scopes exist and how to limit what a key can do.

## API keys

An API key is a long-lived secret tied to your FineProxy account. It starts with `fb_` and carries an explicit list of [scopes](#scopes): an endpoint or MCP tool works only when the key holds the scope it requires.

### Create a key

1. Sign in to the dashboard and open [Settings → API keys](https://fineproxy.org/account_new/settings#api-keys).
2. Give the key a descriptive name (for example `billing-exporter` or `cursor-agent`) and select its scopes.
3. Copy the key immediately. It is shown **only once**; FineProxy cannot display it again. If you lose it, create a new key and revoke the old one.

> **Important:** Treat an API key like a password. Store it in a secret manager or an environment variable, never in Git, client-side code, screenshots or chat messages.

### Key management is dashboard-only

Keys are created, listed and revoked only from a signed-in dashboard session. The key-management endpoints under `/api/v1/customers/me/api-keys` reject API keys, so a key can never create, list or revoke other keys — even one with every scope:

```bash
curl https://fineproxy.org/account_new/api/v1/customers/me/api-keys \
  -H "Authorization: Bearer $FINEPROXY_API_KEY"
```

The response is `403 Forbidden`. This is expected behavior, not a missing scope:

```json
{
  "detail": "api_key_management_requires_session"
}
```

## Send the key

Pass the key as a bearer token in the `Authorization` header. The same header works for REST endpoints and for the MCP endpoint `https://fineproxy.org/account_new/api/v1/mcp`.

```bash
curl https://fineproxy.org/account_new/api/v1/customer/me \
  -H "Authorization: Bearer $FINEPROXY_API_KEY"
```

```javascript
const response = await fetch('https://fineproxy.org/account_new/api/v1/customer/me', {
  headers: { Authorization: `Bearer ${process.env.FINEPROXY_API_KEY}` },
});
console.log(response.status, await response.json());
```

```python
import os
import requests

response = requests.get(
    "https://fineproxy.org/account_new/api/v1/customer/me",
    headers={"Authorization": f"Bearer {os.environ['FINEPROXY_API_KEY']}"},
    timeout=30,
)
print(response.status_code, response.json())
```

Always send the key in the header. Never put it in URLs or query strings, where it ends up in logs and browser history.

## Authentication errors

Authentication failures return `401 Unauthorized` with a `WWW-Authenticate: Bearer` header and a JSON `detail` string. There are two distinct messages.

The header is missing, or it does not use the `Bearer <api_key>` format:

```json
{
  "detail": "Missing or malformed Authorization header. Expected: Bearer <api_key>."
}
```

The header is well-formed, but the key does not exist or has been revoked:

```json
{
  "detail": "Invalid or revoked API key."
}
```

Do not retry a `401` automatically: fix the header or replace the key. For other error responses, see [Errors](/developers/docs/errors/).

## Scopes

Select only the scopes your integration needs. The same scopes apply to REST endpoints and MCP tools; the [API reference](/developers/docs/api/services/) and the [MCP tools reference](/developers/docs/mcp/tools/) list the scope of every operation.

| Scope | Allows | Example endpoints and tools |
| --- | --- | --- |
| `customer:read` | Read your profile and legacy invoice archive | `GET /api/v1/customer/me`, `GET /api/v1/customer/me/whmcs-invoices`; MCP `get_profile`, `get_my_ip`, `get_access_log` |
| `customer:write` | Update profile fields (`name`, `phone`) | `PATCH /api/v1/customer/me` |
| `catalog:read` | Browse products, countries and prices; get quotes | `GET /api/v1/customer/catalog`; MCP `list_countries`, `get_pricing_info`, `quote_composite`, `quote_dedicated` |
| `services:read` | Read services, IPs, credentials, allowlist, rotating config, sticky settings, refresh quotes | `GET /api/v1/customer/services`, `GET .../proxy/ips`, `GET .../proxy/auth`, `GET .../proxy/config`; MCP `list_services`, `get_proxy_credentials`, `quote_refresh` |
| `services:write` | Change services: allowlist, credentials, sticky settings, renew, cancel, auto-renew | `POST .../proxy/whitelist`, `PUT .../proxy/auth`, `POST .../cancel`; MCP `add_whitelist_ip`, `rotate_proxy_credentials`, `set_auto_renew`, `cancel_service` |
| `usage:read` | Read traffic statistics and diagnostics | `GET .../usage`; MCP `get_usage`, `get_usage_overview`, `get_diagnostics`, `get_recommendations` |
| `wallet:read` | Read balance, ledger, invoices and payment gateways | `GET /api/v1/customer/wallet/balance`, `GET /api/v1/customer/wallet/ledger`; MCP `wallet_balance`, `list_ledger`, `list_invoices` |
| `wallet:deposit` | Start a top-up and track its status (returns a checkout link; no money moves until you pay) | `POST /api/v1/customer/wallet/deposit/init`; MCP `init_deposit`, `get_deposit_status`, `list_payments` |
| `wallet:spend` | **Financial.** Debit the wallet: buy, renew, add IPs, paid IP refresh, add-ons | MCP `order_composite`, `order_dedicated`, `buy_service`, `renew_service`, `add_ips`, `refresh_ips`, `purchase_addon` |
| `tickets:read` | Read support tickets and attachments | `GET /api/v1/customer/tickets`; MCP `list_tickets`, `get_ticket` |
| `tickets:write` | Create, reply to and close tickets | `POST /api/v1/customer/tickets`; MCP `create_ticket`, `reply_ticket`, `close_ticket` |
| `webhooks` | Manage webhook endpoints and deliveries | `/api/v1/customer/webhooks` endpoints |

> **Warning:** `wallet:spend` lets the key spend your wallet balance without further confirmation. Grant it only to keys used by code you control, and always combine purchases with [idempotency keys and price guards](/developers/docs/idempotency/).

Money-spending MCP tools need both `services:write` and `wallet:spend`.

## Least privilege

Create one key per integration rather than one key for everything. Typical setups:

| Use case | Scopes |
| --- | --- |
| Exploring the API, dashboards, monitoring | `customer:read`, `catalog:read`, `services:read`, `usage:read`, `wallet:read` |
| AI agent that answers questions and troubleshoots | The read-only set above, plus `tickets:read` if it should see support history |
| Agent or script that manages the allowlist and credentials | Read-only set plus `services:write` |
| Purchasing automation (buy, renew, add IPs) | `catalog:read`, `services:read`, `services:write`, `wallet:read`, `wallet:spend` — in a separate key |
| Webhook receiver setup | `webhooks` |

Recommendations:

- Give AI agents a **read-only key** first. Add write scopes only when you want the agent to act, and keep `wallet:spend` in a separate key that you enable deliberately.
- Keep the purchasing key on a server you control. Never paste a key with `wallet:spend` into a shared agent configuration or a public repository.
- Name keys after the system that uses them, so you know what breaks when you revoke one.

## Rotate and revoke keys

Rotate keys periodically and immediately if a key may have leaked.

1. Create a new key with the same scopes in [Settings → API keys](https://fineproxy.org/account_new/settings#api-keys).
2. Deploy the new key to your integration and confirm it works.
3. Revoke the old key in the dashboard. Requests that still use it get `401` with `"Invalid or revoked API key."`.

If you suspect a leak, revoke first and create the replacement afterwards. Then review the [ledger](/developers/docs/api/wallet/) and your services for unexpected changes.

## Next steps

- [Conventions](/developers/docs/conventions/) — base URL, money, IDs, timestamps and pagination.
- [Errors](/developers/docs/errors/) — error bodies and how to handle them.
- [Idempotency & price guards](/developers/docs/idempotency/) — spend money safely.
- [MCP server](/developers/docs/mcp/) — use the same key with AI agents.
