Concepts
The authentication flow
A user or client sends an API request with an API key to your application server. Your server validates the API key with Hexclave, which returns an authenticatedUser (or Team) object. Your server then processes the request and returns the response.
Two kinds of API keys
Hexclave supports two kinds of API keys:- User API keys - associated with an individual user; calls authenticated with this key act on behalf of that user.
- Team API keys - associated with a team; calls authenticated with this key act on behalf of that team. Only users with the
$manage_api_keyspermission for the team can create or revoke them.
Don’t confuse API Keys with Project Keys. The API Keys app documented here lets your end users issue keys for their accounts and teams. If you want to create or rotate the publishable / secret keys that your Hexclave project uses to call the Hexclave API, that lives in Project Settings → Project Keys instead.
User API keys
User API keys are associated with individual users and allow them to authenticate with your API.- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/create-api-key.tsx
Team API keys
Team API keys are associated with teams and can be used to provide access to team resources over your API.- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/create-team-api-key.tsx
Enabling the API Keys App
To use API keys in your application, you must enable the API Keys app in your Hexclave dashboard:- Open your Hexclave dashboard
- Go to Apps
- Find and open API Keys
- Click Enable
Dashboard settings
Once enabled, the API Keys app exposes exactly two toggles under API Key Settings:
Both are disabled by default. Changes require clicking Save before they take effect.
Toggling User API Keys controls whether the
<AccountSettings> component shows its API Keys tab. Toggling Team API Keys controls whether the team settings page shows its API Keys section to users with the $manage_api_keys permission.
Team permission requirement
Creating, listing, and revoking team API keys requires the$manage_api_keys permission on the team. Make sure your team roles grant this permission to the right members (e.g. admins).
Prebuilt UI Components
Hexclave provides prebuilt UI components that let your users manage their own API keys without any additional code.User API Keys UI
For frameworks that support React components, the<AccountSettings> component includes an API Keys tab where users can:
- View all their active API keys
- Create new API keys with a description and an expiration date
- Revoke existing API keys
- See when each key was created and when it expires
apiKeys.enabled.user is on for your project.
- Next.js
- React
app/account/page.tsx
Team API Keys UI
The team settings page automatically includes an API Keys section when all of the following are true:- The API Keys app is enabled
apiKeys.enabled.teamis on for your project- The current user has the
$manage_api_keyspermission on the team
The ApiKey object
Both user.listApiKeys() and team.listApiKeys() return arrays of ApiKey objects. The same shape comes back from user.createApiKey(...) / team.createApiKey(...), except the value is the full plaintext key only on the first view.
isPublic keys
When creating a key, pass isPublic: true to exempt it from Hexclave’s secret scanner. The secret scanner automatically revokes API keys it detects in public places (e.g. exposed in a GitHub repo). Use isPublic only for keys that are intentionally exposed to clients (e.g. anonymous-style access tokens).
Working with API Keys
Creating a user API key
- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/create-api-key.tsx
Creating a team API key
Requires the$manage_api_keys team permission.
- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/create-team-api-key.tsx
Listing API keys
- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/api-keys-list.tsx
team.useApiKeys() (client) or team.listApiKeys() (server), and the /api/v1/team-api-keys REST endpoint.
Validating an incoming API key on your server
This is the core authentication flow: an incoming request includes an API key, and your server needs to know which user or team it represents. Pass the plaintext key directly tohexclaveServerApp.getUser({ apiKey }) or hexclaveServerApp.getTeam({ apiKey }) - Hexclave validates it and returns the corresponding object, or null if the key is invalid, expired, or revoked.
- Next.js Server
- Team key (Next.js Server)
- Django
- FastAPI
- Flask
app/api/protected/route.ts
Checking an existing key’s validity
When you already hold anApiKey object (e.g. from useApiKeys()), use its synchronous helpers isValid() and whyInvalid(). The latter returns "manually-revoked", "expired", or null.
- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/check-api-key.tsx
Revoking an API key
API keys can be revoked when they are no longer needed or if they have been compromised. Revoking is irreversible: a revoked key’smanuallyRevokedAt becomes set and isValid() returns false (whyInvalid() returns "manually-revoked").
- Next.js Client
- Next.js Server
- React
- Django
- FastAPI
- Flask
app/components/revoke-api-key.tsx
Best Practices
- Show the value once. API key values are returned in plaintext only at creation. Always display, copy, or send them immediately - don’t expect to fetch them again later.
- Set sensible expirations. Long-lived keys are convenient but risky. Default to short expirations (30–90 days) and let users rotate.
- Don’t share user keys across users. A user API key acts as that exact user. If a service needs to act independently, prefer a team API key with a service-style role.
- Use
$manage_api_keysdeliberately. Only grant this team permission to roles you’d trust to lock or unlock the entire team’s programmatic access. - Mark public keys with
isPublic: true. This opts them out of the secret scanner so your legitimately-public keys don’t get auto-revoked. - Use
getUser({ apiKey })/getTeam({ apiKey })for validation. Never try to parse or compare the plaintext value yourself - Hexclave handles hashing, expiration, and revocation.