API Reference

REST API endpoints for running agents, streaming results, and checking status.

Starting the Server

sandcaster serve --port 8000

The server runs a Hono-based HTTP service. By default it listens on port 3000. Use --host 0.0.0.0 to bind to all interfaces in production.

Authentication

Authentication is optional. Set the SANDCASTER_API_KEY environment variable to enable Bearer token auth:

SANDCASTER_API_KEY=my-secret-token sandcaster serve

When set, all API requests must include:

Authorization: Bearer my-secret-token

If the env var is not set, the server accepts all requests without checking credentials.


GET /health

Returns the server status and version. Use this for load balancer health checks and uptime monitoring.

Response

{
	"status": "ok",
	"version": "0.1.0"
}

POST /query

Run an agent and stream results as Server-Sent Events (SSE).

Request Body

FieldTypeRequiredDescription
promptstringYesThe user prompt to send to the agent
modelstringNoModel alias or full ID, overrides sandcaster.json
maxTurnsintegerNoMax conversation turns for this run
timeoutintegerNoSandbox lifetime in seconds
filesobject[]NoFiles to upload: [{ name, content (base64) }]
outputFormatobjectNoJSON Schema for structured output
allowedToolsstring[]NoTool whitelist for this run
compositeobjectNoMulti-sandbox settings (see Configuration)
providerstringNoLLM provider override
sandboxProviderstringNoSandbox backend override

SSE Event Types

The response is a stream of text/event-stream events. Each event has a type field:

Event typeDescription
systemServer lifecycle messages (sandbox created, agent started, etc.)
assistantA chunk of the agent’s text response
userA user-turn message echoed back (rare, used in multi-turn runs)
resultFinal result with cost, token usage, and structured output if requested
warningNon-fatal issues (tool call rejected, soft limit approached)
errorFatal error that terminated the run

Example Request

curl -N -X POST http://localhost:8000/query \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer my-secret-token" \
  -d '{
    "prompt": "Compare Notion, Coda, and Slite for async product teams",
    "model": "sonnet",
    "maxTurns": 30
  }'

Example SSE Response

event: system
data: {"type":"system","message":"Sandbox created","sandboxId":"abc123"}

event: assistant
data: {"type":"assistant","content":"Let me research these tools..."}

event: assistant
data: {"type":"assistant","content":" starting with Notion."}

event: result
data: {"type":"result","content":"...full response...","costUsd":0.0042,"inputTokens":1204,"outputTokens":876}

GET /runs

List recent agent runs. Useful for audit logs and run history.

Query Parameters

ParameterTypeDefaultDescription
limitinteger20Maximum number of runs to return

Example Request

curl http://localhost:8000/runs?limit=5 \
  -H "Authorization: Bearer my-secret-token"

Response

[
	{
		"id": "run_abc123",
		"prompt": "Compare Notion, Coda, and Slite",
		"model": "claude-sonnet-4-6",
		"status": "completed",
		"costUsd": 0.0042,
		"inputTokens": 1204,
		"outputTokens": 876,
		"startedAt": "2026-03-20T14:22:10Z",
		"completedAt": "2026-03-20T14:22:38Z"
	}
]

POST /webhooks/e2b

Receives lifecycle events from E2B for sandbox monitoring. This endpoint is called by E2B infrastructure — you do not need to call it directly.

Register the URL with E2B as a webhook target if you want Sandcaster to react to sandbox events (e.g., unexpected termination, quota warnings).