Fleet API Reference
REST API reference for DefenseClaw IoT fleet device registration, policy and emergency distribution, threat intelligence, and observability.
Preview. The Fleet API manages devices, policy, threat intelligence and metrics for Edge Connector fleets. It is served at /api/v1/fleet/ on the gateway API port (gateway.api_port, 18970 by default), and only when fleet.enabled: true is set in the gateway's config.yaml.
| Route | What it does |
|---|---|
GET /devices, POST /devices | List and register devices. |
GET /devices/{id} | One device. |
POST /devices/{id}/rotate-key | Replace a device key. |
POST /devices/decommission-batch | Decommission devices. |
POST /policy/push, POST /policy/simulate | Compile, sign and publish a policy, or dry-run it. |
GET /policy/versions | Stored policy versions. |
POST /policy/emergency | Publish a signed emergency command. |
POST /threat-intel/push | Revoke allowed hashes from the verdict cache. |
GET /health, GET /metrics | Fleet health and Prometheus metrics. |
POST /token/rotate | Rotate the admin token. |
All paths are under /api/v1/fleet.
Authentication
Every endpoint needs a bearer token in the Authorization header.
| Token | Set with | Reaches |
|---|---|---|
| Admin | DCLAW_FLEET_API_TOKEN on the server | Every endpoint, /metrics included |
| Tenant-scoped | fleet.tenant_tokens or DCLAW_FLEET_TENANT_TOKENS | Only that tenant's data; not /metrics |
# GET request (read-only)
curl -H "Authorization: Bearer $DCLAW_FLEET_API_TOKEN" \
https://gateway.example.com/api/v1/fleet/devices
# POST request (state-changing — requires CSRF header)
curl -X POST \
-H "Authorization: Bearer $DCLAW_FLEET_API_TOKEN" \
-H "X-DefenseClaw-Client: true" \
-H "Content-Type: application/json" \
-d '{"tenant_id":1,"fleet_id":2,"device_id":1001}' \
https://gateway.example.com/api/v1/fleet/devicesIf DCLAW_FLEET_API_TOKEN is not set, all requests are rejected with 401 Unauthorized. Keep the gateway API on loopback or behind a trusted TLS and authentication boundary; the token is a bearer credential.
JSON API request and response bodies use Content-Type: application/json; /metrics returns Prometheus text. Request bodies are limited to 1 MB.
CSRF protection
Every POST needs the X-DefenseClaw-Client header and Content-Type: application/json, also one with no body such as /token/rotate and /devices/{id}/rotate-key.
- Without the header the gateway answers
403. - Without the content type it answers
415with{"error":"Content-Type must be application/json"}.
Devices
List devices
GET /api/v1/fleet/devicesReturns all registered devices with an aggregate fleet summary.
Response 200 OK
{
"devices": [
{
"device_id": 281483566646249,
"tenant_id": 1,
"fleet_id": 2,
"hw_profile": "rpi4",
"fw_version": "1.2.0",
"policy_version": 3,
"capabilities": 127,
"status": "online",
"last_heartbeat": "2026-10-05T14:32:00Z",
"last_audit_hmac": "base64...",
"site_id": "factory-east",
"registered_at": "2026-09-01T10:00:00Z",
"flags": 0,
"denied_total": 42,
"allowed_total": 18305,
"warned_total": 7,
"escalated_total": 1,
"flash_writes": 1200,
"last_uptime": 86400,
"boot_counter": 3,
"prev_denied": 0,
"prev_allowed": 0,
"prev_warned": 0,
"prev_escalated": 0,
"boot_epoch": 3
}
],
"limit": 10000,
"offset": 0,
"summary": {
"total": 150,
"online": 142,
"offline": 5,
"degraded": 2,
"lockdown": 1
},
"total": 150
}Register a device
POST /api/v1/fleet/devicesRegisters a device and returns its per-device key. Pre-register each production device this way; MQTT auto-registration is for unmanaged local development only.
- Registering a composite ID that already exists returns
200 OKinstead of201 Createdand replaces the device key. Put the returned key on the device at once. - A decommissioned device also needs
force_reregister: true. - Registration fails closed when the credential store or the required credential audit is unavailable.
- Moving a C device to another tenant or fleet needs a trusted flash reset and new provisioning (Device keys and registration).
Request body
| Field | Type | Required | Description |
|---|---|---|---|
tenant_id | uint16 | yes | Tenant identifier |
fleet_id | uint16 | yes | Fleet identifier |
device_id | uint32 | yes | Device identifier (must be non-zero) |
hw_profile | string | no | Hardware profile name (free text) |
fw_version | string | no | Firmware version string |
policy_version | uint16 | no | Highest accepted policy version (anti-rollback watermark); after a canary rollback this can exceed the active partition's version |
capabilities | uint8 | no | Capability bitmask the device supports |
force_reregister | bool | no | Required to re-enable a decommissioned device |
{
"tenant_id": 1,
"fleet_id": 2,
"device_id": 1001,
"hw_profile": "rpi4",
"fw_version": "1.2.0",
"policy_version": 3,
"capabilities": 127
}Response 201 Created (new device)
{
"device": {
"device_id": 281483566646249,
"tenant_id": 1,
"fleet_id": 2,
"hw_profile": "rpi4",
"fw_version": "1.2.0",
"policy_version": 3,
"capabilities": 127,
"status": "online",
"last_heartbeat": "0001-01-01T00:00:00Z",
"last_audit_hmac": null,
"site_id": "",
"registered_at": "2026-10-05T14:00:00Z",
"flags": 0,
"denied_total": 0,
"allowed_total": 0,
"flash_writes": 0
},
"device_key": "a1b2c3d4...hex-encoded-32-byte-key..."
}Response 200 OK (device already exists): the same shape, with a new device_key.
device_key is returned on registration, re-registration and key rotation, and cannot be read again later. Each new key invalidates the previous one. Put it on the device as DCLAW_DEVICE_KEY (the remote install writes it to /etc/defenseclaw/edge-connector.env). Production key delivery requires HTTPS or a trusted same-host TLS proxy.
Status codes
| Status | Condition |
|---|---|
200 | Device already exists (idempotent) |
201 | Device created |
400 | Missing device_id or malformed JSON |
403 | Token is not authorized for the tenant, or credential delivery channel is not protected |
409 | Device was decommissioned; force_reregister is required |
413 | Request body exceeds 1 MB |
503 | Atomic credential/tombstone store or mandatory audit unavailable; existing registration and key are preserved so the request can be retried |
Rotate a device key
POST /api/v1/fleet/devices/{id}/rotate-keyGenerates and stores a new 32-byte device HMAC key. The response has device_id, device_key and status: "rotated". Put the key on the device before it sends more signed messages.
- One rotation per device per minute (
429otherwise). Needs a configured key store (501otherwise). - A tenant-scoped token can rotate only devices in its tenant. A missing device returns
404. - Key delivery requires HTTPS or a trusted same-host TLS proxy.
Rotate the Fleet API token
POST /api/v1/fleet/token/rotateNeeds the admin token and returns a new 32-byte token once. The old admin token stops working in the running gateway. Rotation is limited to once per minute, and token delivery requires HTTPS or a trusted same-host TLS proxy.
Rotation is in memory only: it does not update DCLAW_FLEET_API_TOKEN. Save the new token in the gateway's secret source, or a restart brings the old token back.
Get device details
GET /api/v1/fleet/devices/{id}Returns the full record of one device, with the same fields as one entry of List devices. The {id} is the 64-bit composite device ID, not the raw device_id.
Status codes
| Status | Condition |
|---|---|
200 | Device found |
400 | Invalid id (not a valid uint64) |
404 | Device not found |
Decommission devices (batch)
POST /api/v1/fleet/devices/decommission-batchRemoves multiple devices from the fleet in a single request. Returns which devices were decommissioned and which were not found. Each existing device needs a successful pre-commit credential audit before its key and tombstone can change.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
devices | array | yes | List of device identifiers (must not be empty) |
devices[].tenant_id | uint16 | yes | Tenant identifier |
devices[].fleet_id | uint16 | yes | Fleet identifier |
devices[].device_id | uint32 | yes | Device identifier |
{
"devices": [
{ "tenant_id": 1, "fleet_id": 2, "device_id": 1001 },
{ "tenant_id": 1, "fleet_id": 2, "device_id": 1002 },
{ "tenant_id": 1, "fleet_id": 2, "device_id": 9999 }
]
}Response 200 OK
{
"batch_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"requested": 3,
"decommissioned": 2,
"status": "completed",
"not_found": [281483566655247]
}Optional fields in the response, all holding 64-bit composite device IDs unless noted:
| Field | Present when |
|---|---|
not_found | One or more devices do not exist. |
audit_failed, persistence_failed | Those devices were not durably decommissioned. Review and retry them; the others stay decommissioned. |
tenant_denied_count (a count) | A tenant-scoped request skipped entries from another tenant. |
Status codes
| Status | Condition |
|---|---|
200 | Batch completed (even if some devices were not found) |
400 | Empty devices list or malformed JSON |
207 | Partial failure (including a foreign-tenant entry) or 30-second batch deadline; inspect failure fields and status |
Policy
Push policy
POST /api/v1/fleet/policy/pushCompiles a policy YAML, signs it with DCLAW_OTA_HMAC_KEY, stores the version and publishes the signed binary to the fleet's MQTT topic. Compiling needs Python 3 and PyYAML on the gateway (policy compiler requirements).
- Version. The gateway assigns it from the stored fleet history, from 1 up to 65534; a YAML
versionfield does not select it. After 65534 a push returns409and needs a new device policy lineage. - Delivery. A
200confirms broker publication, not that the device applied it. After a signed registration or heartbeat from a device on an older version, the gateway can publish the latest policy again. Confirm application from a later signed heartbeat. - Keys. Devices need the same secret and a production build with
-DDCLAW_ALLOW_HMAC_OTA=ON.DCLAW_OTA_KEYnames a public Ed25519 key, which the C build does not verify and does not use as an HMAC secret. Emergency commands use the separateDCLAW_EMERGENCY_KEY.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
tenant_id | uint16 | yes | Tenant identifier |
fleet_id | uint16 | yes | Fleet identifier |
policy_yaml | string | yes | Raw YAML policy content |
profile | string | no | Build profile (defaults to standard) |
{
"tenant_id": 1,
"fleet_id": 2,
"policy_yaml": "name: factory-east\nskill_actions:\n critical:\n runtime: disable\n high:\n runtime: disable\n",
"profile": "standard"
}Response 200 OK
{
"version": 1,
"blob_size": 2048,
"tenant_id": 1,
"fleet_id": 2,
"profile": "standard",
"status": "distributed"
}Status codes
| Status | Condition |
|---|---|
200 | Policy compiled, signed, stored, and published to the broker; device application is unconfirmed |
400 | Missing required fields, invalid policy, or unsupported profile |
409 | The fleet policy version reached 65534; provision a new device policy lineage |
413 | Request body or compiled policy exceeds its size limit |
422 | Policy YAML cannot be compiled |
500 | Signing or distribution failed |
501 | Policy service not configured |
List policy versions
GET /api/v1/fleet/policy/versions?tenant_id={tenant_id}&fleet_id={fleet_id}Returns every stored policy version for a tenant and fleet, newest first.
Query parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
tenant_id | uint16 | yes | Tenant identifier |
fleet_id | uint16 | yes | Fleet identifier |
Response 200 OK
{
"tenant_id": 1,
"fleet_id": 2,
"versions": [
{
"tenant_id": 1,
"fleet_id": 2,
"version": 4,
"profile": "standard",
"policy_bin": null,
"signature": null,
"created_at": "2026-10-05T14:00:00Z",
"distributed": true
}
]
}Status codes
| Status | Condition |
|---|---|
200 | Versions returned (may be empty list) |
400 | Invalid or missing tenant_id / fleet_id |
501 | Policy service not configured |
Simulate policy (dry run)
POST /api/v1/fleet/policy/simulateCompiles a policy YAML without signing or distributing. Use this to validate policy changes before pushing them.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
policy_yaml | string | yes | Raw YAML policy content |
profile | string | no | Build profile (defaults to standard) |
{
"policy_yaml": "name: test-policy\nversion: 1\nskill_actions:\n critical:\n runtime: disable\n",
"profile": "edge"
}Response 200 OK
{
"blob_size": 1536,
"payload_len": 1024,
"canary_baseline": 0,
"fits_target_profile": true,
"status": "dry-run compilation succeeded"
}Status codes
| Status | Condition |
|---|---|
200 | Compilation succeeded (or policy service not configured, returns stub result) |
400 | Malformed JSON |
422 | Compilation failed (invalid policy YAML) |
Send emergency command
POST /api/v1/fleet/policy/emergencyPublishes a signed emergency command to the fleet's MQTT topic. A 200 confirms broker publication, not that a device received or ran it.
- A device that is offline at publication misses the first send. The gateway keeps a signed emergency history and replays missed commands in order after the device's next signed registration or heartbeat, up to 32 per pass.
- Each command signs the sequence of the one before it, so a later command cannot skip a missed lockdown. A gap in the history, or an unavailable store, fails closed.
- During an incident, confirm the device's last applied emergency sequence in a later signed heartbeat.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
tenant_id | uint16 | yes | Tenant identifier |
fleet_id | uint16 | yes | Fleet identifier |
command | string | yes | One of: BLOCK_ALL, ENTER_LOCKDOWN, RELEASE_LOCKDOWN, REVOKE_SESSIONS, FORCE_SYNC |
{
"tenant_id": 1,
"fleet_id": 2,
"command": "ENTER_LOCKDOWN"
}Response 200 OK
{
"tenant_id": 1,
"fleet_id": 2,
"command": "ENTER_LOCKDOWN",
"status": "distributed"
}| Command | Effect |
|---|---|
BLOCK_ALL | A receiving device blocks every tool call |
ENTER_LOCKDOWN | A receiving device enters lockdown mode and blocks tool calls |
RELEASE_LOCKDOWN | A receiving device clears emergency lockdown and resumes normal policy evaluation |
REVOKE_SESSIONS | A receiving device terminates active agent sessions and clears its verdict cache |
FORCE_SYNC | A receiving device flushes its in-RAM audit buffer to durable storage |
Status codes
| Status | Condition |
|---|---|
200 | Emergency command published to the broker; device execution is unconfirmed |
400 | Missing required fields or unknown command |
500 | Distribution failed |
501 | Policy service not configured |
Threat Intelligence
Push threat intelligence
POST /api/v1/fleet/threat-intel/pushRemoves previously allowed hashes from the gateway verdict cache, or flushes the whole cache in an emergency. For each registered tenant and fleet, the gateway also publishes a signed REVOKE_SESSIONS message so devices clear their own caches.
- Publication does not confirm delivery. An offline device misses the first message, and a cached
ALLOWcan remain on it until it reconnects. - The C connector flushes its verdict cache when it reconnects to the broker, before it decides more tool calls. The gateway can also replay missed emergency commands after the device's next signed heartbeat.
device_cache_flushed: falseis a delivery limit, not a device acknowledgment.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
revoke_allow_hashes | string[] | no | List of SHA-256 hashes (64 hex chars each) to remove from the allow cache |
emergency | bool | no | If true, flush the entire verdict cache before processing individual revocations |
{
"revoke_allow_hashes": [
"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
],
"emergency": false
}Response 202 Accepted when all requested fleet publications succeed
{
"revoked": 1,
"device_cache_flush_published": 2,
"device_cache_flush_target_fleets": 2,
"device_cache_flushed": false,
"warning": "MQTT publication does not confirm device receipt; offline devices may keep cached verdicts until reconnect or TTL expiry"
}If any fleet publication fails, the answer is 207 Multi-Status with the successful publication count and a device_cache_flush_failed list of "tenant_id/fleet_id" strings; the gateway cache revocation still happens. An empty request returns 202 with only revoked.
Status codes
| Status | Condition |
|---|---|
202 | Gateway cache revocations processed; requested device-cache flush messages published, if any. Device receipt is not confirmed |
207 | Gateway cache revocations processed, but one or more fleet publications failed; inspect device_cache_flush_failed |
400 | Invalid hex string or hash is not exactly 32 bytes (64 hex chars) |
Observability
Fleet health
GET /api/v1/fleet/healthWith the admin token, returns fleet status and verdict cache statistics. With a tenant-scoped token, returns only that tenant's device counts and policy versions under fleet, without the cache statistics.
policy_versions counts each device's highest accepted version. After a canary rollback the active policy can be older, so check the CANARY_ROLLBACK flag before you read this as policy adoption.
Response 200 OK
{
"fleet": {
"total_devices": 150,
"online": 142,
"offline": 5,
"degraded": 2,
"lockdown": 1,
"policy_versions": {
"3": 10,
"4": 140
}
},
"cache_hits": 1843920,
"cache_misses": 42817,
"cache_size": 8192
}Prometheus metrics
GET /api/v1/fleet/metricsReturns global metrics in Prometheus text format (text/plain; version=0.0.4). Scrape it with the admin bearer token; a tenant-scoped token gets 403 Forbidden, so cross-tenant totals do not leak. The dashboard and scrape example are in the Fleet assets (Grafana dashboard).
Metrics
| Metric | Type | Description |
|---|---|---|
defenseclaw_fleet_devices_total | gauge | Registered devices by status (online, offline, degraded, lockdown) |
defenseclaw_fleet_heartbeats_received_total | counter | Total heartbeats received from all devices |
defenseclaw_fleet_blocks_total | counter | Total block verdicts across the fleet |
defenseclaw_fleet_allows_total | counter | Total allow verdicts across the fleet |
defenseclaw_fleet_verdict_cache_hits_total | counter | Server-side verdict cache hits |
defenseclaw_fleet_verdict_cache_misses_total | counter | Server-side verdict cache misses |
defenseclaw_fleet_verdict_cache_size | gauge | Current number of entries in the verdict cache |
defenseclaw_fleet_policy_rollback_total | counter | Policy canary rollback transitions reported by devices |
defenseclaw_fleet_alerts_total | counter | Fleet alerts emitted |
defenseclaw_fleet_ota_rollbacks_total | counter | OTA canary rollback transitions reported by devices |
Both rollback counters go up once, when a device's authenticated heartbeat first carries the CANARY_ROLLBACK flag. Later heartbeats with the same flag do not count again. The device's policy_version stays at the highest accepted version, so it does not prove that version is still active.
Error format
Error responses from the fleet API use this JSON structure. A method the path does not accept returns 405 with the plain text Method Not Allowed instead.
{
"error": "human-readable error message"
}Some errors include an additional detail field with diagnostic information:
{
"error": "failed to dispatch command",
"detail": "MQTT connection timeout"
}Common status codes
| Status | Meaning |
|---|---|
200 | Success |
201 | Device registered |
202 | Threat intelligence accepted and published |
207 | Partial result: a batch decommission or threat-intelligence publication partly failed, or the decommission hit its 30-second deadline |
400 | Bad request (validation error, malformed JSON) |
401 | Missing or invalid Bearer token, or DCLAW_FLEET_API_TOKEN is not set |
403 | Token not allowed for this tenant or endpoint, missing CSRF header, non-localhost Origin, or key or token delivery without TLS |
404 | Resource not found |
405 | Method not allowed for this path (plain text Method Not Allowed) |
409 | Device decommissioned (force_reregister needed), or policy version 65534 reached |
413 | Request body or compiled policy too large |
415 | POST without Content-Type: application/json |
422 | Policy YAML cannot be compiled |
429 | Token or device key rotated less than a minute ago |
500 | Internal error, including signing or distribution failure (for example MQTT not configured) |
501 | Policy service or device key store not configured |
503 | Credential, registration or audit store unavailable; retry |