# Authentication

> How to authenticate to the Hollow model API with a Bearer API key: scopes, expiry, rotation, and how to keep the secret out of client code.

## Send your key

Send the key as a Bearer token in the `Authorization` header of every request, on both the OpenAI-compatible and the Anthropic-compatible API.

**The header**

```http
Authorization: Bearer hlw_sk_...
```

A key always starts with `hlw_sk_`. The rest is a long random string, and the start of it is shown on the [Keys](https://platform.projecthollow.com/keys/) page so you can tell your keys apart.

> **Note: Only the Authorization header is read**
>
> The API does not read `x-api-key`. The Anthropic SDKs send their `api_key` option in that header, so give them the key as an auth token instead: `auth_token` in Python, `authToken` in TypeScript. The OpenAI SDKs already send a Bearer token.

## Keys and projects

Create keys on the [Keys](https://platform.projecthollow.com/keys/) page, inside the project that should be charged for what the key spends. A Project is the group that holds keys, limits and usage together.

The model API counts a key's spend against its project and applies the project's own limits, then the key's. A request for a project that is archived or missing is refused. See [Limits](https://platform.projecthollow.com/docs/limits.md).

## Scopes

A key can only do what its scopes allow. Calling a model needs the `models:*` scope, and Platform gives a new key that scope and no other, so a key made for a script cannot be used for anything wider.

**The scope the model API needs**

| Scope | Name | What it allows |
| --- | --- | --- |
| `models:*` | Model proxy | Use Hollow models through the API. It is paid from your prepaid API credit. |

A request whose key lacks the scope is refused with HTTP 403 and the error type `permission_error`.

Other APIs use other scopes. `platform:read` reads usage and cost ([Usage API](https://platform.projecthollow.com/docs/usage-api.md)), and `platform:run` starts published workflows ([Run workflows over the API](https://platform.projecthollow.com/docs/workflow-api.md)). A key that has only one of these scopes cannot call a model.

## Expiry

Choose when a key stops working as you create it: 30 days, 90 days, 1 year or never. A new key starts on 90 days. A key that lasts a fixed time can last at most 365 days; a request with an impossible expiry is refused, not shortened. Never is allowed, and a key that never expires is the one most worth rotating.

Platform tells you in the notification bell 7 days before a key expires and again on the last day. The expiry is fixed when the key is made. A request with an expired key is refused with HTTP 401.

## Rotate a key

Rotate a key before it expires, or whenever you think it may have been seen. Rotation never switches anything off for you.

1. On the [Keys](https://platform.projecthollow.com/keys/) page choose Rotate for the key. Platform makes a new key with the same settings and shows it once.
2. Put the new key wherever the old one is used and deploy.
3. Check on [Usage](https://platform.projecthollow.com/usage/) that the old key has stopped being used.
4. Disable the old key. Platform sets a reminder to do this but never does it for you.

## Disable and delete

- Disable stops a key at once. You do it, and you can undo it with Enable.
- Delete is permanent and asks you to type the key's name. You do it, it cannot be undone, and requests that use a deleted key fail straight away.
- Suspended means Hollow stopped the key, not you, after a sudden spike in spend. Going over the request rate never suspends a key: those requests get HTTP 429 and the key carries on working.
- A disabled or deleted key gets HTTP 401 with the message "This API key has been revoked or suspended." A suspended key gets HTTP 401 with the code `key_suspended` and a message that says when to try again, or that the key owner must re-enable it.

## Keep the secret safe

- The secret is shown once, when the key is made. Hollow keeps only a one-way hash of it, so it cannot be shown again. If you lose it, make a new key.
- **Never put a key in client code**: not in a web page, a mobile app or a desktop app you ship. Anyone can read it. The API accepts requests from a browser, which is exactly why a browser must not hold a key. Call Hollow from your own server and let your server hold the key.
- Read the key from an environment variable or a secret store. Do not commit it, paste it into a chat or a ticket, or print it in logs.
- Make one key for each service and environment, so you can switch one off without breaking the rest.
- Give each key the narrowest scopes and a spend limit that suits the job.
- If a key may have leaked, disable it first, then rotate.

**Read the key from the environment**

**Shell**

```bash
export HOLLOW_API_KEY="paste-your-key-here"
```

**Python**

```python
import os

api_key = os.environ["HOLLOW_API_KEY"]
```

**TypeScript**

```typescript
const apiKey = process.env.HOLLOW_API_KEY;
if (!apiKey) throw new Error("HOLLOW_API_KEY is not set");
```

## Authentication errors

**Errors caused by the key**

| Situation | HTTP status | Error type | Message |
| --- | --- | --- | --- |
| No `Authorization: Bearer` header | 401 | `authentication_error` | Missing API key in Authorization header. |
| The key does not start with `hlw_sk_` | 401 | `authentication_error` | Invalid API key format. |
| The key does not exist | 401 | `authentication_error` | Invalid API key. |
| The key is disabled or deleted | 401 | `authentication_error` | This API key has been revoked or suspended. |
| Hollow suspended the key for unusual spend | 401 | `authentication_error` with the code `key_suspended` | This API key has been suspended for unusual activity. |
| The key has expired | 401 | `authentication_error` | This API key has expired. |
| The key lacks the `models:*` scope | 403 | `permission_error` | This API key does not have the required scope: models:*. |
| The account is not approved for Hollow | 403 | `permission_error` | This account is not approved for Hollow. |

The full list of failures, with which to retry, is in [Errors and status codes](https://platform.projecthollow.com/docs/errors.md).
