Skip to content

API Keys

Copy page

divinci.apiKeys manages the API keys that authenticate access to a workspace. Keys are workspace-scoped, so every call takes a workspaceId.

The secret is returned once, at creation. Store it immediately.

const created = await divinci.apiKeys.create({
workspaceId: "ws_123",
name: "CI pipeline",
// optional: permissions, expiry, etc.
});
console.log(created.secret); // shown only here — save it now

permissions controls what a key may do. Leave it empty (or omit it) and the key gets full access scoped to its workspace — the right default for a trusted backend integration. Pass an explicit array only when you want to restrict the key:

// Full access (scoped to the workspace) — empty/omitted permissions
const full = await divinci.apiKeys.create({ workspaceId: "ws_123", name: "backend" });
// Restricted: this key can read RAG and send chat messages, nothing else
const scoped = await divinci.apiKeys.create({
workspaceId: "ws_123",
name: "chat widget",
permissions: ["rag:read", "transcript:write"],
});

Each scope is category:action:

ScopeGrants
transcript:read / transcript:writeRead transcripts / send chat messages
rag:read / rag:writeRead / manage RAG vectors and sources
release:read / release:writeRead / manage releases
finetune:read / finetune:writeRead / manage fine-tune jobs
whitelabel:read / whitelabel:writeRead / modify workspace config
analytics:readRead usage analytics
byok:read / byok:write / byok:resolveManage bring-your-own provider keys
const { data } = await divinci.apiKeys.list("ws_123", { limit: 20 });
const key = await divinci.apiKeys.get("ws_123", "key_abc");
await divinci.apiKeys.update("ws_123", "key_abc", { name: "CI pipeline (prod)" });
// Rotate: issues a new secret, invalidates the old one
const rotated = await divinci.apiKeys.rotate("ws_123", "key_abc");
console.log(rotated.secret);
// Revoke: disable without deleting the record
await divinci.apiKeys.revoke("ws_123", "key_abc");
// Delete entirely
await divinci.apiKeys.delete("ws_123", "key_abc");

Check a key’s status without making an authenticated call:

const result = await divinci.apiKeys.validate("divinci_key_...");
if (result.valid) {
console.log(result.status); // "active" | "revoked" | "expired"
console.log(result.workspaceId);
console.log(result.permissions);
} else {
console.error(result.error);
}
const usage = await divinci.apiKeys.getUsage("ws_123", "key_abc", "month");
MethodDescription
list(workspaceId, options?)Paginated keys.
get(workspaceId, keyId)Fetch a key (no secret).
create(options)Create a key; returns the secret once.
update(workspaceId, keyId, options)Update key metadata.
rotate(workspaceId, keyId)Issue a new secret, invalidate the old.
revoke(workspaceId, keyId)Disable a key.
delete(workspaceId, keyId)Permanently delete a key.
validate(apiKey)Check status, workspace, and permissions.
getUsage(workspaceId, keyId, period?)Usage stats.