Authentication¶
Pagelore protects its API with API keys. Each key has a scope and can be limited to some projects. Authentication is off by default, so a local install works without keys. Turn it on before the API can be reached from other machines.
When it is off, anyone who can reach the API can use all of it, and the app logs a warning at startup.
Turn it on¶
-
Generate an admin key of at least 32 characters:
-
Set both settings in
src/.env, or indocker/env/.env.appfor Docker: -
Apply the migration that creates the
api_keystable (alembic upgrade head; the Docker image does this when it starts). See Database migrations. Then restart the app.
From then on, every request needs a key in one of two headers:
curl -H "Authorization: Bearer $PAGELORE_KEY" http://localhost:8000/api/v1/projects
curl -H "X-API-Key: $PAGELORE_KEY" http://localhost:8000/api/v1/projects
GET /api/v1/ and GET /api/v1/health (the health checks) and the /docs page stay public. On
/docs, click Authorize to send a key with every request you try.
Startup fails when no one could get in
With AUTH_ENABLED=true, the app refuses to start if ADMIN_API_KEY is
shorter than 32 characters, or if it is empty and the database has no
admin key that is still valid.
The ADMIN_API_KEY¶
The ADMIN_API_KEY has the admin scope and can use every project. It is
read from the environment and never stored in the database. Use it to
create the keys your apps will use.
Once you have created an admin key with the API, you can remove
ADMIN_API_KEY. The app keeps starting as long as an admin key in the
database is valid. Keeping it set is also fine: it is your way back in if
every admin key is deleted or expires.
Create keys¶
curl -X POST http://localhost:8000/api/v1/auth/keys \
-H "Authorization: Bearer $ADMIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{"name": "chat-app", "scope": "read", "project_ids": [1, 2], "expires_in_days": 90}'
{
"id": 1,
"name": "chat-app",
"prefix": "pl_Xq3v9KcA",
"scope": "read",
"project_ids": [1, 2],
"created_at": "2026-11-29T18:00:00Z",
"expires_at": "2027-02-27T18:00:00Z",
"last_used_at": null,
"expired": false,
"key": "pl_Xq3v9KcA..."
}
The key is shown only in this response. Only its SHA-256 hash is
stored, so it can't be shown again. If it is lost, delete the key and
create a new one. The prefix helps you tell keys apart in lists.
| Field | Default | |
|---|---|---|
name |
required | What the key is for, up to 128 characters |
scope |
read |
read, write or admin (see below) |
project_ids |
every project | Limit the key to these projects. Not allowed for admin keys |
expires_in_days |
never | 1 to 3650 days |
user_id |
none | Bind a read key to one user, so it only sees that user's documents (see below) |
Scopes¶
Each scope includes the ones before it.
| Scope | Can |
|---|---|
read |
Every GET, plus retrieval (POST /projects/{id}/retrieve, POST /retrieve), POST /rerank and POST /embeddings |
write |
Also create, change and delete projects and documents, cancel background jobs, and use the LLM, evaluation and preview endpoints |
admin |
Also manage API keys (/auth/keys) and use the raw vector DB API (/vectordb), which isn't tied to projects |
An app that only searches needs a read key. Use write for the service
that adds documents.
Keys limited to projects¶
A key with project_ids can only use those projects:
- Requests to any other
/projects/{id}/...path get 403, even when that project doesn't exist, so a key can't find out which projects exist. GET /projectslists only its projects.POST /retrievereturns 403 ifproject_idsincludes another project.- It can't create projects (
POST /projectsreturns 403).
Use this to give each tenant or app a key that sees only its own documents.
Keys bound to a user¶
A read key created with user_id acts as that user: retrieval and the
document endpoints show only the documents whose
access list lets the user in, with the user's stored
groups. A request that sends another user, or any groups, gets 403, and
the job endpoints aren't available to it. Use it for a key that sits in an
end user's app. A back end that serves many users can instead keep one key
and send user with each request.
Manage keys¶
All of these need an admin key.
| Endpoint | |
|---|---|
POST /auth/keys |
Create a key (201). The response has the key itself, shown once |
GET /auth/keys |
List keys, newest first (page, page_size), without the keys themselves |
GET /auth/keys/{id} |
One key: its scope, projects, expiry and last_used_at |
DELETE /auth/keys/{id} |
Revoke a key (204). Requests with it fail at once |
GET /auth/me |
Any key: what the current key can do |
last_used_at is updated at most once a minute. A key past its
expires_at gets 401 and is listed with expired: true until you delete
it.
Errors¶
| Status | When |
|---|---|
| 401 | No key, an unknown or revoked key, or an expired one. The response has WWW-Authenticate: Bearer |
| 403 | The key's scope is too low for the endpoint, it can't use that project, or it is bound to a user and sent another identity |
Good practice¶
- Serve the API over HTTPS (a reverse proxy in front of it), so keys aren't sent in plain text.
- Give each app its own key, with the lowest scope it needs, so you can revoke one without breaking the others.
- Keep keys in a secret store or environment variables, not in code.
- Set
expires_in_daysfor keys given to people or to other teams.