Edge Connector

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.

RouteWhat it does
GET /devices, POST /devicesList and register devices.
GET /devices/{id}One device.
POST /devices/{id}/rotate-keyReplace a device key.
POST /devices/decommission-batchDecommission devices.
POST /policy/push, POST /policy/simulateCompile, sign and publish a policy, or dry-run it.
GET /policy/versionsStored policy versions.
POST /policy/emergencyPublish a signed emergency command.
POST /threat-intel/pushRevoke allowed hashes from the verdict cache.
GET /health, GET /metricsFleet health and Prometheus metrics.
POST /token/rotateRotate the admin token.

All paths are under /api/v1/fleet.

Authentication

Every endpoint needs a bearer token in the Authorization header.

TokenSet withReaches
AdminDCLAW_FLEET_API_TOKEN on the serverEvery endpoint, /metrics included
Tenant-scopedfleet.tenant_tokens or DCLAW_FLEET_TENANT_TOKENSOnly 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/devices

If 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 415 with {"error":"Content-Type must be application/json"}.

Devices

List devices

GET /api/v1/fleet/devices

Returns 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/devices

Registers 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 OK instead of 201 Created and 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

FieldTypeRequiredDescription
tenant_iduint16yesTenant identifier
fleet_iduint16yesFleet identifier
device_iduint32yesDevice identifier (must be non-zero)
hw_profilestringnoHardware profile name (free text)
fw_versionstringnoFirmware version string
policy_versionuint16noHighest accepted policy version (anti-rollback watermark); after a canary rollback this can exceed the active partition's version
capabilitiesuint8noCapability bitmask the device supports
force_reregisterboolnoRequired 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

StatusCondition
200Device already exists (idempotent)
201Device created
400Missing device_id or malformed JSON
403Token is not authorized for the tenant, or credential delivery channel is not protected
409Device was decommissioned; force_reregister is required
413Request body exceeds 1 MB
503Atomic 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-key

Generates 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 (429 otherwise). Needs a configured key store (501 otherwise).
  • 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/rotate

Needs 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

StatusCondition
200Device found
400Invalid id (not a valid uint64)
404Device not found

Decommission devices (batch)

POST /api/v1/fleet/devices/decommission-batch

Removes 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

FieldTypeRequiredDescription
devicesarrayyesList of device identifiers (must not be empty)
devices[].tenant_iduint16yesTenant identifier
devices[].fleet_iduint16yesFleet identifier
devices[].device_iduint32yesDevice 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:

FieldPresent when
not_foundOne or more devices do not exist.
audit_failed, persistence_failedThose 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

StatusCondition
200Batch completed (even if some devices were not found)
400Empty devices list or malformed JSON
207Partial failure (including a foreign-tenant entry) or 30-second batch deadline; inspect failure fields and status

Policy

Push policy

POST /api/v1/fleet/policy/push

Compiles 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 version field does not select it. After 65534 a push returns 409 and needs a new device policy lineage.
  • Delivery. A 200 confirms 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_KEY names a public Ed25519 key, which the C build does not verify and does not use as an HMAC secret. Emergency commands use the separate DCLAW_EMERGENCY_KEY.

Request body

FieldTypeRequiredDescription
tenant_iduint16yesTenant identifier
fleet_iduint16yesFleet identifier
policy_yamlstringyesRaw YAML policy content
profilestringnoBuild 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

StatusCondition
200Policy compiled, signed, stored, and published to the broker; device application is unconfirmed
400Missing required fields, invalid policy, or unsupported profile
409The fleet policy version reached 65534; provision a new device policy lineage
413Request body or compiled policy exceeds its size limit
422Policy YAML cannot be compiled
500Signing or distribution failed
501Policy 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

ParameterTypeRequiredDescription
tenant_iduint16yesTenant identifier
fleet_iduint16yesFleet 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

StatusCondition
200Versions returned (may be empty list)
400Invalid or missing tenant_id / fleet_id
501Policy service not configured

