# Introduction

> Base URL, authentication, and conventions for the Vectoral API.

The Vectoral API is JSON over HTTPS.

```
https://api.vectoral.cloud
```

Self-hosted deployments use your own base URL (default bind `:8080`).

## Authentication

Every `/v1` endpoint but one authenticates with your **secret key** as a bearer token:

```
Authorization: Bearer vg_live_xxx
```

Keys are `vg_live_` followed by 43 base64url characters, and are shown once at creation —
only a hash is stored. The key resolves server-side to your customer, and everything is
scoped to that customer; there is no way to address another tenant's data.

Auth failures return `401` with the standard error envelope:

| Cause | Body |
| - | - |
| No `Authorization` header, wrong scheme, or not a `vg_live_` key | `{"error": "missing or malformed Authorization: Bearer <api key>"}` |
| Unknown, expired, or revoked key | `{"error": "invalid, expired, or revoked api key"}` |

The one exception is the public browser endpoint
[`/v1/sensor/collect`](https://docs.vectoral.si/api-reference/sensor-collect), which authenticates with your
**publishable site key** (`pk_live_…`) carried in the request body — so it can be
called directly from the browser.

## Errors

Errors use a uniform envelope with the appropriate HTTP status:

```json theme={null}
{ "error": "account_id required" }
```

The message string is for humans and is **not stable** — branch on the status code,
not the text.

| Status | Meaning |
| - | - |
| `400` | Malformed request — invalid JSON, a body over the size cap, or a query parameter outside its allowed values |
| `401` | Missing / malformed / invalid / expired / revoked key |
| `403` | Key valid but not permitted — today only [`/v1/sensor/verify`](https://docs.vectoral.si/api-reference/sensor-verify), for a token minted for another customer |
| `404` | No such resource (e.g. an unknown account on [account detail](https://docs.vectoral.si/api-reference/account-detail.md)), or a route not enabled on this deployment |
| `500` | Server error |

> [!NOTE]
>
> A route that is not enabled on a deployment (for example [`/v1/import`](https://docs.vectoral.si/api-reference/import)
> without its feature flag) is not registered at all. Once your key is accepted it returns
> a **plain-text** `404 page not found`, not the JSON envelope — so don't assume every error
> body parses as JSON. Without a valid key, you get the `401` first.

### Fail-open scoring

[`/v1/score`](https://docs.vectoral.si/api-reference/score) fails **open**: internal failures on our side don't
turn into errors for you. A signal that can't be computed is scored as missing, a failed
write still returns the verdict, and if scoring is unavailable you get a `200` with tier
`low` and reason `scoring_unavailable` — so a Vectoral problem never blocks your users. The
read endpoints and telemetry writes don't fail open: they return `500` and are safe to
retry (with `event_id` on writes).

## Idempotency

Every write endpoint — [`/v1/score`](https://docs.vectoral.si/api-reference/score),
[`/v1/events/post-call`](https://docs.vectoral.si/api-reference/events-post-call),
[`/v1/identity`](https://docs.vectoral.si/api-reference/identity), and [`/v1/labels`](https://docs.vectoral.si/api-reference/labels) —
accepts an optional `event_id`. Send one and a repeat of the same
`(customer, event_id)` writes nothing:

* `/v1/score` replays the **original verdict**, unchanged, with `duplicate: true`.
* The telemetry endpoints return `{ "ok": true, "duplicate": true }`. Spend is not
  double-counted and reputation is not re-accrued.

This makes retries safe, which matters most on post-call telemetry — a retried cost
event would otherwise inflate the account's spend history.

> [!WARNING]
>
> Make `event_id` stable across **your own** retries of the same logical event. Don't
> derive it from a transport message id, which typically changes per delivery attempt
> and would defeat the deduplication entirely.

`duplicate` is omitted when false, so a caller that doesn't send `event_id` sees exactly
the responses it always did.

## Conventions

* **Body cap:** 1 MiB per request; a larger body is a `400`. [`/v1/import`](https://docs.vectoral.si/api-reference/import)
  is the one exception at 8 MiB.
* **Timestamps** are RFC 3339; server-generated ones are UTC.
* **Pagination** on the list endpoints is offset-based: `limit` (default 50, clamped to
  200\) and `offset`, with a `total` of all matches in the response.
* **Additive changes.** Fields may be added to `/v1` without notice — ignore ones you
  don't recognise. Renames, removals, and enum changes ship under a new prefix (`/v2`).
* **`GET /healthz`** is unauthenticated, for load balancers and uptime checks. It returns
  `200` with `{"ok": true, "version": "…"}` (plus `commit` when known) while the database
  is reachable, and `503` with a plain-text `db unreachable` when it isn't.
