# Authentication

> API keys, how to send them, and how to keep them safe.

Source: https://lernexa.com/docs/developers/language-test/authentication

Every request but the [OpenAPI document](https://api-language-test.lernexa.com/api/v1/openapi.json)
needs an API key, sent in the `Authorization` header:

```http
Authorization: Bearer ltk_YOUR_KEY
```

## Keys

- **Created on the Integrations page** of the staff app, by anyone on your school's staff. A key
  is shown once, when it is created. Lernexa keeps only a hash of it, so a lost key cannot be
  shown again: revoke it and create another.
- **One per system.** Give Zapier its own key, your CRM sync its own. Revoking one then stops only
  that system.
- **Your school's only.** A key reaches your school's tests and nothing else.
- **Last used** shows on the Integrations page, so a key nothing uses any more is easy to spot and
  revoke.
- **Revoking is immediate:** the next request with the key is refused.

## For servers only

Keys are for server-to-server calls: your backend, Zapier, a scheduled job. A web page cannot call
the API with a key, as browsers are not allowed to send one to it. Never put a key in front-end
code or a mobile app.

## When a key is refused

The answer is `401` with a `WWW-Authenticate: Bearer` header:

```json
{ "error": "Send a valid API key, as Authorization: Bearer <key>." }
```

Check the key is sent whole, starts with `ltk_`, and has not been revoked.
