Developer guide: 1. Keys and authentication

Key types, scopes, environments, project keys, account keys, sessions versus keys, OAuth apps and the versioning header.

Embed
Preview of the card
<a href="https://lucidace.com/help/developer-guide-keys-and-authentication"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/16c5f883-729a-4d5c-be5a-05e542f5c859/social-card.svg?v=3e7ae33eec8b" alt="Developer guide: 1. Keys and authentication" width="600" height="315"></a>

1. Keys and authentication

Lucida has two kinds of principal: a person (a browser session, cookie lc_session) and a key (a bearer token). Every management call sends Authorization: Bearer <key>. Tenant identity (organization and project) always comes from the key or the URL you are allowed to reach, never from a request body.

Key types

Key

Looks like

Made by

Scope

Can do

Account key

lc_pat_...

POST /v1/me/keys (session only)

all orgs you belong to, or the org_ids you pick

acts as you, capped by its scopes; creates orgs and projects, mints project keys, then uses the project API

Project public key

lc_pk_...

project create, or POST {p}/keys kind:"public"

one project, no scopes

send events and replays, evaluate flags. Safe to ship in a browser

Project secret key

lc_sk_...

POST {p}/keys kind:"secret" with at least one scope (project create mints the public key and a send-only Secret key with ["capture"])

one project

everything a public key does, plus POST /v1/s2s/batch; its scopes also open the management API of that one project. Never ship it

Project personal key

lc_pat_...

POST {p}/keys kind:"personal"

one project, at least one scope

a scoped token bound to a project (for tools that expect a pat)

OAuth access token

lc_oat_...

POST /v1/oauth/token

one project, granted scopes

an app or CLI acting as a user; expires

Secrets are shown once in the create answer; Lucida stores only a SHA-256 hash. A public key's full value stays visible as public_value in GET {p}/keys. Lost a secret: mint a replacement and revoke the old one.

Scopes: GET /v1/scopes

The catalogue has 53 entries: {name, level, resource}. Read access is implied by write for the same resource. Read the live list with curl -sS $LUCIDA_API/v1/scopes | jq -r '.[].name'.

Scope

Opens

*:read

read every project resource except pii:read data; also reads orgs and project settings

*:write

write every project resource including settings, webhooks, transformations; never keys, members, billing, PII, data_catalog*, endpoint:write, pipeline:write

query:read, draft:write

the older broad names: read access to every project resource

insight:read/write

insights, queries, events list, event and property definitions, data-quality, saved queries

notebook:, action:, dashboard:, replay:, flag:, experiment:, cohort:, person:, connector:, settings: read/write

exactly that resource. settings covers tracking plans, transformations, ingest and SDK settings, traffic rules

pii:read

unmasked personal data (person properties, replay ids). No write

data_catalog, data_catalog_approval

propose catalog objects (metrics, table marks, relationships); approve what was proposed

capture

secret keys only: send events and read nothing

endpoint:read/write

run / create-edit query endpoints

pipeline:read/write

data pipeline (transformations, destinations, exports) without project admin

profiles:read

the gateway Profile API (GET /v1/profiles/...) and nothing else

privacy:execute

secret keys may hold it: person erasure (DELETE persons/{id}, persons/bulk_delete) and the Cookie Munch rights executor (/privacy/...), nothing else

project:setup

bundle for provisioning from code: flag:write, experiment:write, cohort:write, action:write and data_catalog (metrics), nothing else (no settings, keys, PII)

admin

acts as org admin on the project: keys, members, access policy, retention, deletion

org:read, org:write

account keys: list and read orgs; create orgs and rename them (write implies read)

project:read, project:write

account keys: list projects and settings; create projects, mint project keys, manage project settings

members:read/write, roles:read/write, audit:read, billing:read, sso:read/write, scim:read/write

org admin API: account key restricted to exactly one org (see section 2). There is no audit:write or billing:write

delegate

send X-Lucida-Actor: <user_id> to act as an org member (chat integrations). Not for secret keys

