Skip to main content
The API Keys app enables your users to generate and manage API keys for programmatic access to your backend services. API keys provide a secure way to authenticate requests, allowing developers to associate API calls with specific users or teams. Hexclave provides prebuilt UI components so users and teams can manage their own keys.

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 authenticated User (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_keys permission 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.
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.
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:
  1. Open your Hexclave dashboard
  2. Go to Apps
  3. Find and open API Keys
  4. 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
The tab is only shown when apiKeys.enabled.user is on for your project.
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.team is on for your project
  • The current user has the $manage_api_keys permission on the team
Users with the right permission can create, list, and revoke team API keys directly from the team settings interface - no extra code required.

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.
The full plaintext value of an API key is only returned once - at creation time. After that, the SDK only ever exposes value.lastFour. Display, copy, or store the value immediately on creation; it cannot be retrieved later.

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

app/components/create-api-key.tsx

Creating a team API key

Requires the $manage_api_keys team permission.
app/components/create-team-api-key.tsx

Listing API keys

app/components/api-keys-list.tsx
The same pattern works for team API keys via 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 to hexclaveServerApp.getUser({ apiKey }) or hexclaveServerApp.getTeam({ apiKey }) - Hexclave validates it and returns the corresponding object, or null if the key is invalid, expired, or revoked.
app/api/protected/route.ts

Checking an existing key’s validity

When you already hold an ApiKey object (e.g. from useApiKeys()), use its synchronous helpers isValid() and whyInvalid(). The latter returns "manually-revoked", "expired", or null.
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’s manuallyRevokedAt becomes set and isValid() returns false (whyInvalid() returns "manually-revoked").
app/components/revoke-api-key.tsx

Best Practices

  1. 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.
  2. Set sensible expirations. Long-lived keys are convenient but risky. Default to short expirations (30–90 days) and let users rotate.
  3. 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.
  4. Use $manage_api_keys deliberately. Only grant this team permission to roles you’d trust to lock or unlock the entire team’s programmatic access.
  5. Mark public keys with isPublic: true. This opts them out of the secret scanner so your legitimately-public keys don’t get auto-revoked.
  6. Use getUser({ apiKey }) / getTeam({ apiKey }) for validation. Never try to parse or compare the plaintext value yourself - Hexclave handles hashing, expiration, and revocation.