Simulate policy (dry run)

POST /api/v1/fleet/policy/simulate

Compiles a policy YAML without signing or distributing. Use this to validate policy changes before pushing them.

Request body

FieldTypeRequiredDescription
policy_yamlstringyesRaw YAML policy content
profilestringnoBuild 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

StatusCondition
200Compilation succeeded (or policy service not configured, returns stub result)
400Malformed JSON
422Compilation failed (invalid policy YAML)

Send emergency command

POST /api/v1/fleet/policy/emergency

Publishes 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

FieldTypeRequiredDescription
tenant_iduint16yesTenant identifier
fleet_iduint16yesFleet identifier
commandstringyesOne 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"
}
CommandEffect
BLOCK_ALLA receiving device blocks every tool call
ENTER_LOCKDOWNA receiving device enters lockdown mode and blocks tool calls
RELEASE_LOCKDOWNA receiving device clears emergency lockdown and resumes normal policy evaluation
REVOKE_SESSIONSA receiving device terminates active agent sessions and clears its verdict cache
FORCE_SYNCA receiving device flushes its in-RAM audit buffer to durable storage

Status codes

StatusCondition
200Emergency command published to the broker; device execution is unconfirmed
400Missing required fields or unknown command
500Distribution failed
501Policy service not configured

Threat Intelligence

Push threat intelligence

POST /api/v1/fleet/threat-intel/push

Removes 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 ALLOW can 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: false is a delivery limit, not a device acknowledgment.

Request body

FieldTypeRequiredDescription
revoke_allow_hashesstring[]noList of SHA-256 hashes (64 hex chars each) to remove from the allow cache
emergencyboolnoIf 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

StatusCondition
202Gateway cache revocations processed; requested device-cache flush messages published, if any. Device receipt is not confirmed
207Gateway cache revocations processed, but one or more fleet publications failed; inspect device_cache_flush_failed
400Invalid hex string or hash is not exactly 32 bytes (64 hex chars)

Observability

Fleet health

GET /api/v1/fleet/health

With 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/metrics

Returns 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

MetricTypeDescription
defenseclaw_fleet_devices_totalgaugeRegistered devices by status (online, offline, degraded, lockdown)
defenseclaw_fleet_heartbeats_received_totalcounterTotal heartbeats received from all devices
defenseclaw_fleet_blocks_totalcounterTotal block verdicts across the fleet
defenseclaw_fleet_allows_totalcounterTotal allow verdicts across the fleet
defenseclaw_fleet_verdict_cache_hits_totalcounterServer-side verdict cache hits
defenseclaw_fleet_verdict_cache_misses_totalcounterServer-side verdict cache misses
defenseclaw_fleet_verdict_cache_sizegaugeCurrent number of entries in the verdict cache
defenseclaw_fleet_policy_rollback_totalcounterPolicy canary rollback transitions reported by devices
defenseclaw_fleet_alerts_totalcounterFleet alerts emitted
defenseclaw_fleet_ota_rollbacks_totalcounterOTA 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

StatusMeaning
200Success
201Device registered
202Threat intelligence accepted and published
207Partial result: a batch decommission or threat-intelligence publication partly failed, or the decommission hit its 30-second deadline
400Bad request (validation error, malformed JSON)
401Missing or invalid Bearer token, or DCLAW_FLEET_API_TOKEN is not set
403Token not allowed for this tenant or endpoint, missing CSRF header, non-localhost Origin, or key or token delivery without TLS
404Resource not found
405Method not allowed for this path (plain text Method Not Allowed)
409Device decommissioned (force_reregister needed), or policy version 65534 reached
413Request body or compiled policy too large
415POST without Content-Type: application/json
422Policy YAML cannot be compiled
429Token or device key rotated less than a minute ago
500Internal error, including signing or distribution failure (for example MQTT not configured)
501Policy service or device key store not configured
503Credential, registration or audit store unavailable; retry