create() - API keys | Clerk Docs
create()
Creates a new API key for the given user or Organization.
Returns the created APIKey object.
function create(params: CreateAPIKeyParams): Promise<APIKey>
CreateAPIKeyParams
Name
claims?
TypeRecord<string, any> | null
Description
Custom claims to store additional information about the API key.Name
createdBy?
Typestring | null
Description
The user ID of the user who created the API key.Name
description?
Typestring | null
Description
The description of the API key.Name
name
Typestring
Description
A descriptive name for the API key (e.g., "Production API Key", "Development Key").Name
scopes?
Typestring[]
Description
Scopes to limit the API key's access to specific resources.Name
secondsUntilExpiration?
Typenumber | null
Description
The number of seconds until the API key expires. Defaults tonull(never expires).Name
subject
Typestring
Description
The user or Organization ID to associate the API key with.
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.