Auth API
The Auth API provides methods for user authentication and API key management.
Access via client.auth:
const client = new CastariClient({ apiKey: '...' });
const auth = client.auth;
Methods
me()
Get the current authenticated user’s information.
const user = await client.auth.me();
Returns: Promise<User>
Example:
const user = await client.auth.me();
console.log(user.email); // 'user@example.com'
console.log(user.created_at); // '2025-01-15T10:00:00Z'
Response type:
interface User {
id: string;
email: string;
api_key_prefix?: string;
created_at: string;
}
listApiKeys()
List all API keys for the authenticated user.
const keys = await client.auth.listApiKeys();
Returns: Promise<ApiKeyInfo[]>
Example:
const keys = await client.auth.listApiKeys();
for (const key of keys) {
console.log(`${key.name} (${key.prefix}...) - Created: ${key.created_at}`);
}
Response type:
interface ApiKeyInfo {
id: string;
name: string;
prefix: string;
created_at: string;
last_used_at?: string;
}
createApiKey(name?)
Create a new named API key.
const result = await client.auth.createApiKey(name?);
Parameters:
| Name | Type | Required | Description |
|---|
name | string | No | Descriptive name for the key (default: 'Default') |
Returns: Promise<ApiKeyCreateResponse>
Example:
const result = await client.auth.createApiKey('CI/CD Pipeline');
console.log(result.key); // 'cast_xxxxxxxx_xxxxxxxxxx' — save this!
console.log(result.api_key.id); // key ID for future reference
The full API key (result.key) is only returned once at creation. Store it securely.
Response type:
interface ApiKeyCreateResponse {
api_key: ApiKeyInfo;
key: string; // Full API key — only shown once
}
revokeApiKey(keyId?)
Revoke an API key by its ID.
await client.auth.revokeApiKey(keyId?);
Parameters:
| Name | Type | Required | Description |
|---|
keyId | string | No | The ID of the key to revoke |
Returns: Promise<void>
Example:
await client.auth.revokeApiKey('ak_abc123');
See Also