# Authentication

> Mint an API token and authenticate requests

Source: https://app.relvoerp.com/docs/product/guides/authentication/

The public API authenticates every request with an **organization-scoped API token** — never with the session cookie your browser uses when logged into the Relvo dashboard.

```
Authorization: Bearer rk_live_xxxxxxxxxxxxxxxxxxxx
```

## Getting a token

Mint a token from the **Developer Zone** inside the Relvo dashboard (Settings → Developers → API keys). Only organization OWNER/ADMIN members can issue keys. New hosted sandbox keys use `rk_test_…`; production keys use `rk_live_…`. Existing keys remain valid. The plaintext token is shown **once**, at creation — copy it immediately, Relvo does not store or redisplay it.

A token is bound to a single organization. Every endpoint scopes its results to that organization automatically — there is no `organization_id` parameter to pass, and no way for a token to read or write another organization's data.

## Scopes

The OpenAPI spec declares one security scheme, `BearerAuth` (HTTP bearer, "API Token"). Each operation lists the scopes it accepts in `x-required-scopes`. Your token must hold **any one** of them.

Scopes follow a `resource:action` convention. A `write` scope implies `read` on the same resource, so a token with `contracts:write` can also call endpoints that require `contracts:read`.

| Resource | Scopes |
|---|---|
| Catalog (items, billable metrics, seat metrics) | `catalog:read`, `catalog:write` |
| Prices | `charging:read`, `charging:write` |
| Contracts | `contracts:read`, `contracts:write` |
| Customers, billing entities and taxpayer lookup | `customers:read`, `customers:write` |
| Payment methods | `payment_methods:read`, `payment_methods:write` |
| Payments | `payments:read` |
| Invoices, credit notes, debit notes | `invoices:read`, `invoices:write` |
| Usage events | `usage_events:read`, `usage_events:write`, `usage_events:correct`, `usage_event_volume:read` |
| Billable metric evaluation | `usage_metric_evaluations:read` |
| Seat events | `seat_events:read`, `seat_events:write` |
| Credits | `credits:read`, `credits:write` |
| Unmatched receipts (*pagos sin identificar*) | `reconciliation:read` |
| Reports | `reports:read` |
| FX conversions | `fx:read` |
| Messages | `messages:read` |
| Webhook endpoints | `webhooks:read`, `webhooks:write` |
| Event log | `events:read` |

### Read-only keys: `full_read`

`full_read` grants every `:read` scope in the table above and nothing else. It never passes a write check, so a key holding it cannot create, change, issue or delete anything. Use it for dashboards, BI exports and reporting scripts that read across invoices, usage, customers, contracts, reports and payments.

A `full_read` key also reads resources added later under an existing `:read` scope.

### `full_access`

`full_access` is a wildcard scope that passes every check, writes included. It is convenient for a single internal integration, but it grants everything. Prefer narrowly scoped keys, such as `usage_events:write` alone for a metering-only integration or `full_read` for a dashboard, so that a leaked key can do less damage.

## Example

```bash
curl "https://app.relvoerp.com/api/v1/public/customers?limit=50" \
  -H "Authorization: Bearer rk_live_xxxxxxxxxxxxxxxxxxxx"
```

## Rate limits

Every authenticated request counts against two per-minute limits:

| Limit | Default |
|---|---|
| Per API token | 600 requests per minute |
| Per client IP, across all tokens | 1,200 requests per minute |
| Hosted sandbox, per organization | 300 requests per minute, shared by every key and IP |

Every authenticated response, `429` included, reports the limit that is closer to running out:

| Header | Meaning |
|---|---|
| `RateLimit-Limit` | Requests allowed per window. |
| `RateLimit-Remaining` | Requests left in the current window. |
| `RateLimit-Reset` | **Seconds** until the window frees capacity. It is a delay, not a timestamp. |

When you exceed a limit, Relvo answers `429` with code `rate_limited` and a `Retry-After` header in seconds. Wait that long before retrying. Pace a bulk read by `RateLimit-Remaining` rather than retrying in a tight loop.

List endpoints return 50 items by default and up to 200 with `?limit=200`. Follow `next_cursor` until it is `null`. At 200 items per page, 600 requests per minute reads 120,000 records a minute, so a full dashboard refresh normally takes seconds. If you need a higher per-token limit, contact Relvo support.

## Common auth errors

| Status | `code` and cause |
|---|---|
| `401` | `unauthenticated`: the `Authorization` header is missing or malformed, or the token is invalid. The response carries a `WWW-Authenticate` header. |
| `403` | `insufficient_scope`: the token holds none of the operation's `x-required-scopes`. |
| `403` | `ip_not_allowed`: the caller's IP is not on the token's allow-list. |
| `404` | `not_found`: the resource belongs to another organization, or doesn't exist. |
| `429` | `rate_limited`: the token or IP exceeded its per-minute limit. Retry after `Retry-After` seconds. |
