StepflowStepflow

API Reference

Complete HTTP API reference for Stepflow

API Reference

Stepflow exposes a REST API through framework adapters. All adapters implement the same endpoints.

Base URL

The base URL depends on your adapter configuration:

// Hono
app.route("/api/stepflow", createStepflowRoutes(stepflow));

// Express
app.use("/api/stepflow", createStepflowRouter(stepflow));

// Next.js
// Routes are at /api/stepflow/[...path]

Authentication

Stepflow supports multiple authentication methods:

API Key

curl -X POST https://api.example.com/api/stepflow/trigger/my-workflow \
  -H "X-API-Key: your-api-key" \
  -H "Content-Type: application/json" \
  -d '{"userId": "123"}'

Bearer Token

curl -X POST https://api.example.com/api/stepflow/trigger/my-workflow \
  -H "Authorization: Bearer your-jwt-token" \
  -H "Content-Type: application/json" \
  -d '{"userId": "123"}'

Public Access Token

For client-side run monitoring:

curl https://api.example.com/api/stepflow/runs/run_123?token=pat_xyz

Endpoints

Trigger Workflow

Start a new workflow execution.

POST /trigger/{workflowId}

Parameters:

NameInTypeRequiredDescription
workflowIdpathstringYesWorkflow identifier

Request Body:

{
  "userId": "user_123",
  "email": "user@example.com"
}

Response:

{
  "runId": "run_abc123",
  "publicAccessToken": "pat_xyz789"
}

Status Codes:

CodeDescription
200Workflow triggered successfully
400Invalid request body
401Unauthorized
404Workflow not found

Get Run

Retrieve the current status of a workflow run.

GET /runs/{runId}

Parameters:

NameInTypeRequiredDescription
runIdpathstringYesRun identifier
tokenquerystringNoPublic access token

Response:

{
  "id": "run_abc123",
  "workflowId": "welcome-user",
  "status": "running",
  "input": {
    "userId": "user_123",
    "email": "user@example.com"
  },
  "steps": [
    {
      "name": "send-welcome",
      "status": "completed",
      "result": { "sent": true }
    },
    {
      "name": "send-followup",
      "status": "pending"
    }
  ],
  "createdAt": "2024-01-15T10:30:00Z",
  "updatedAt": "2024-01-15T10:31:00Z"
}

Run Status Values:

StatusDescription
pendingRun is queued
runningRun is executing
completedRun finished successfully
failedRun failed with error
cancelledRun was cancelled

Stream Run Updates

Subscribe to real-time updates via Server-Sent Events (SSE).

GET /runs/{runId}/stream

Parameters:

NameInTypeRequiredDescription
runIdpathstringYesRun identifier
tokenquerystringNoPublic access token

Response:

event: status
data: {"status":"running","stepName":"send-email"}

event: step
data: {"name":"send-email","status":"completed","result":{"sent":true}}

event: complete
data: {"status":"completed","result":{"success":true}}

Event Types:

EventDescription
statusRun status changed
stepStep completed or failed
completeRun finished
errorRun failed

Notify Event

Send an event to a waiting workflow.

POST /notify/{eventId}

Parameters:

NameInTypeRequiredDescription
eventIdpathstringYesEvent identifier

Request Body:

{
  "status": "paid",
  "amount": 99.99,
  "transactionId": "txn_456"
}

Response:

{
  "success": true
}

Health Check

Check service health status.

GET /health

Response:

{
  "status": "ok",
  "timestamp": "2024-01-15T10:30:00Z"
}

OpenAPI Specification

The complete OpenAPI 3.1 specification is available at:

You can import this into tools like Postman, Insomnia, or use it to generate client SDKs.

Error Responses

All error responses follow this format:

{
  "error": "Workflow not found",
  "code": "WORKFLOW_NOT_FOUND"
}

Common error codes:

CodeHTTP StatusDescription
WORKFLOW_NOT_FOUND404Workflow ID doesn't exist
RUN_NOT_FOUND404Run ID doesn't exist
EVENT_NOT_FOUND404Event ID doesn't exist
UNAUTHORIZED401Missing or invalid auth
INVALID_INPUT400Request body validation failed

On this page