Management API
Enroll, rotate and revoke agents and services, manage policies and tokens, and read the audit log from scripts, CI and the 4quays CLI
The management API (/api/mgmt/v1) controls a team's agents, services, policies and management tokens, and reads its audit log. Use it from scripts, CI pipelines, operator consoles and the 4quays CLI.
A management token can enroll, rotate and revoke agents, but it can never sign, encrypt or decrypt as one: it holds no agent keys. Never put a management token in an agent's environment. Each agent gets only its own 4q_… key, which is returned once when you enroll it.
The machine-readable OpenAPI 3.1 document is served at /api/mgmt/v1/openapi.json.
Management tokens
Create a token in the console under Settings → API access. It is shown once.
Authorization: Bearer 4qm_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Kind | Created by | Acts on |
|---|---|---|
| Team | Team owners and members | Its own team |
| Tenant | Tenant owners and admins | Any team in the tenant; pass ?team=<id or slug> on team endpoints (otherwise 400 TEAM_REQUIRED) |
Tokens belong to the team, not the person who created them. They keep working if that person leaves. Every token has an expiry (7–365 days), and can optionally be restricted to a list of IP ranges.
Scopes
| Scope | Allows |
|---|---|
agents:read / agents:write | List and inspect / enroll, update, rotate, revoke and delete agents |
services:read / services:write | List and inspect / create, update, activate, revoke and delete services, and enroll |
policies:read / policies:write | List and inspect / create, toggle, rotate and delete policies and their API keys |
audit:read | Query and stream the audit log (metadata only, never payloads) |
tokens:write | List, mint (within its own scopes) and revoke tokens |
containment:write | Freeze, escrow, release and shred (tenant tokens only) |
containment:read | Forensic reads of escrowed keys and escrow exports (tenant tokens only; not implied by containment:write) |
A write scope includes its read scope. A team token can't hold scopes beyond its creator's permissions. While a tenant is frozen, every write is refused with 403 TENANT_FROZEN.
Requests and responses
Successful responses use one envelope:
{
"data": { "id": "…" },
"nextCursor": "…",
"requestId": "6f1c…"
}
nextCursor appears only on list endpoints. To fetch the next page, pass it back as ?cursor= (along with limit, default 50).
Errors:
{
"error": { "code": "SCOPE_REQUIRED", "message": "This token lacks agents:write" },
"requestId": "6f1c…"
}
Idempotency
Creates, and any call that returns a secret, accept an Idempotency-Key header. A retry with the same key and body within 24 hours returns the original result, with the secret redacted. Reusing a key with a different body returns 422 IDEMPOTENCY_MISMATCH.
Actions
State changes that aren't plain updates are POST requests to {id}:{verb}:
POST /api/mgmt/v1/agents/8d0e…:revoke
Endpoints
| Endpoint | Methods | Scope |
|---|---|---|
/whoami | GET | any |
/agents | GET, POST | agents:read, agents:write |
/agents/{id} | GET, PATCH, DELETE | agents:read, agents:write |
/agents/{id}:revoke · :rotate · :regenerate-key · :enable-encryption | POST | agents:write |
/agents/{id}/operations | PUT | agents:write |
/services | GET, POST | services:read, services:write |
/services/{id} | GET, PATCH, DELETE | services:read, services:write |
/services/{id}:activate · :deactivate · :revoke · :rotate · :regenerate-key | POST | services:write |
/services/{id}/config | PATCH | services:write |
/services/{id}/public-key | PUT | services:write |
/enroll | POST | services:write |
/policies | GET, POST | policies:read, policies:write |
/policies/{id} | GET, PATCH, DELETE | policies:read, policies:write |
/policies/{id}:toggle · :rotate · :regenerate-key | POST | policies:write |
/policies/{id}/operations | PUT | policies:write |
/policies/{id}/keys | POST, DELETE | policies:write |
/containment/freeze | POST | containment:write |
/containment/unfreeze | POST | containment:write |
/containment/escrow · /containment/release | POST | containment:write |
/containment/escrow/export · /containment/forensic-decrypt | POST | containment:read |
/containment/forensic-keys | GET, POST | containment:write |
/containment/forensic-keys/{id} | DELETE | containment:write |
/containment/shred | GET, POST | containment:write |
/containment/shred/{id}:approve · :cancel | POST | containment:write |
/tokens | GET, POST | tokens:write |
/tokens/{id} | DELETE | tokens:write |
/audit | GET | audit:read |
/audit/stream | GET (SSE) | audit:read |
Agent policies are managed through their agent. Calling /policies/{id} on one returns 409 USE_AGENT_ENDPOINT.
Containment
Freezing an agent or service refuses its next data-plane call until it's unfrozen:
- Agents:
sign,decrypt, andencrypt-forin both directions. A sender sees a frozen recipient asRECIPIENT_INACTIVE. - Services:
protect,unprotectandoperations, for every policy the service is part of.
Status, keys and policies are kept, so unfreezing restores exactly what was there. A frozen agent is refused with 403 AGENT_FROZEN, and a frozen service with 403 SERVICE_FROZEN.
POST /api/mgmt/v1/containment/freeze?team=research
Content-Type: application/json
{ "tag": "swarm:run-42", "reason": "Drifting from its task" }
The body names targets ([{ "kind": "agent" | "service", "id": "…" }]), a tag (every agent carrying it, at that moment), or both. You can freeze up to 500 principals per call.
- Idempotent: an already frozen principal keeps its original freeze. Each change is recorded in the management audit log.
- Levels: a freeze made with a tenant token, or by a tenant owner or admin in the console, is tenant level, and only a tenant-level actor can lift it. Team members can freeze and unfreeze from the agent's page in the console, but can't lift a tenant-level freeze.
Escrow, forensic reads and shred
A freeze is the fast, flag-based cut-off. Escrow makes the cut-off cryptographic. Each key version of a frozen agent or service, including rotated and revoked ones, is moved out of the column every normal decrypt and sign path reads, so those paths have nothing left to unwrap.
You choose the custody each time you escrow:
| Custody | Escrowed under | 4Quays can… |
|---|---|---|
platform | A separate forensic master key (not the account master key) | Release it, or decrypt a message to it for an investigator (/containment/forensic-decrypt, audited) |
customer | A JWE (RSA-OAEP-256 + A256GCM) to a forensic public key your tenant registered | Nothing: the investigator opens the export offline with the forensic private key. Release isn't possible; shred it when the case closes |
Rules:
- Order: freeze before escrowing (
409otherwise). An escrowed principal can't be unfrozen until it's released. - Release: release puts platform-custody keys back, and the principal stays frozen until you unfreeze it.
- Shred: destroying escrowed keys takes two people. One requests (
POST /containment/shred, with a reason) and a different user approves within 24 hours (:approve). It can't be undone. - Tenant tokens only: all of this needs a tenant token. Forensic reads need
containment:read, whichcontainment:writedoesn't imply. Every escrow, release, read, export and shred is a management event.
4quays freeze --tag swarm:run-42 --yes 4quays escrow --tag swarm:run-42 --custody platform --yes 4quays forensic decrypt --agent-id <id> --file message.jwe 4quays shred request --tag swarm:run-42 --reason "case closed" # then a second person: 4quays shred approve <request-id> --yes
Tenant owners and admins can do the same from the tenant console, under Containment. It lists every frozen agent and service across the tenant's teams with its escrow state. From there they can escrow, release, unfreeze, request a shred and approve or cancel one, and register or revoke forensic keys. Console actions go through the same checks as the API, including the second person for a shred. They are recorded as tenant_admin management events. Forensic decrypts and envelope exports stay API and CLI only.
Audit
GET /audit?source=operations|management returns events newest first.
operationsis the data plane: sign, encrypt, decrypt and the rest.managementis what was done in the console or through this API.
Filters: agentId, serviceId, tag, operation, action, outcome and since.
GET /audit/stream takes the same filters and returns a text/event-stream of new events. It closes after about five minutes. To resume without gaps, reconnect with the Last-Event-ID header set to the last event's id.
Error codes
| Code | Status | Meaning |
|---|---|---|
INVALID_REQUEST | 400 | Bad body, query or cursor |
TEAM_REQUIRED | 400 | A tenant token called a team endpoint without ?team= |
TOKEN_INVALID | 401 | Unknown, malformed or revoked token, or a request from outside its allowed IP ranges |
TOKEN_EXPIRED | 401 | Token past its expiry |
SCOPE_REQUIRED | 403 | Token lacks the scope |
TENANT_FROZEN | 403 | Writes are refused while the tenant is frozen |
NOT_FOUND | 404 | No such resource in this team |
CONFLICT | 409 | Duplicate, or the target's state forbids the change |
USE_AGENT_ENDPOINT | 409 | Agent policies are managed through /agents |
IDEMPOTENCY_MISMATCH | 422 | Idempotency-Key reused with a different request |
RATE_LIMITED | 429 | Too many requests; wait Retry-After seconds |
INTERNAL_ERROR | 500 | Unexpected failure; quote the requestId |
Each token is limited to 300 requests per minute.
CLI and SDK
npm install -g @4quays/cli 4quays login --endpoint https://<your 4Quays host> # paste the token at the prompt 4quays agents enroll researcher-01 --operations sign,encrypt,decrypt --json 4quays audit tail --tag swarm:run-42 4quays freeze --tag swarm:run-42 --reason "drifting" --yes # tenant token
In CI, set FOURQ_MGMT_TOKEN and FOURQ_ENDPOINT instead of logging in.
import { FourQ } from '@4quays/sdk';
const mgmt = FourQ.management({
endpoint: process.env.FOURQ_ENDPOINT!,
token: process.env.FOURQ_MGMT_TOKEN!,
});
const { agent, apiKey } = await mgmt.agents.create(
{ name: 'researcher-01', operations: ['sign'], tags: ['swarm:run-42'] },
{ idempotencyKey: 'run-42/researcher-01' },
);
for await (const { event } of mgmt.audit.stream({ tag: 'swarm:run-42' })) {
console.log(event.source, event.occurredAt);
}