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
KindCreated byActs on
TeamTeam owners and membersIts own team
TenantTenant owners and adminsAny 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

ScopeAllows
agents:read / agents:writeList and inspect / enroll, update, rotate, revoke and delete agents
services:read / services:writeList and inspect / create, update, activate, revoke and delete services, and enroll
policies:read / policies:writeList and inspect / create, toggle, rotate and delete policies and their API keys
audit:readQuery and stream the audit log (metadata only, never payloads)
tokens:writeList, mint (within its own scopes) and revoke tokens
containment:writeFreeze, escrow, release and shred (tenant tokens only)
containment:readForensic 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

EndpointMethodsScope
/whoamiGETany
/agentsGET, POSTagents:read, agents:write
/agents/{id}GET, PATCH, DELETEagents:read, agents:write
/agents/{id}:revoke · :rotate · :regenerate-key · :enable-encryptionPOSTagents:write
/agents/{id}/operationsPUTagents:write
/servicesGET, POSTservices:read, services:write
/services/{id}GET, PATCH, DELETEservices:read, services:write
/services/{id}:activate · :deactivate · :revoke · :rotate · :regenerate-keyPOSTservices:write
/services/{id}/configPATCHservices:write
/services/{id}/public-keyPUTservices:write
/enrollPOSTservices:write
/policiesGET, POSTpolicies:read, policies:write
/policies/{id}GET, PATCH, DELETEpolicies:read, policies:write
/policies/{id}:toggle · :rotate · :regenerate-keyPOSTpolicies:write
/policies/{id}/operationsPUTpolicies:write
/policies/{id}/keysPOST, DELETEpolicies:write
/containment/freezePOSTcontainment:write
/containment/unfreezePOSTcontainment:write
/containment/escrow · /containment/releasePOSTcontainment:write
/containment/escrow/export · /containment/forensic-decryptPOSTcontainment:read
/containment/forensic-keysGET, POSTcontainment:write
/containment/forensic-keys/{id}DELETEcontainment:write
/containment/shredGET, POSTcontainment:write
/containment/shred/{id}:approve · :cancelPOSTcontainment:write
/tokensGET, POSTtokens:write
/tokens/{id}DELETEtokens:write
/auditGETaudit:read
/audit/streamGET (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, and encrypt-for in both directions. A sender sees a frozen recipient as RECIPIENT_INACTIVE.
  • Services: protect, unprotect and operations, 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:

CustodyEscrowed under4Quays can…
platformA separate forensic master key (not the account master key)Release it, or decrypt a message to it for an investigator (/containment/forensic-decrypt, audited)
customerA JWE (RSA-OAEP-256 + A256GCM) to a forensic public key your tenant registeredNothing: 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 (409 otherwise). 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, which containment:write doesn'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.

  • operations is the data plane: sign, encrypt, decrypt and the rest.
  • management is 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

CodeStatusMeaning
INVALID_REQUEST400Bad body, query or cursor
TEAM_REQUIRED400A tenant token called a team endpoint without ?team=
TOKEN_INVALID401Unknown, malformed or revoked token, or a request from outside its allowed IP ranges
TOKEN_EXPIRED401Token past its expiry
SCOPE_REQUIRED403Token lacks the scope
TENANT_FROZEN403Writes are refused while the tenant is frozen
NOT_FOUND404No such resource in this team
CONFLICT409Duplicate, or the target's state forbids the change
USE_AGENT_ENDPOINT409Agent policies are managed through /agents
IDEMPOTENCY_MISMATCH422Idempotency-Key reused with a different request
RATE_LIMITED429Too many requests; wait Retry-After seconds
INTERNAL_ERROR500Unexpected 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);
}