API Keys
API key lifecycle management.
Methods on this page are called through client.apikeys.
client.apikeys.create
client.apikeys.create(request: CreateApiKeyRequest, requestOptions?: RequestOptions): Promise<CreateApiKeyResponseShape>Creates a new API key for authenticating with the API. New keys start in ACTIVE status and can be used immediately for authentication. The response includes the one-time raw API key value which will not be retrievable later - clients must save this value as it cannot be recovered. Requires CREATE_APIKEY_OWN permission (or CREATE_APIKEY_ANY for admin users). Side effects include generating cryptographically secure key material, recording creation timestamp, and tracking creator ID. Returns INVALID_ARGUMENT if expires_at is set to a time in the past.
HTTP: POST /v1/apikeys
Parameters
| Parameter | Type | Description |
|---|---|---|
request | CreateApiKeyRequest | Request body. |
requestOptions | RequestOptions optional | Per-call signal, timeout, or headers. |
Returns: Promise<CreateApiKeyResponseShape>
Example
const apiKey = await client.apikeys.create({ labels: { env: "docs" } });
console.log(apiKey.rawApiKey);client.apikeys.delete
client.apikeys.delete(id: string, requestOptions?: RequestOptions): Promise<void>Permanently deletes an API key. This operation cannot be undone and immediately invalidates the key for all future authentication attempts. TIP: For reversible deactivation, use PUT /v1/apikeys/{id} with status=INACTIVE instead. Requires DELETE_APIKEY_OWN permission for keys you own (or DELETE_APIKEY_ANY for admin users to delete any user's keys). Side effects include permanently removing the key record from the database and immediate authentication invalidation.
HTTP: DELETE /v1/apikeys/{id}
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The UUID of the API key to delete |
requestOptions | RequestOptions optional | Per-call signal, timeout, or headers. |
Returns: Promise<void>
Example
await client.apikeys.delete("your-api-key-id");client.apikeys.list
client.apikeys.list(requestOptions?: RequestOptions): Promise<Array<ApiKeyResponseShape>>Retrieves a list of API keys belonging to the authenticated user. The list includes metadata about each key but not the actual key values or key hashes for security reasons. Requires LIST_APIKEY_OWN permission (or LIST_APIKEY_ANY for admin users to view keys from any user). This is a read-only operation with no side effects.
HTTP: GET /v1/apikeys
Parameters
| Parameter | Type | Description |
|---|---|---|
requestOptions | RequestOptions optional | Per-call signal, timeout, or headers. |
Returns: Promise<Array<ApiKeyResponseShape>>
Example
for (const key of await client.apikeys.list()) {
console.log(key.apiKeyId, key.status);
}client.apikeys.update
client.apikeys.update(id: string, request: UpdateApiKeyRequest, requestOptions?: RequestOptions): Promise<ApiKeyResponseShape>Updates an existing API key with new values for status or labels. IMPORTANT: Key ID, user ownership, key material, and audit fields cannot be modified - only status (ACTIVE/INACTIVE) and labels are mutable. Requires UPDATE_APIKEY_OWN permission for keys you own (or UPDATE_APIKEY_ANY for admin users to modify any user's keys). Side effects include updating the updated_at timestamp and recording the updater's user ID. This operation is idempotent - repeated identical requests have no additional effect.
HTTP: PUT /v1/apikeys/{id}
Parameters
| Parameter | Type | Description |
|---|---|---|
id | string | The UUID of the API key to update |
request | UpdateApiKeyRequest | Request body. |
requestOptions | RequestOptions optional | Per-call signal, timeout, or headers. |
Returns: Promise<ApiKeyResponseShape>
Example
const updatedKey = await client.apikeys.update("your-api-key-id", {
status: "INACTIVE",
mergeLabels: { rotated: "true" },
});
console.log(updatedKey.status);Data Models
Interfaces
ApiKeyResponse
API key metadata without sensitive information.
| Field | Type | Required | Description |
|---|---|---|---|
apiKeyId | string | yes | Unique identifier for the API key. |
userId | string | yes | ID of the user that owns this API key. |
keyPrefix | string | yes | First few characters of the key for display/identification purposes. |
status | "STATUS_UNSPECIFIED" | "ACTIVE" | "INACTIVE" | yes | Current status of the API key: ACTIVE, INACTIVE, or STATUS_UNSPECIFIED. |
labels | Record<string, string> | yes | User-defined labels for organization and filtering. |
expiresAt | number | null | no | Expiration timestamp in milliseconds since epoch. If not provided, the key does not expire. |
lastUsedAt | number | null | no | Last time this API key was used, in milliseconds since epoch. |
createdAt | number | yes | When the API key was created, in milliseconds since epoch. |
updatedAt | number | yes | When the API key was last updated, in milliseconds since epoch. |
createdById | string | yes | ID of the user that created this API key. |
updatedById | string | yes | ID of the user that last updated this API key. |
CreateApiKeyRequest
Request parameters for creating a new API key.
| Field | Type | Required | Description |
|---|---|---|---|
labels | Record<string, string> | null | no | Key-value pairs of metadata associated with the API key. Used for organization and filtering. |
expiresAt | number | null | no | Expiration timestamp in milliseconds since epoch. If not provided, the key does not expire. |
apiKeyId | string | null | no | Optional client-provided UUID for idempotent creation. If not provided, server generates a new UUID. Returns ALREADY_EXISTS if ID is already in use. |
CreateApiKeyResponse
Response returned when creating a new API key.
| Field | Type | Required | Description |
|---|---|---|---|
apiKeyMetadata | ApiKeyResponse | no | Metadata for the created API key. |
rawApiKey | string | no | The actual API key value. This is only returned once and cannot be retrieved again. |
ListApiKeysResponse
Response containing a list of API keys.
| Field | Type | Required | Description |
|---|---|---|---|
keys | Array<ApiKeyResponse> | yes | List of API keys belonging to the authenticated user. |
UpdateApiKeyRequest
Request parameters for updating an API key.
| Field | Type | Required | Description |
|---|---|---|---|
status | "ACTIVE" | "INACTIVE" | null | no | New status for the API key. Allowed values: ACTIVE, INACTIVE. |
replaceLabels | Record<string, string> | null | no | Replace all existing labels with this set. Mutually exclusive with mergeLabels. |
mergeLabels | Record<string, string> | null | no | Merge these labels with existing ones. Mutually exclusive with replaceLabels. |
Response Shapes
Response shape types model values returned by the SDK after forward-compatible unknown enum strings are coerced to null.
ApiKeyResponseShape
| Field | Type | Required | Description |
|---|---|---|---|
apiKeyId | string | yes | Unique identifier for the API key. |
userId | string | yes | ID of the user that owns this API key. |
keyPrefix | string | yes | First few characters of the key for display/identification purposes. |
status | "STATUS_UNSPECIFIED" | "ACTIVE" | "INACTIVE" | null | yes | Current status of the API key: ACTIVE, INACTIVE, or STATUS_UNSPECIFIED. |
labels | Record<string, string> | yes | User-defined labels for organization and filtering. |
expiresAt | number | null | no | Expiration timestamp in milliseconds since epoch. If not provided, the key does not expire. |
lastUsedAt | number | null | no | Last time this API key was used, in milliseconds since epoch. |
createdAt | number | yes | When the API key was created, in milliseconds since epoch. |
updatedAt | number | yes | When the API key was last updated, in milliseconds since epoch. |
createdById | string | yes | ID of the user that created this API key. |
updatedById | string | yes | ID of the user that last updated this API key. |
CreateApiKeyResponseShape
| Field | Type | Required | Description |
|---|---|---|---|
apiKeyMetadata | ApiKeyResponseShape | no | Metadata for the created API key. |
rawApiKey | string | no | The actual API key value. This is only returned once and cannot be retrieved again. |
ListApiKeysResponseShape
| Field | Type | Required | Description |
|---|---|---|---|
keys | Array<ApiKeyResponseShape> | yes | List of API keys belonging to the authenticated user. |