Skip to main content

Synopsis

npx @refrainai/cli serve
Starts the HTTP API server that powers the Web Console and enables remote runbook execution. The server provides REST endpoints, SSE streaming, job scheduling via Inngest, and real-time updates via Redis Pub/Sub.
The API server requires Team plan or higher for remote execution features.

Prerequisites

Before starting the server, ensure you have:
  1. PostgreSQL — Database for runbooks, jobs, settings, and metering
  2. Redis — Required for SSE real-time streaming and Pub/Sub
  3. Inngest (optional) — Job queue for scheduled and background execution

Environment variables

Required

VariableDescription
DATABASE_URLPostgreSQL connection string
REDIS_URLRedis connection string
BETTER_AUTH_SECRETSecret for authentication (session signing)

Optional

VariableDefaultDescription
PORT3000Server port
INNGEST_EVENT_KEY-Inngest event key for job queue
INNGEST_SIGNING_KEY-Inngest signing key
REFRAIN_API_KEY-Default API key

AI provider credentials

The server uses the same AI provider environment variables as the CLI:
VariableDescription
ANTHROPIC_API_KEYAnthropic API key
OPENAI_API_KEYOpenAI API key
GOOGLE_GENERATIVE_AI_API_KEYGemini API key
AZURE_RESOURCE_NAMEAzure OpenAI resource name
AZURE_API_KEYAzure OpenAI API key
AWS_REGIONAWS region for Bedrock
AWS_ACCESS_KEY_IDAWS access key for Bedrock
AWS_SECRET_ACCESS_KEYAWS secret key for Bedrock
GOOGLE_VERTEX_PROJECTGoogle Cloud project for Vertex
GOOGLE_VERTEX_LOCATIONGoogle Cloud region for Vertex

Setup

1

Configure environment

Create a .env file with required variables:
DATABASE_URL="postgresql://user:pass@localhost:5432/refrain"
REDIS_URL="redis://localhost:6379"
BETTER_AUTH_SECRET="your-random-secret"
ANTHROPIC_API_KEY="sk-ant-..."
2

Run database migrations

npx @refrainai/cli db:migrate
3

Start the server

npx @refrainai/cli serve

API endpoints

The server exposes REST endpoints for managing runbooks, jobs, and settings. All endpoints require authentication via API key or session.
EndpointMethodDescription
/api/runbooksGETList runbooks
/api/runbooksPOSTCreate a runbook
/api/runbooks/:idGETGet runbook details
/api/jobsPOSTCreate a job (execute/generate/self-heal)
/api/jobsGETList jobs
/api/jobs/:idGETGet job details
/api/jobs/:id/streamGETSSE stream for real-time updates
/api/jobs/:id/approvePOSTApprove a waiting job
/api/jobs/:id/rejectPOSTReject a waiting job
/api/jobs/:id/cancelPOSTCancel a running job
See SDK for programmatic usage.