Authentication and API keys
Every request is authenticated with an API key sent as a bearer token. A key belongs to one church and carries only the scopes you give it.
Before you start
- You are an administrator of the church in Lectern, or you can ask one to create a key for you.
Send the key#
Put the key in the Authorization header on every request:
Authorization: Bearer lk_live_...Keys start with lk_live_. Treat the rest as opaque: do not parse it, and do not rely on its length. A key sent in the URL (api_key, access_token or key in the query string) is refused with 400 key_in_url, and a request that carries both a key and a browser session cookie is refused with 400 credential_conflict. Send the key only in the header, and send nothing else for authentication.
Create a key#
- In Lectern, open Integrations & export, then the API keys tab.
- Choose Create API key and give it a name your team will recognise, such as “Website sync”.
- Tick the scopes the key needs and nothing more.
- Optionally set an expiry, a requests-per-minute limit, daily and monthly spend caps, a monthly limit of submitted teachings, and an IP allowlist.
- Copy the secret. It is shown once. Lectern stores only a hash, so it cannot show it again.
Create a separate key for each integration. If one leaks you revoke it without breaking the others, and each key’s usage and spend are reported separately.
Scopes#
A scope allows a group of routes. A route called without its scope answers 403 insufficient_scope, and the message names the scope it needed.
| Scope | Allows | Uses AI budget |
|---|---|---|
teachings:read | List and read teachings, transcripts, series and teachers, and search. | No |
teachings:ingest | Add a teaching from a link and upload recordings and transcript files. Also lets the key see teachings that are still being prepared. | Yes, when a teaching is processed |
notes:read | Read approved notes, and embed the latest note in a teaching. | No |
notes:generate | Queue a draft note and read drafts with status=latest. | Yes |
ask:use | Ask questions and read the conversations the key started. | Yes |
scripture:read | Read the Scripture citations found in approved notes. | No |
webhooks:manage | Create, change, test, rotate and delete webhook endpoints, and read their deliveries. | No |
A key with only read scopes sees teachings that have an approved note, and approved notes. Keys with teachings:ingest or notes:generate can also see teachings that are still being prepared, because they are the ones putting them there.
Limits on a key#
| Setting | What it does |
|---|---|
Expiry | The key stops working on that date. A key can last up to two years. |
| Requests per minute | Default 60, up to 3,000. See Rate limits. |
| Daily and monthly spend caps | Stop AI work for the key once its spend for the day or month reaches the cap. Requests that would start more work answer 429. Reading is never blocked by a spend cap. |
| Monthly teaching limit | The most teachings the key may submit in a month. |
| IP allowlist | Up to 20 addresses or ranges (CIDR) the key may be used from. A request from anywhere else answers 403 ip_not_allowed. The address is the one Lectern’s own proxy reports for the connection; a client cannot change it by sending an X-Forwarded-For header. |
GET /usage shows the calling key’s scopes, limits, and the last 30 days of requests, errors and AI spend. It works with any scope, which makes it the best first call when you test a new key.
curl "$LECTERN_BASE_URL/v1/api/o/$LECTERN_SLUG/usage" \
-H "Authorization: Bearer $LECTERN_API_KEY"Rotate a key#
Rotate a key from the same screen. Rotation issues a new secret and keeps the old one working for a grace period so you can deploy without downtime: 24 hours by default, up to 7 days. After the grace period the old secret stops working.
- Rotate the key and copy the new secret.
- Deploy the new secret to your servers.
- Check
GET /usagewith the new key. The old secret stops working when the grace period ends;previous_key_valid_untilin the response says when.
Revoke a key#
Revoke a key if it may have leaked or is no longer needed. Revocation takes effect within a few seconds. Requests with a revoked, expired or unknown key answer 401 invalid_api_key.
Key hygiene#
- Keep keys in a secrets manager or environment variables. Never commit them, log them, or paste them into chat or tickets.
- Never ship a key in a web page, mobile app, browser extension or desktop app that your users install. Call Lectern from your server and give your front end the results.
- Give each key the fewest scopes and the shortest expiry that fit the job, and an IP allowlist when your servers have fixed addresses.
- Watch each key’s usage in Lectern. A spike you cannot explain is a reason to rotate.
- Rotate on a schedule, and immediately when someone with access leaves.
Revoke it in Lectern, create a new one, and check GET /usage for requests you do not recognise. Nothing else needs to change: webhook secrets are separate from API keys.
The church in the URL#
A key works for one church. Every route includes that church’s slug: /v1/api/o/{slug}/.... Any other slug answers 404, the same as a church that does not exist, so a key can never be used to discover another church.