create() - API keys | Clerk Docs

create()

  1. CreateAPIKeyParams
  2. Usage
    1. Create a basic API key
    2. Create an API key with optional parameters
    3. Backend API (BAPI) endpoint

Creates a new API key for the given user or Organization.

Returns the created APIKey object.

function create(params: CreateAPIKeyParams): Promise<APIKey>

CreateAPIKeyParams

Usage

Create a basic API key

const userId = 'user_123'

const apiKey = await clerkClient.apiKeys.create({
  name: 'My API Key',
  subject: userId,
})

Create an API key with optional parameters

const userId = 'user_123'

const apiKey = await clerkClient.apiKeys.create({
  name: 'Production API Key',
  subject: userId,
  description: 'API key for accessing my application',
  scopes: ['read:users', 'write:users'],
  secondsUntilExpiration: 86400, // expires in 24 hours
})

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/api_keys. See the BAPI reference for more information.