Rules that always apply:

  • A personal key with scopes:["admin"] acts as a project admin: it can mint, rotate and revoke project keys and it sees person emails unmasked. Give admin only to keys you would trust with a signed-in admin's session.

  • A capture-only key (a secret key whose scopes are only capture, such as the one project create mints) that calls any other route of its own project gets 403 this key can only send events. Another project's routes are 404, as for every key.

  • A key never exceeds its minter. A key minted through an account key can only carry scopes the account key holds. Your org role is also the ceiling, at creation and on every call.

  • A wrong scope on an org route gives 403 naming the scope (for example this key needs the members:write scope). On a project route, a key that lacks the scope gets 404, not 403: Lucida answers 404 for anything the key cannot reach, so a wrong project id and a missing scope look the same. Check the key with GET /v1/keys/self (or GET /v1/me/keys for account keys, GET {p}/keys for project keys) before suspecting the id.

  • An account key can mint a narrower account key with POST /v1/me/keys, only with scopes it holds; an all-orgs admin key can mint any.

  • Erasure key. A server that erases people should hold a key that can do only that: POST /v1/projects/{p}/keys {"kind":"secret","name":"erasure","scopes":["privacy:execute"]}. It allows POST {p}/persons/bulk_delete, DELETE {p}/persons/{id} and the /privacy/* rights routes for that project only. admin also works but is project admin (keys, members, retention), so do not use it for this. Secret keys cannot hold admin or delegate (400).

  • org:*, *:* and admin do not open the org admin routes (members, roles, audit, billing, SSO, SCIM); only the matching area scope does.

Environments

Each project starts with production (default) and development: GET {p}/environments returns {data:[{id,name,is_default}],next_cursor}. A public or secret key may be bound to one environment with environment (its name) at creation; flags and remote config are then served for that environment and events carry it. Default: the project's default environment; in GET {p}/keys an unbound key shows environment: null, which means that default. A name that does not exist, or environment on a personal key, is 400.

Project keys: mint, list, rotate, revoke

Method and path

Scope

Purpose

GET {p}/keys

admin

metadata only, usable keys only (revoked keys too with ?include_revoked=true): id, name, kind, key_prefix, scopes, environment, last_used_at, expires_at, revoked_at, public_value, legacy_read_all; pages with ?limit=&cursor= and answers {data, next_cursor} (next_cursor is null on the last page)

POST {p}/keys

admin or project:write

mint; the answer carries secret once

POST {p}/keys/{key_id}/rotate

admin or project:write

issue a replacement with the same name, kind, scopes, environment and expiry, and revoke the old key at once (rotating a legacy read-all secret key needs *:read on the caller)

DELETE {p}/keys/{key_id}

admin

revoke (204); a second delete is 404

# A server key that reads and writes the project (no admin)
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/keys" \
  -d '{"name":"ci-server","kind":"secret","scopes":["*:read","*:write"],"expires_at":"2027-06-01T00:00:00Z"}' \
  | jq '{id, key_prefix, expires_at, value}'

# A key that can only send events (secret keys with the capture scope read nothing)
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/keys" \
  -d '{"name":"ingest-only","kind":"secret","scopes":["capture"]}' | jq -r .value > ingest.key && chmod 600 ingest.key

# A browser key bound to the development environment
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/keys" \
  -d '{"name":"web-dev","kind":"public","environment":"development"}' | jq '{public_value, environment}'

# Rotate, then revoke
KEY_ID=$(lc "$LUCIDA_API/v1/projects/$PROJECT_ID/keys" | jq -r '.data[] | select(.name=="ci-server") | .id')
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/keys/$KEY_ID/rotate" | jq '{id, secret}'   # 201, new id and secret
lc -X DELETE "$LUCIDA_API/v1/projects/$PROJECT_ID/keys/$KEY_ID" -w '%{http_code}\n'        # 404: rotation already revoked it

Rules verified against the live API:

  • kind is public, secret or personal; anything else is 400 kind must be public, secret or personal.

  • public: scopes forbidden (400 public keys take no scopes).

  • secret: at least one scope. Empty or missing scopes is 400 (secret keys need scopes: ["capture"] to send events only, or read scopes such as ["*:read"], ["flag:read"] or ["profiles:read"]). To send events and read nothing, use ["capture"]. admin and delegate are refused (400).

  • Legacy secret keys. Secret keys minted before this rule, with empty scopes, keep working and still read the whole project. GET {p}/keys marks them legacy_read_all: true (it is false on every other key). Rotate one to a scoped key when you can; no new key is made that way.

  • personal: at least one scope (400 personal keys need at least one scope).

  • Unknown scope names are 400 unknown scope. A missing kind is 422 with errors[].

  • expires_at is RFC 3339; the key stops working at that time (401). A past value is rejected at creation with 400 expires_at must be in the future (project keys and POST /v1/me/keys alike). There is no automatic rotation: schedule rotate yourself.

  • Key names are not unique; use the id.

  • A revoked or rotated-out key answers 401 with detail API key revoked; an expired one, API key expired. A key Lucida has no record of (never issued, or deleted before revocation was kept, 2026-11-12) gets missing or invalid credentials. Every such 401 also carries a machine-readable code member: key_revoked, key_expired or key_unknown, and nothing else differs. GET /v1/me/keys lists your account keys with last_used_at (set on every authenticated call). For a read-only integration mint {"kind":"secret","scopes":["query:read"]}: it reads every project resource through the API and cannot change experiments, flags or settings. Every key create (POST /v1/projects/{id}/keys, POST /v1/me/keys) returns the secret as value; secret is a deprecated copy.

  • last_used_at updates lazily. Use it to find unused keys to revoke.

Which key an integration needs

Integration

Key

Minted with

Browser or app capture, flags

project public key lc_pk_...

project create

Server events (POST /v1/s2s/batch)

project secret key with capture

project create, or POST {p}/keys with an account key

Rights requests (Cookie Munch executor secretKey, erasure handlers)

project secret key with privacy:execute

POST {p}/keys {"kind":"secret","scopes":["privacy:execute"]} with an account key

Creating orgs and projects, minting keys, MCP

account key lc_pat_...

POST /v1/me/keys (a session, or an all-orgs account key holding admin)

A project key cannot mint keys, and a capture-only key refuses everything else with 403 this key can only send events plus the key it needs. When in doubt, ask the key: GET /v1/whoami.

Check a key: GET /v1/keys/self (or GET /v1/whoami)

GET /v1/whoami is the same route under the name other platforms use, on both hosts.

Checking a capture key needs no test event. GET https://capture.lucidace.com/v1/whoami with the key answers 200 with its kind and scopes (a revoked or wrong key: 401) and stores nothing, so no provisioning_check event lands in production data.

A key describes itself, so an integration can verify a key it was handed without guessing from a failing call. It needs no scope: any valid key may read its own description, and it never returns the secret or its hash. A session or a missing key gets 401/404 (a session is not a key). The same path answers on both hosts with the same shape: the API host for account keys and project keys, the capture host for public and secret project keys. A public key answers keys/self only on the capture host; the API host answers it 401.

curl -sS "$LUCIDA_API/v1/keys/self"     -H "Authorization: Bearer $LUCIDA_ACCOUNT_KEY" | jq .
curl -sS "$LUCIDA_CAPTURE/v1/keys/self" -H "Authorization: Bearer lc_sk_..." | jq .

Field

Meaning

kind

public, secret or personal for a project key; account for an account key

scopes

the key's scopes ([] for a public key). An empty list on a secret key means a legacy read-all key

org_ids

account keys: the orgs the key is limited to, or null for every org its owner belongs to. Always null on a project key

project_id

project keys: the project; null on an account key

environment

public and secret keys: the environment the key serves (its binding, else the project default); null for personal and account keys

expires_at

RFC 3339 or null

name, prefix

the key's name and its non-secret prefix

whoami and keys/self are read-only and store nothing, so they are the safe way to see what a key is. For example, to check that a key for rights requests holds privacy:execute, call GET /v1/whoami with it and look for that scope in scopes. Only a key can ask: a session gets 404.

Is this account key still alive: GET /v1/keys/lookup

When all you have is the key's display prefix (a log line, a ticket), ask for its status without the key itself:

curl -sS "$LUCIDA_API/v1/keys/lookup?prefix=lc_pat_AbCd" -H "Authorization: Bearer $LUCIDA_ACCOUNT_KEY" | jq .
  • It needs a session or an account key. The prefix must start with lc_pat_ and have at least 4 characters after it (11 characters in all, at most 64), else 400. A project key gets 404.

  • The answer is {status, revoked_at, created_at, name, owner_email}. status is active, revoked or unknown. unknown also covers a key that belongs to someone else.

  • You see only your own account keys. An instance admin sees any account key, and owner_email is set only for them.

  • An account key's key_prefix (11 characters, for example lc_pat_AbCd) is in each row of GET /v1/me/keys. A longer prefix than the stored one still matches.

Account keys and /v1/me

GET /v1/me works with an account key and returns {user:{id,email,name,created_at,is_disabled}, orgs:[{id,name,slug,plan,ip_capture_default,created_at}], mfa_enabled, passkey_count}; for an account key it also returns key_scopes (the key's own scopes, which the hosted MCP uses to list only the tools they allow) and key_org_ids (the org_ids the key was restricted to; empty when it is not restricted). A restricted key sees only those orgs in orgs. A capture-only project key (secret key with only the capture scope) reads nothing, so GET /v1/me with it is 404. Everything else under /v1/me needs a session.

Method and path

Auth

Purpose

GET /v1/me

key or session

who am I, my orgs

DELETE /v1/me

session

delete my account

PATCH /v1/me/profile

session

name

POST /v1/me/email

session

start an email change (mails a confirmation link to the new address)

POST /v1/me/password

session

change password; signs out every other session

GET, PUT /v1/me/preferences

session

UI and notification preferences

GET /v1/me/keys, POST /v1/me/keys

session, or an all-orgs account key holding admin

list, create account keys (a key grants only scopes it holds). Any other key: 403

POST /v1/me/keys/{key_id}/rotate, DELETE /v1/me/keys/{key_id}

session

rotate (same name, scopes, org list, expiry; old key revoked) or revoke

GET /v1/me/oauth-apps, DELETE /v1/me/oauth-apps/{app_id}

session

apps I authorised; revoke one

An account key is created in the app (Personal settings > API keys) or with a session:

POST /v1/me/keys  {"name":"provisioning","scopes":["org:read","org:write","project:write","*:read","*:write"],"org_ids":[],"expires_at":null}

Never hand an unrestricted account key to an integrator, vendor or any third party. An account key with empty org_ids sees every org of the person who minted it. For a third party, mint a key restricted to their org from a session: POST /v1/me/keys with "org_ids":["<their org id>"] and only the scopes they need. Then check it before you hand it over: GET /v1/orgs with the new key must list exactly one org.

org_ids limits the key to those orgs (each must be one you belong to); empty means all of yours, except that the org admin scopes need exactly one. If you are removed from an org, the key stops seeing it at once (404). The full first-key walkthrough (including the browserless device flow) is in Account API keys.

Sessions versus keys: what only a session can do

Sign-in routes (/v1/auth/signup, login, mfa, passkeys/*, password/*, email/*, sso/*, social/*, logout, sessions) belong to people, not scripts. Cookie-authenticated mutations are checked against CSRF: the Origin header must be the API host or an allowed origin, else 403 (bearer-key requests are exempt). Prefer keys for automation. Session-only actions an agent must hand to the user:

  • create, list, rotate or revoke account keys (/v1/me/keys); delete the account; change password or email; enrol MFA or passkeys

  • delete an org (DELETE /v1/orgs/{org_id}, owner only; a key gets 404); leave an org; impersonate a member

  • billing checkout, portal, spend limits; org domains, IP allow-list, security policy, audit sinks, OAuth apps, trusted IdPs, region pin

  • move a project to another org; create a test project

  • the /v1/instance/* operator routes

OAuth apps and tokens

Use OAuth when an app acts for a user on one project (the CLI, MCP clients, third-party tools). Endpoints (metadata at /.well-known/oauth-authorization-server and /.well-known/oauth-protected-resource, both public):

Method and path

Auth

Purpose

POST /v1/oauth/register

none

dynamic client registration (RFC 7591): {client_name*, redirect_uris, grant_types, scope, token_endpoint_auth_method} returns client_id (lc_oac_...)

GET, POST /v1/oauth/authorize

session

consent screen validation and the user's decision (PKCE S256 required; code lives 10 minutes)

POST /v1/oauth/device_authorization

none

device grant (RFC 8628): form client_id, scope; returns device_code, user_code, verification_uri(_complete), expires_in 600, interval 5

GET, POST /v1/oauth/device

session

the page where the user approves a user_code and picks one project

POST /v1/oauth/token

client

form-encoded. grant_type is authorization_code, refresh_token, urn:ietf:params:oauth:grant-type:device_code or urn:ietf:params:oauth:grant-type:jwt-bearer

POST /v1/oauth/revoke

client

RFC 7009

GET/POST/DELETE /v1/orgs/{org_id}/oauth-apps

session

org-owned registered apps (name*, redirect_uris*, scopes*); GET /v1/me/oauth-apps lists a user's grants

GET/POST/DELETE /v1/orgs/{org_id}/trusted-idps

session

enterprise IdPs trusted for the JWT-bearer (ID-JAG) grant

Access tokens last 1 hour (15 minutes for the JWT-bearer grant); refresh tokens last 30 days and rotate on use (reusing one revokes the whole authorisation). Token errors use RFC 6749 names. Verified live:

R=$(curl -sS -X POST "$LUCIDA_API/v1/oauth/register" -H 'Content-Type: application/json' -d '{
  "client_name":"my-cli","grant_types":["urn:ietf:params:oauth:grant-type:device_code"],
  "token_endpoint_auth_method":"none","scope":"flag:read"}')
CID=$(echo "$R" | jq -r .client_id)
D=$(curl -sS -X POST "$LUCIDA_API/v1/oauth/device_authorization" -d "client_id=$CID&scope=flag:read")
echo "$D" | jq '{user_code, verification_uri_complete, interval}'      # show this to the user
curl -sS -X POST "$LUCIDA_API/v1/oauth/token" \
  -d "grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=$(echo "$D" | jq -r .device_code)&client_id=$CID"
# 400 {"error":"authorization_pending"} until the user approves; then access_token, refresh_token, scope, project_id

An unauthorised call to /mcp answers 401 with a WWW-Authenticate header pointing at /.well-known/oauth-protected-resource.

Versioning header

Send Lucida-Version: YYYY-MM-DD on management calls to pin the API; the response echoes the version served. No header means the newest. A non-date or too-old value is 400; a future date resolves to the newest (verified: 2026-11-01 today). Capture-host routes have a fixed wire format. Details and the deprecation policy (Deprecation and Sunset headers, six months minimum): API versioning.

Updated