API Keys hooks
React hooks for API keys — list, get, create, delete.
Usage
import Aeontel from "@aeontel/sdk";
import { AeontelProvider, useListApiKeys } from "@aeontel/react";
const client = new Aeontel(import.meta.env.VITE_AEONTEL_API_KEY);
function App() {
return (
<AeontelProvider client={client}>
<ApiKeysList workspaceId="wsp_abc123" />
</AeontelProvider>
);
}
function ApiKeysList({ workspaceId }: { workspaceId: string }) {
const { data, isLoading } = useListApiKeys({ workspace_id: workspaceId });
if (isLoading) return <p>Loading…</p>;
return (
<ul>
{data?.data.map((k) => (
<li key={k.id}>{k.name}</li>
))}
</ul>
);
}Hooks
useCreateApiKey mutation
Create a new API key. Auto-invalidates API key queries on success.
useCreateApiKey(options?: MutationOpts<ApiKeyCreated, CreateApiKeyParams>)Types: ApiKeyCreated · CreateApiKeyParams
const create = useCreateApiKey();
create.mutate({ workspaceId: "wsp_abc123", name: "CI token" });useDeleteApiKey mutation
Delete an API key. Auto-invalidates API key queries on success.
useDeleteApiKey(options?: MutationOpts<SuccessResponse, string>)Types: SuccessResponse
const del = useDeleteApiKey();
del.mutate("apikey_abc123");useListApiKeys query
Fetch paginated list of API keys. Supports workspace_id filter.
useListApiKeys(params?: Omit<ListApiKeysParams, | > & { filter?: ApiKeyFilter; orderBy?: ApiKeyOrderBy[]; } & ApiKeyShorthands, options?: QueryOpts<Page<ApiKey>>)Types: ListApiKeysParams · ApiKeyFilter · ApiKeyOrderBy · ApiKeyShorthands · Page · ApiKey
const { data } = useListApiKeys({ workspace_id: "wsp_abc123" });usePurgeApiKey composite
Permanently delete a soft-deleted API key. Caller must have admin tier.
usePurgeApiKey(options?: MutationOpts<SuccessResponse, PurgeApiKeyParams>)Types: SuccessResponse · PurgeApiKeyParams
useRestoreApiKey composite
Restore a soft-deleted API key. Auto-invalidates API key queries.
useRestoreApiKey(options?: MutationOpts<ApiKey, string>)Types: ApiKey
useRetrieveApiKey query
Fetch a single API key by ID.
useRetrieveApiKey(id: string, options?: QueryOpts<ApiKey>)Types: ApiKey
const { data: key } = useRetrieveApiKey("apikey_abc123");useRotateApiKey composite
Regenerate an API key's secret. The previous key is invalidated and the new plaintext value is returned in the mutation result. Auto-invalidates queries.
useRotateApiKey(options?: MutationOpts<ApiKeyCreated, RotateApiKeyParams>)Types: ApiKeyCreated · RotateApiKeyParams
const roll = useRotateApiKey({
onSuccess: (rolled) => showOnce(rolled.key),
});
roll.mutate({ id: "apikey_abc" });useUpdateApiKey mutation
Update an API key (e.g. rename). Auto-invalidates API key queries on success.
useUpdateApiKey(options?: MutationOpts<ApiKey, UpdateApiKeyParams>)Types: ApiKey · UpdateApiKeyParams
const update = useUpdateApiKey();
update.mutate({ id: "apikey_abc", name: "CI deploy key" });