brain/wiki/connections-auth/api-keys.md
Long-lived platform service credentials (prefixed sk-) for machine-to-machine API calls on behalf of a platform. Each key is 64 chars, stored only as a SHA-256 hash — the plaintext is returned once on creation and never again. Gated by platform.plan.apiKeysEnabled (EE/Cloud).
api_key: id, platformId (FK, CASCADE), displayName, hashedValue (SHA-256, looked up every request), truncatedValue (last 4 chars for display), lastUsedAt (updated on each authenticated request).
/v1/api-keys, all platformAdminOnly: POST (create, returns ApiKeyResponseWithValue with raw value once), GET (list, SeekPage without value), DELETE /:id.add (generates key, stores hashed/truncated), getByValue (lookup by SHA-256 hash, updates lastUsedAt — used by auth middleware), list, delete.secureApId(61) + sk- prefix = 64 chars; hashed with cryptoUtils.hashSHA256.Entry point: apiKeyModule, registered on the Fastify app in packages/server/api/src/app/app.ts.
packages/server/api/src/app/ee/api-keys/ — the whole backend slice: module (routes + feature gate), TypeORM entity, servicepackages/server/api/src/app/core/security/v2/authn/ — where getByValue is called to authenticate an incoming keypackages/core/shared/src/lib/ee/api-key/ — shared ApiKey types and request/response contractspackages/web/src/features/platform-admin/api/api-key-api.ts — frontend API clientpackages/web/src/features/platform-admin/hooks/api-key-hooks.ts — React Query hookspackages/web/src/app/routes/platform/security/api-keys/ — platform admin UI page and create dialogPaths verified 2026-07-17.