Skip to content

APIKeysManager

API Keys management client

Provides methods for managing API keys for service-to-service authentication. API keys allow external services to authenticate without user credentials.

const client = createClient({ url: 'http://localhost:8080' })
await client.auth.login({ email: 'user@example.com', password: 'password' })
// Create an API key
const { api_key, key } = await client.management.apiKeys.create({
name: 'Production Service',
scopes: ['read:users', 'write:users'],
rate_limit_per_minute: 100
})
// List API keys
const { api_keys } = await client.management.apiKeys.list()

new APIKeysManager(fetch): APIKeysManager

ParameterType
fetchFluxbaseFetch

APIKeysManager

create(request): Promise<CreateAPIKeyResponse>

Create a new API key

ParameterTypeDescription
requestCreateAPIKeyRequestAPI key configuration

Promise<CreateAPIKeyResponse>

Created API key with the full key value (only shown once)

const { api_key, key } = await client.management.apiKeys.create({
name: 'Production Service',
description: 'API key for production service',
scopes: ['read:users', 'write:users'],
rate_limit_per_minute: 100,
expires_at: '2025-12-31T23:59:59Z'
})
// Store the key securely - it won't be shown again
console.log('API Key:', key)

delete(keyId): Promise<DeleteAPIKeyResponse>

Delete an API key

Permanently removes the API key from the system.

ParameterTypeDescription
keyIdstringAPI key ID

Promise<DeleteAPIKeyResponse>

Deletion confirmation

await client.management.apiKeys.delete('key-uuid')
console.log('API key deleted')

get(keyId): Promise<APIKey>

Get a specific API key by ID

ParameterTypeDescription
keyIdstringAPI key ID

Promise<APIKey>

API key details

const apiKey = await client.management.apiKeys.get('key-uuid')
console.log('Last used:', apiKey.last_used_at)

list(): Promise<ListAPIKeysResponse>

List all API keys for the authenticated user

Promise<ListAPIKeysResponse>

List of API keys (without full key values)

const { api_keys, total } = await client.management.apiKeys.list()
api_keys.forEach(key => {
console.log(`${key.name}: ${key.key_prefix}... (expires: ${key.expires_at})`)
})

revoke(keyId): Promise<RevokeAPIKeyResponse>

Revoke an API key

Revoked keys can no longer be used but remain in the system for audit purposes.

ParameterTypeDescription
keyIdstringAPI key ID

Promise<RevokeAPIKeyResponse>

Revocation confirmation

await client.management.apiKeys.revoke('key-uuid')
console.log('API key revoked')

update(keyId, updates): Promise<APIKey>

Update an API key

ParameterTypeDescription
keyIdstringAPI key ID
updatesUpdateAPIKeyRequestFields to update

Promise<APIKey>

Updated API key

const updated = await client.management.apiKeys.update('key-uuid', {
name: 'Updated Name',
rate_limit_per_minute: 200
})