Skip to main content

Documentation Index

Fetch the complete documentation index at: https://stackauth-e0affa27-chore-move-mcp-to-a-sep-app.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

ApiKey represents an authentication token that allows programmatic access to your application’s backend. API keys can be associated with individual users or teams. On this page:

ApiKey

API keys provide a way for users to authenticate with your backend services without using their primary credentials. They can be created for individual users or for teams, allowing programmatic access to your application. API keys can be obtained through:

Table of Contents

Properties

Methods


Types

UserApiKey

A type alias for an API key owned by a user.
type UserApiKey = ApiKey<"user", false>;

UserApiKeyFirstView

A type alias for a newly created user API key, which includes the full key value instead of just the last four characters.
type UserApiKeyFirstView = ApiKey<"user", true>;

TeamApiKey

A type alias for an API key owned by a team.
type TeamApiKey = ApiKey<"team", false>;

TeamApiKeyFirstView

A type alias for a newly created team API key, which includes the full key value instead of just the last four characters.
type TeamApiKeyFirstView = ApiKey<"team", true>;

Creation Options

When creating an API key using user.createApiKey() or team.createApiKey(), you need to provide an options object.
description
string
required
A human-readable description of the API key’s purpose.
expiresAt
Date | null
required
The date when the API key will expire. Use null for keys that don’t expire.
isPublic
boolean
Whether the API key is public. Defaults to false. Secret API Keys are monitored by Stack Auth’s secret scanner, which can revoke them if detected in public code repositories. Public API Keys are designed for client-side code where exposure is not a concern.
const user = await stackApp.getUser();

const secretKey = await user.createApiKey({
  description: "Backend integration",
  expiresAt: new Date(Date.now() + 90 * 24 * 60 * 60 * 1000),
  isPublic: false,
});

const publicKey = await user.createApiKey({
  description: "Client-side access",
  expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000),
  isPublic: true,
});