import type { ApiKey } from "../_internal/types.gen"; import type { RequestOptions } from "../base-client"; import { RequestBuilder } from "../request-builder"; /** Attributes for creating an API key. */ export type CreateApiKeyAttributes = { name?: string; key_type?: "user" | "application" | "system" | "server"; scopes?: string[]; application_id?: string; tenant_id?: string; user_id?: string; workspace_id?: string; credit_limit?: number; credit_limit_period?: "daily" | "weekly" | "monthly" | "yearly" | "lifetime"; rate_limit_requests?: number; rate_limit_period_seconds?: number; expires_at?: string; token?: string; }; /** Attributes for updating an API key. */ export type UpdateApiKeyAttributes = { name?: string; scopes?: string[]; credit_limit?: number; credit_limit_period?: "daily" | "weekly" | "monthly" | "yearly" | "lifetime"; rate_limit_requests?: number; rate_limit_period_seconds?: number; }; /** API key usage statistics entry. */ export interface ApiKeyUsageStat { api_key_id?: string; request_count?: number; date?: string; [key: string]: unknown; } /** * Manages API keys across all tenants. * * Provides platform-level key administration including allocation of credits, * revocation (with credit reclaim), and rotation (new token, same metadata). * Keys returned are scoped to the actor's authorization level. */ export declare function createApiKeysNamespace(rb: RequestBuilder): { /** * Lists API keys. Supports keyset and offset pagination. * * Returns keys scoped to the actor — users see only their own keys, * ISV owners see keys for their application. * * @param options - Optional request options. * @returns Array of ApiKey objects. * @example * ```typescript * const keys = await admin.apiKeys.list({ page: 1, pageSize: 25 }); * ``` */ list: (options?: { page?: number; pageSize?: number; } & RequestOptions) => Promise; /** * List all API keys by following every page. * @param options - Optional request options. * @returns Complete array of API keys visible to the actor. * @example * ```typescript * const allKeys = await admin.apiKeys.listAll(); * ``` */ listAll: (options?: RequestOptions) => Promise; /** * Fetches a single API key by ID. * * @param id - API key ID. * @param options - Optional request options. * @returns The ApiKey record. * @example * ```typescript * const key = await admin.apiKeys.get("key_123"); * ``` */ get: (id: string, options?: RequestOptions) => Promise; /** * Revokes an API key, setting its status to `revoked` and recording the * revocation timestamp. * * Triggers smart credit reclaim: any unspent credits allocated to this key * are returned to the App Treasury or Tenant Wallet. Prefer this over * hard deletion to preserve the audit trail. * * @param id - API key ID. * @param options - Optional request options. * @returns Updated ApiKey with status `revoked`. * @example * ```typescript * const revoked = await admin.apiKeys.revoke("key_123"); * console.log(revoked.status); * ``` */ revoke: (id: string, options?: RequestOptions) => Promise; /** * Rotates an API key by generating a new token while preserving the key's * ID, metadata, and configuration. * * The new raw token is returned once in the `generated_api_key` field and * cannot be retrieved again. All active sessions using the old token are * immediately invalidated. * * @param id - API key ID. * @param options - Optional request options. * @returns Updated ApiKey with the new token in `generated_api_key`. * @example * ```typescript * const rotated = await admin.apiKeys.rotate("key_123"); * console.log(rotated.generated_api_key); * ``` */ rotate: (id: string, options?: RequestOptions) => Promise; /** * Create a new API key. * @param attributes - Key attributes (name, key_type, scopes, etc.) * @returns Created API key with generated token * @example * ```typescript * const key = await admin.apiKeys.create({ * name: "Operations key", * key_type: "server", * scopes: ["threads:read"], * }); * ``` */ create: (attributes: CreateApiKeyAttributes, options?: RequestOptions) => Promise; /** * Update an API key's configuration. * @param id - API key ID * @param attributes - Attributes to update (name, scopes, rate limits) * @returns Updated API key * @example * ```typescript * const key = await admin.apiKeys.update("key_123", { * scopes: ["threads:read", "threads:write"], * }); * ``` */ update: (id: string, attributes: UpdateApiKeyAttributes, options?: RequestOptions) => Promise; /** * Delete an API key permanently. * @param id - API key ID * @param options - Optional request options * @returns `true` when deletion succeeds * @example * ```typescript * await admin.apiKeys.delete("key_123"); * ``` */ delete: (id: string, options?: RequestOptions) => Promise; /** * Set or remove a credit budget for an API key. * @param id - API key ID * @param creditLimit - Max credits per period (null to remove) * @param creditLimitPeriod - Budget period (null to remove) * @returns Updated API key * @example * ```typescript * await admin.apiKeys.setBudget("key_123", 10_000, "monthly"); * await admin.apiKeys.setBudget("key_123", null, null); * ``` */ setBudget: (id: string, creditLimit: number | null, creditLimitPeriod: "daily" | "weekly" | "monthly" | "yearly" | "lifetime" | null, options?: RequestOptions) => Promise; /** * Get API key usage statistics grouped by key type. * @param options - Optional request options. * @returns Array of usage stat records * @example * ```typescript * const stats = await admin.apiKeys.usageStats(); * ``` */ usageStats: (options?: { page?: number; pageSize?: number; } & RequestOptions) => Promise; /** * Fetch all API key usage-stat pages. Returns an aggregated usage view * across every page — credits used per period, request counts, last-used * timestamps — for ops dashboards or billing reconciliation. * @param options - Optional request options. * @returns Complete array of usage stat records. * @example * ```typescript * const usage = await admin.apiKeys.usageStatsAll(); * const overBudget = usage.filter((u) => u.period_credits_used >= u.credit_limit); * ``` */ usageStatsAll: (options?: RequestOptions) => Promise; /** * List only active (non-revoked) API keys. * @param options - Optional request options. * @returns Array of active API keys * @example * ```typescript * const activeKeys = await admin.apiKeys.active(); * ``` */ active: (options?: { page?: number; pageSize?: number; } & RequestOptions) => Promise; /** * List all active API keys by following every page. * @param options - Optional request options. * @returns Complete array of active API keys. * @example * ```typescript * const allActive = await admin.apiKeys.activeAll(); * ``` */ activeAll: (options?: RequestOptions) => Promise; /** * Reset the budget period for an API key (resets period_credits_used to 0). * @param id - API key ID * @returns Updated API key * @example * ```typescript * const key = await admin.apiKeys.resetBudgetPeriod("key_123"); * ``` */ resetBudgetPeriod: (id: string, options?: RequestOptions) => Promise; }; //# sourceMappingURL=apiKeys.d.ts.map