# Connect a front end

## Get the three values

In Velora, open **Publication**, then **Overview**. The card **Connect your front end** shows:

| Value | What it is | Keep it |
| --- | --- | --- |
| **Delivery URL** | `https://delivery.velora.build/{site_id}`. Every read starts here. | In your front end's environment, for example `VELORA_DELIVERY_URL` |
| **Read key** | Reads the publication's published content. It also reads a draft, but only with a [signed preview link](https://developers.velora.build/previews.md), and tells Velora your [block list changed](https://developers.velora.build/bodies.md#tell-velora-it-changed). | On your server, for example `VELORA_READ_KEY` |
| **Webhook secret** | Signs the [revalidate webhook](https://developers.velora.build/caching.md#the-revalidate-webhook) and [preview links](https://developers.velora.build/previews.md). | On your server only, for example `VELORA_WEBHOOK_SECRET` |

The same card has **Replace read key** and **Replace webhook secret**, for when one leaks. Velora's API refuses the old one within a minute; answers the edge already holds for the old read key can still be served from its cache for up to an hour. Update your front end's environment straight away.

Two more settings tell Velora where your front end is. Set them once your front end is deployed ([Deploy order](https://developers.velora.build/deploy.md)). They are under **Edit in CMS settings** on the same card:

- **Revalidate URL**, for example `https://your-site.com/api/revalidate`: where Velora sends the [revalidate webhook](https://developers.velora.build/caching.md#the-revalidate-webhook). Velora also reads your [block list](https://developers.velora.build/bodies.md#your-own-blocks) from this URL's origin.
- **Preview URL**, for example `https://your-site.com/api/preview`: where the editor's Preview button sends a [signed preview link](https://developers.velora.build/previews.md).

## Call the API

Every read is a `GET` to the delivery URL plus the route:

```bash
curl -H "Authorization: Bearer $VELORA_READ_KEY" \
  "https://delivery.velora.build/$SITE_ID/articles?limit=3"
```

- Send the read key as `Authorization: Bearer <key>`, or as `?key=<key>`. If you send both, `?key=` wins. Both forms share cache entries at the edge.
- Always call `https://delivery.velora.build`. It is Velora's edge: it keeps answers close to your servers, serves the last good answer if Velora's API is down, and resizes [images](https://developers.velora.build/bodies.md#images). The API behind it does not answer requests that do not come through the edge.
- Only the query parameters a route reads reach the API. Anything else is dropped before the cache, so extra parameters cannot bypass it.
- Answers are JSON, except `/llms.txt`, which is markdown.
- Every answer allows any origin (`Access-Control-Allow-Origin: *`), so a browser can call the API. Read on the server anyway: the key stays private, and your own cache does the work described in [Caching](https://developers.velora.build/caching.md).

## Answers and errors

| Status | Meaning |
| --- | --- |
| `200` | The answer. |
| `404` | Nothing here. A wrong Site id, a wrong read key and a missing article all answer 404, so the three cannot be told apart. Check the key first when everything is 404. |
| `405` | A method other than `GET`, `HEAD` or `OPTIONS`. |
| `422` | A parameter is out of range, for example `limit=500` on a listing. |
| `503` | Velora's API is unreachable and the edge holds no earlier copy of this answer. |

Errors have one shape (`DeliveryError` in the [API reference](https://developers.velora.build/reference.md#deliveryerror)):

```json
{"error": "NOT_FOUND", "detail": "Not found"}
```

Every answer from the edge says how it was served in `X-Velora-Cache`: `HIT`, `MISS`, `STALE` (Velora's API is down and this is the last good copy) or `BYPASS` (never cached, such as a preview).

## Types

[`/openapi.json`](https://developers.velora.build/openapi.json) describes every route and answer. Generate your types from it rather than writing them by hand, for example with `openapi-typescript`:

```bash
bunx openapi-typescript https://developers.velora.build/openapi.json -o velora-api.d.ts
```

The [API reference](https://developers.velora.build/reference.md) is the same document as a page.
