Account API keys
Account-level personal API keys act as you across organizations and projects, so a script, an agency tool or an AI agent can create orgs, projects and project keys.
A project key only works inside the project it was created in. An account key belongs to you: it acts as you in every organization and project you can access, limited to the scopes you pick. Use one to provision workspaces from a script, manage client accounts as an agency, or let an AI agent set up a project.
Your first key
There is no key before you have an account: a key never creates a key broader than itself, and the very first one needs a signed-in session. In order:
Sign up and sign in in the app (or
POST /v1/auth/signup, which answers202and emails a confirmation link; see Install Lucida on your site). The app creates your organization and default project, and with it the project's public key (Settings > Project > Keys), which is enough to send events from a browser or app. A secret key is never created for you: mint one when a server needs it, with the scopes it should have (captureto send events only). A secret key with no scopes is refused (400).For anything across projects or organizations, create an account key (
lc_pat_...) under Personal settings > API keys, or withPOST /v1/me/keysfrom the session. The secret is shown once.On the command line, install the CLI, then run
lucida login. It opens the browser (on a machine without one, uselucida login --device, below), you pick one project and approve, and the CLI stores a session for that project in your keychain and renews it on its own. It opens that project only; for anything across projects, give the CLI an account key by settingLC_API_KEYor piping one tolucida login(never a flag); it is checked withGET /v1/orgs, so it needsorg:read. The session or key goes to the OS keychain when there is one (macOSsecurity, Linuxsecret-tool), else to a0600file in your user config directory.LC_API_URL,LC_API_KEYandLC_PROJECT_IDoverride the stored values.
From nothing to a project key with no browser on the machine (CI, SSH)
The machine that needs the key never has to open a browser. You approve the sign-in on any other device (your laptop, your phone), and the terminal finishes by itself. The only browser step on the way is the account's confirmation link, which can be opened on any device too.
1. Create the account (skip if you have one):
curl -sS -X POST https://<your-host>/v1/auth/signup -H 'Content-Type: application/json' \
-d '{"email": "you@example.com", "password": "<a long passphrase>"}'It answers 202 and emails a confirmation link (a deployment with CAPTCHA turned on also needs captcha_token; see GET /v1/auth/config). Open the link on any device; that signs you in there and creates your organization and default project.
2. Start the sign-in on the headless machine:
lucida login --api-url https://<your-host> --deviceIt prints this and waits (nothing else is printed until you approve):
To sign in, open this page in a browser on any device and sign in to Lucida:
https://<your-host>/oauth/device
Then check that the code is WDJB-MJHT and that the client is "Lucida CLI", choose a project and approve.
Only approve if you ran this command yourself.
Or open the link with the code filled in:
https://<your-host>/oauth/device?user_code=WDJB-MJHT
Waiting for approval (expires in 10 minutes)...3. Approve on the other device. Open the link, signed in to Lucida. The page names the app (Lucida CLI), shows the code and every scope it asks for, and warns if the app is not verified. Check the code matches your terminal, untick any scope you do not want to give, choose the one project, and press Approve. Press Deny (or close the page) if you did not start this: whoever gets you to approve a code gets access to that project, which is why the code is only valid for 10 minutes, works once, and the page only accepts a few guesses per minute.
4. The terminal finishes:
logged in to https://<your-host>; token stored in OS keychain(On a server with no keychain it says file /home/<you>/.config/lucida/credentials.json, a 0600 file.) The session is bound to the project you chose, is renewed on its own, and is never printed. If you press Deny, the command ends with sign-in was denied; if nobody approves within the 10 minutes it ends with the code expired before it was approved; run the command again.
5. Create the project key and send it to your secret store:
lucida keys create --name ci --kind secret --scopes '*:read' --project <project-id> --secret-only | gh secret set LUCIDA_API_KEY--secret-only prints just the key on stdout, once; Lucida keeps only its hash, so it cannot be shown again. Without the flag the whole JSON answer is printed (id, name, kind, key_prefix, scopes, value, ...; secret is a deprecated copy of value). The project id is printed by lucida projects list and is the default project of the session, so --project can be left out. Use --kind public (no scopes) for the key the browser SDK ships with.
Creating a key needs project:write, which lucida login asks for: leave it ticked in step 3. A session from before this was added gets a 403, so run lucida login --device again. A key keeps working after the session ends, so revoke it separately. A key can never be broader than the session that creates it. The session holds the scopes you left ticked in step 3, so a session that only holds *:read can create keys with *:read (or a secret key scoped to *:read) and gets 403 for --scopes '*:write', pii:read or anything else it was not granted. Your own role in the project is the ceiling as well. The session cannot create account keys, list or revoke keys, or touch another project (404).
Under the hood (for other CLIs and CI systems): this is the OAuth device authorization grant (RFC 8628). POST /v1/oauth/device_authorization (form: client_id, scope) answers device_code, user_code, verification_uri, verification_uri_complete, expires_in (600) and interval (5). Poll POST /v1/oauth/token with grant_type=urn:ietf:params:oauth:grant-type:device_code, device_code and client_id, no faster than interval. While waiting it answers 400 authorization_pending; polling too fast answers slow_down (add 5 seconds from then on); then expired_token, access_denied or, once, the token response (access_token, refresh_token, scope, project_id). Register a client without a redirect URI first with POST /v1/oauth/register and "grant_types": ["urn:ietf:params:oauth:grant-type:device_code"]; the endpoints are listed in /.well-known/oauth-authorization-server.
Is there a sandbox? There is no separate key-less or throwaway environment. What exists: POST /v1/projects/{project_id}/test-project (signed-in session only) creates a project flagged as a test project, which copies actions, cohorts, flags (disabled), insights and dashboards from the source, copies no events or persons, and is not metered; and lucida demo seed --project <id> fills a project with generated sample events using a secret key. Both still need your own account.
Create one
Open Personal settings > API keys, name the key, tick its scopes and, if you want, tick the organizations it may touch (none ticked means all of yours). The secret (lc_pat_...) is shown once; Lucida stores only its hash. Via the API, with a signed-in session:
POST /v1/me/keys {"name": "provisioning", "scopes": ["org:read", "org:write", "project:write"], "org_ids": []}
GET /v1/me/keys your keys (never the secret)
POST /v1/me/keys/{id}/rotate
DELETE /v1/me/keys/{id}A signed-in session creates account keys, and so can an account key holding admin with no org_ids; a key never grants a scope it does not hold.
Scopes
Scope | Allows |
|---|---|
|
|
|
|
|
|
|
|
| bundle: |
| the usual project scopes, applied to every project you can access |
GET /v1/scopes lists all of them. Project keys created through an account key can only carry scopes the account key itself holds (a key with admin can mint any).
Limits that always apply
Your role is the ceiling. If you are removed from an organization, or leave it, the key stops seeing it immediately (404).
A key restricted to organizations A and B answers 404 for organization C, and cannot create new organizations.
Members, roles, audit, billing, SSO and SCIM are reachable with their own area scope, or with
admin, which opens every org route your role allows: see Org admin API.Revoke a key from the same panel; it stops working at once.
Keys never expire from being idle. A key stops working only when it is revoked, when its
expires_atpasses, or when the account is secured after a takeover check (signing in with Atlas to an account whose email was never verified revokes all of that account's keys and sessions, and writesuser.reclaimedto the audit log of each of the account's organizations). A dead key gets401withdetailAPI key revokedorAPI key expired; a key Lucida never issued getsmissing or invalid credentials.
curl -H "Authorization: Bearer $LUCIDA_ACCOUNT_KEY" https://<your-host>/v1/orgs