API keys
Managing keys requires a key with the keys:manage scope. There is no public signup in v1: an operator provisions your first admin key, and you create narrower keys from it.
Create a key
Section titled “Create a key”POST /api-keys takes a name of 1 to 100 characters and one or more scopes. A new key’s scopes must be a subset of the caller’s scopes; asking for a scope you do not hold is rejected.
The response is 201 Created with the key’s metadata and its secret. The secret is returned only once, with Cache-Control: no-store. Sonic Docs stores only a digest of it, so a lost secret cannot be recovered: revoke the key and create a new one.
List and revoke keys
Section titled “List and revoke keys”GET /api-keys returns metadata only: ID, name, a short prefix to help you recognize the key, scopes, creation time and revoked_at. Secrets never appear in listings.
{ "keys": [ { "id": "key_example", "name": "Development", "prefix": "sd_test_example", "scopes": [ "documents:read" ], "created_at": "2026-11-30T20:00:00Z", "revoked_at": null } ]}DELETE /api-keys/{key_id} revokes a key and returns 204. It also returns 204 if the key is already revoked or does not exist in your tenant. Revocation applies to HTTP requests, outstanding WebSocket tickets and active event subscriptions before the response is sent.
Example
Section titled “Example”#!/usr/bin/env bash# Sonic Docs contract example: create a read-only key, list keys, then revoke it.# Written against the planned v1 contract; not yet run against a live API.set -euo pipefail
API_BASE="${SONIC_API_BASE:-https://api.sonicdocs.ai/v1}": "${SONIC_API_KEY:?Set SONIC_API_KEY to a key with keys:manage}"AUTH="Authorization: Bearer $SONIC_API_KEY"
# The secret is returned only in this response. Store it in a secret manager.CREATED=$(curl -sS --fail-with-body -X POST "$API_BASE/api-keys" -H "$AUTH" \ -H "Content-Type: application/json" \ -d '{"name":"Read-only reporting","scopes":["documents:read"]}')KEY_ID=$(jq -r .key.id <<<"$CREATED")echo "Created $KEY_ID ($(jq -r .key.prefix <<<"$CREATED")...)"
curl -sS --fail-with-body -H "$AUTH" "$API_BASE/api-keys" | jq -r '.keys[] | "\(.id)\t\(.name)\t\(.scopes | join(","))\t\(.revoked_at // "active")"'
curl -sS --fail-with-body -X DELETE -H "$AUTH" "$API_BASE/api-keys/$KEY_ID"echo "Revoked $KEY_ID"// Sonic Docs contract example: create a read-only key, list keys, then revoke it.// Written against the planned v1 contract; not yet run against a live API.import { API_BASE, api } from './client.mjs';
// The secret is returned only in this response. Store it in a secret manager.const created = await ( await api(`${API_BASE}/api-keys`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: 'Read-only reporting', scopes: ['documents:read'] }), })).json();console.log(`Created ${created.key.id} (${created.key.prefix}...)`);
const { keys } = await (await api(`${API_BASE}/api-keys`)).json();for (const key of keys) console.log(key.id, key.name, key.scopes.join(','), key.revoked_at ?? 'active');
await api(`${API_BASE}/api-keys/${encodeURIComponent(created.key.id)}`, { method: 'DELETE' });console.log(`Revoked ${created.key.id}`);"""Sonic Docs contract example: create a read-only key, list keys, then revoke it.
Written against the planned v1 contract; not yet run against a live API."""from urllib.parse import quote
from client import API_BASE, api
# The secret is returned only in this response. Store it in a secret manager.created = api("POST", f"{API_BASE}/api-keys", json={"name": "Read-only reporting", "scopes": ["documents:read"]}).json()print(f"Created {created['key']['id']} ({created['key']['prefix']}...)")
for key in api("GET", f"{API_BASE}/api-keys").json()["keys"]: print(key["id"], key["name"], ",".join(key["scopes"]), key["revoked_at"] or "active")
api("DELETE", f"{API_BASE}/api-keys/{quote(created['key']['id'], safe='')}")print(f"Revoked {created['key']['id']}")