Skip to main content

REST API

swamp serve exposes a REST API alongside its WebSocket interface. This page documents the available HTTP endpoints.

Authentication

All REST API endpoints require a Bearer token in the Authorization header with admin authorization. The token is the same credential used for WebSocket authentication.

Authorization: Bearer <token>

When --auth-mode is none (deprecated), no token is required.

See Monitor Server Health for how to mint a monitoring token and grant admin access.

Server Info Endpoint

GET /

Returns a JSON object describing the server instance and its capabilities. This is the unauthenticated discovery endpoint — it does not require a Bearer token.

Response body

Field Type Description
name string Server identifier.
version string Swamp version running on the server.
instanceId string Unique identifier for this server instance, stable for the lifetime of the process.
remoteOnly bool Whether the server is running in remote-only mode. When true, all steps must declare placement for dispatch.

Response

Status Condition
200 Server info returned.

Example

curl https://swamp.example.com/
{
  "name": "swamp-serve",
  "version": "20260818.234252.0",
  "instanceId": "a1b2c3d4",
  "remoteOnly": true
}

Health Monitoring Endpoints

GET /api/v1/health

Returns a point-in-time JSON snapshot of node health.

Response body

Field Type Description
instanceId string Unique identifier for the server instance.
mode string Deployment mode (e.g. standalone, cluster).
uptime number Seconds since the server started.
ready bool Whether the instance is accepting work.
remoteOnly bool Whether the server is running in remote-only mode. When true, all steps must declare placement.
runs array Active runs — each entry includes id, kind, resource, duration, principal.
throughput object Sliding-window (5 min) counters: completions, failures, cancellations, throughput/min, latency percentiles (P50/P95/P99).
workers array Each entry includes name, status, connected, capacity, activeDispatches, platform. Worker status is one of idle, busy, unverified, draining.
scheduling object enabled flag and entries array with cron expressions and next run times.
webhooks array Registered routes, target workflows, and verification schemes.
components object Health of internal subsystems. Each component reports healthy (bool), message, latency, and details. Components: datastore (reachability + latency), vault (availability).

Response

Status Condition
200 Health snapshot returned.
401 Missing or invalid Bearer token.

Example

curl https://swamp.example.com/api/v1/health \
  -H "Authorization: Bearer health-monitor.secret"

GET /api/v1/health/stream

Server-Sent Events stream that pushes health snapshots at a configurable interval.

An initial snapshot is sent immediately on connect, then at the configured interval. Supports Last-Event-ID for resumable connections.

Query parameters

Parameter Type Default Description
interval number 5000 Push frequency in milliseconds (min 1000, max 60000).

SSE format

id: 1
event: health
data: {"instanceId":"...","uptime":3600,...}

id: 2
event: health
data: {"instanceId":"...","uptime":3605,...}

Headers

Includes X-Accel-Buffering: no for nginx reverse proxy compatibility.

Response

Status Condition
200 SSE stream opened.
401 Missing or invalid Bearer token.

Example

curl -N https://swamp.example.com/api/v1/health/stream?interval=10000 \
  -H "Authorization: Bearer health-monitor.secret"

To resume after a disconnect:

curl -N https://swamp.example.com/api/v1/health/stream \
  -H "Authorization: Bearer health-monitor.secret" \
  -H "Last-Event-ID: 42"

GET /internal/runs

Returns all run records from the SQLite-backed RunTrackerStore, including completed, failed, and cancelled runs with full metadata.

Disabled by default. Enable with any of:

  • --enable-internal-api flag
  • enable-internal-api: true in the serve config file
  • SWAMP_ENABLE_INTERNAL_API=true environment variable

Returns 404 when not enabled.

Response

Status Condition
200 Run records returned.
401 Missing or invalid Bearer token.
404 Internal API not enabled (--enable-internal-api required).

Example

curl https://swamp.example.com/internal/runs \
  -H "Authorization: Bearer health-monitor.secret"

Cancel Endpoints

Cancel a running execution via HTTP. These endpoints complement the CLI commands (swamp workflow cancel, swamp model cancel) for use by external tooling, CI/CD pipelines, or custom dashboards.

POST /api/v1/cancel/:type/:id

Cancel a single running execution by type and ID.

Parameter Value Description
:type workflow-run or method-run The execution type to cancel.
:id string The execution's run ID.

Response

Status Body Condition
200 { "status": "cancelled", "executionType": "...", "executionId": "..." } The execution was confirmed stopped — deregistered within the grace period.
200 { "status": "cancellation_requested", "executionType": "...", "executionId": "..." } The abort signal was delivered but the execution is still active — it has not yet deregistered within the grace period.
401 "Unauthorized: token required" or "Unauthorized" Missing or invalid Bearer token.
404 { "status": "not_found", "message": "..." } No active execution with the given type/ID.

Example

curl -X POST https://swamp.example.com/api/v1/cancel/workflow-run/3f8a2b1c \
  -H "Authorization: Bearer paul-token.secret"

POST /api/v1/cancel

Cancel all running executions, optionally filtered by type.

Request body (optional)

Field Type Description
executionType string Filter by type: workflow-run or method-run. Omit to cancel all.
{ "executionType": "workflow-run" }

Response

Status Body Condition
200 { "status": "cancellation_requested", "count": <number> } Abort signals delivered. Returns the count of runs cancellation was requested for.
400 { "status": "error", "message": "executionType must be 'workflow-run' or 'method-run'" } Invalid executionType value.
401 "Unauthorized: token required" or "Unauthorized" Missing or invalid Bearer token.

Example

# Cancel all running executions
curl -X POST https://swamp.example.com/api/v1/cancel \
  -H "Authorization: Bearer paul-token.secret"

# Cancel only workflow runs
curl -X POST https://swamp.example.com/api/v1/cancel \
  -H "Authorization: Bearer paul-token.secret" \
  -H "Content-Type: application/json" \
  -d '{"executionType": "workflow-run"}'