# Authentication

> How to send your API key, and what happens when it is missing or wrong.

The base address of the API is:

```
https://towers-api.vinsa.dev
```

The public operations [`POST /towers`](https://towers.vinsa.dev/docs/api/build-towers.md), [`POST /placements`](https://towers.vinsa.dev/docs/api/placements.md) and [`POST /recoveries`](https://towers.vinsa.dev/docs/api/recoveries.md) require an API key. Send it with every request in the `Authorization` header:

```sh
curl "https://towers-api.vinsa.dev/api/v1/towers" \
  -H "Authorization: Bearer twr_..." \
  -H "Content-Type: application/json" \
  -d @program.json
```

If your HTTP client makes the `Authorization` header awkward, `X-API-Key: twr_...` is accepted as well. Send one or the other.

## When a key is rejected

A request with no key, an unknown key, or a revoked key gets `401`:

```json
{
  "message": "This API key is not valid or has been revoked.",
  "error": "Unauthorized",
  "statusCode": 401
}
```

| Message | Cause |
| --- | --- |
| `An API key is required. Send it as "Authorization: Bearer <key>".` | No key in either header. |
| `This API key is not valid or has been revoked.` | The key is mistyped, was revoked, or belongs to a different deployment. |

## Call from your server, not the browser

The API is built for server-to-server calls. A key placed in browser code is visible to every visitor, and browsers on other sites are blocked from calling the API in any case. Put the call in your backend and send the result to your page, as shown in the [Next.js](https://towers.vinsa.dev/docs/guides/nextjs.md) and [existing portal](https://towers.vinsa.dev/docs/guides/existing-portal.md) guides.
