Skip to main content

HTTP API

Every Orchestate capability is available over a plain JSON REST API. The TypeScript SDK is a thin wrapper around these endpoints — use the raw API when you are working from a language without an SDK, from a shell script, or from another backend service.

Base URL and authentication

The supported REST API lives under /api/v1 on the app origin. On the hosted service that is:

https://orchestate.wentzel.ai/api/v1

Every request (except the WebSocket inspector, noted below) must include an API key as a bearer token. GET /api/health is not part of this API-key surface: it answers only an internal caller (Cloudflare Access or the service-binding secret), described under GET /api/health below.

Authorization: Bearer orch_YOUR_API_KEY

API keys are created in the console under Settings → API Keys and have the form orch_ followed by 48 hex characters. The raw key is shown once at creation and stored only as a SHA-256 hash, so copy it immediately. See Auth & API keys for the full lifecycle.

Request and response bodies are JSON. Send Content-Type: application/json on any request with a body. CORS is enabled and OPTIONS preflight requests are supported, so the API can be called directly from the browser.

Versioning and migration

The unversioned REST paths, such as /api/machines and /api/instances, are deprecated aliases of their /api/v1 successors. They were deprecated on October 26, 2026, and may stop working on April 24, 2027. Alias responses include Deprecation, Sunset, and a Link header with rel="successor-version" pointing to the matching versioned path, including on error responses.

Migrate REST requests to /api/v1, preserving the remaining path, query parameters, method, bearer token, and JSON body. The v1 bridge reuses the existing handlers; versioned responses do not announce alias deprecation. The WebSocket inspector at /api/inspect/{instanceId} and internal health at /api/health retain their separate URLs and authentication contracts below.

POST /api/v1/machines

Publish a machine definition. Each publish creates a new immutable version under the given slug. See Machine definitions for the definition schema.

FieldTypeRequiredDescription
slugstringYesStable identifier, matches ^[a-z0-9-]+$, up to 80 characters.
namestringNoHuman-readable display name.
definitionobjectYesThe machine definition: { initial, states } (optional context).
curl -X POST https://orchestate.wentzel.ai/api/v1/machines \
  -H "Authorization: Bearer orch_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "slug": "checkout",
    "name": "Checkout flow",
    "definition": {
      "initial": "cart",
      "states": {
        "cart": { "on": { "SUBMIT": "paid" } },
        "paid": { "type": "final" }
      }
    }
  }'

201 Created

{
  "id": "mch_8c1f0a2b3d4e5f6a",
  "version": 1
}

GET /api/v1/machines

List the published machines for your organization.

curl https://orchestate.wentzel.ai/api/v1/machines \
  -H "Authorization: Bearer orch_YOUR_API_KEY"

200 OK

[
  {
    "id": "mch_8c1f0a2b3d4e5f6a",
    "slug": "checkout",
    "name": "Checkout flow",
    "currentVersion": 1,
    "updatedAt": "2026-06-09T12:00:00.000Z"
  }
]

GET /api/v1/machines/{idOrSlug}

Fetch a single machine by its id or slug, scoped to your organization.

curl https://orchestate.wentzel.ai/api/v1/machines/checkout \
  -H "Authorization: Bearer orch_YOUR_API_KEY"

200 OK

{
  "id": "mch_8c1f0a2b3d4e5f6a",
  "slug": "checkout",
  "name": "Checkout flow",
  "currentVersion": 1,
  "definition": { "initial": "cart", "states": { "cart": {}, "paid": {} } },
  "createdAt": "2026-06-09T12:00:00.000Z",
  "updatedAt": "2026-06-09T12:00:00.000Z"
}

Returns 404 if no machine with that id or slug exists in your organization.

POST /api/v1/instances

Create a running instance of a published machine. The instance starts in the machine's initial state. The runtime executes in a Cloudflare Durable Object.

FieldTypeRequiredDescription
machineSlugstringYesSlug of the machine to instantiate.
contextobjectNoInitial context merged into the machine's default context.
curl -X POST https://orchestate.wentzel.ai/api/v1/instances \
  -H "Authorization: Bearer orch_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machineSlug": "checkout",
    "context": { "cartId": "cart_123" }
  }'

201 Created

{
  "id": "ins_5a6b7c8d9e0f1a2b",
  "currentState": "cart",
  "status": "active",
  "machineVersion": 1,
  "createdAt": "2026-06-09T12:01:00.000Z"
}

Returns 404 if the machine slug does not exist and 502 if the runtime fails to start the instance.

GET /api/v1/instances

List instances in your organization, newest first. At most 200 are returned; this endpoint does not provide pagination. Both query parameters are optional and can be combined:

  • machineSlug — filter by a machine slug in your organization. An unknown slug returns 200 OK with an empty array ([]).
  • status — one of active, done, error, or cancelled. An unsupported value returns 400 Bad Request with an Invalid status error; it is not an empty result. Omit either filter to leave it unrestricted.
curl "https://orchestate.wentzel.ai/api/v1/instances?machineSlug=checkout&status=active" \
  -H "Authorization: Bearer orch_YOUR_API_KEY"

200 OK

[
  {
    "id": "ins_5a6b7c8d9e0f1a2b",
    "currentState": "cart",
    "status": "active",
    "machineVersion": 1,
    "createdAt": "2026-06-09T12:01:00.000Z",
    "updatedAt": "2026-06-09T12:01:00.000Z"
  }
]

GET /api/v1/instances/{id}

Fetch a single instance by id, including its current state and context snapshot.

curl https://orchestate.wentzel.ai/api/v1/instances/ins_5a6b7c8d9e0f1a2b \
  -H "Authorization: Bearer orch_YOUR_API_KEY"

200 OK

{
  "id": "ins_5a6b7c8d9e0f1a2b",
  "currentState": "paid",
  "context": { "cartId": "cart_123" },
  "status": "active",
  "machineVersion": 1,
  "createdAt": "2026-06-09T12:01:00.000Z",
  "updatedAt": "2026-06-09T12:02:00.000Z"
}

Returns 404 if the instance does not exist in your organization.

POST /api/v1/instances/{id}/events

Send an event to a running instance. If the current state defines a transition for the event type, the instance moves to the target state and any assign actions on the transition are applied.

FieldTypeRequiredDescription
typestringYesEvent name, matched against the current state's on map.
payloadobjectNoArbitrary data carried with the event.
curl -X POST https://orchestate.wentzel.ai/api/v1/instances/ins_5a6b7c8d9e0f1a2b/events \
  -H "Authorization: Bearer orch_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "SUBMIT",
    "payload": { "amount": 4200 }
  }'

200 OK

{
  "fromState": "cart",
  "toState": "paid",
  "final": true
}

When toState is a final state, final is true and the instance status becomes done. Returns 404 if the instance does not exist, 409 if the instance is no longer active, and 422 if the current state has no transition for the event or a guard rejected it (code: "GUARD_REJECTED").

Idempotency — send an Idempotency-Key header to make retries safe. A replayed key returns the original transition result with "replayed": true and does not re-run the transition or append to the event log.

GET /api/v1/instances/{id}/events

The instance's transition history, newest first. Each row records the event type, payload, and the from/to states — an audit trail for the instance. Query params: limit (default 50, max 200) and before. When older rows remain, the response carries an opaque X-Next-Cursor header; pass it back as before for the next page (the header is absent on the last page). The cursor encodes each row's (createdAt, id), so events written in the same millisecond never skip or repeat across pages. A legacy ISO timestamp or epoch-ms before is still accepted and returns rows strictly older than it.

curl -i "https://orchestate.wentzel.ai/api/v1/instances/ins_5a6b7c8d9e0f1a2b/events?limit=20" \
  -H "Authorization: Bearer orch_YOUR_API_KEY"

// 200 OK
// X-Next-Cursor: gc1.…   (pass as ?before= for the next page)
[
  {
    "id": "…",
    "eventType": "SUBMIT",
    "payload": { "amount": 4200 },
    "fromState": "cart",
    "toState": "paid",
    "createdAt": "2026-06-10T12:18:32.000Z"
  }
]

POST /api/v1/instances/batch

Create up to 10 instances in one request. The body is { "items": [...] }, each item exactly the POST /api/v1/instances body. Items run in order and each gets its own result — one failed item never aborts the rest. Every item counts against the same per-org create rate limit as the single endpoint: items past the limit come back as per-item 429, and the whole request is 429 when no budget is left. An empty or over-10 batch is 400, and a body over 1 MB is 413. Creates are not idempotent: if a batch times out, list your instances before retrying, or a retry can create every item again.

curl -X POST https://orchestate.wentzel.ai/api/v1/instances/batch \
  -H "Authorization: Bearer orch_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "items": [
    { "machineSlug": "checkout", "context": { "cartId": "cart_123" } },
    { "machineSlug": "no-such-machine" }
  ] }'

// 200 OK
{
  "results": [
    { "index": 0, "ok": true, "status": 201, "result": { "id": "ins_…", "currentState": "cart", … } },
    { "index": 1, "ok": false, "status": 404, "error": { "error": "Machine not found" } }
  ],
  "succeeded": 1,
  "failed": 1
}

POST /api/v1/events/batch

Send up to 25 events in one request, applied in order (so several events for the same instance apply in the order sent). Each item is the POST /api/v1/instances/{id}/events body plus its target instanceId and an optional per-item idempotencyKey; pass a caller token per item in callerToken. Each item's status and result / error match what the single endpoint would return (404, 409, 422 GUARD_REJECTED, …), and items draw from the same per-org event rate limit. A body over 1 MB is 413.

Rate limits and batches — each batch item counts as one request against the same per-org limit as the matching single endpoint (see Rate limits below). The limit is enforced atomically, so batches sent concurrently can never together exceed it: items past the remaining budget come back as per-item 429.

Retries — if a batch times out or fails in transit, retrying it re-applies every item that has no idempotencyKey. Give each item a stable idempotencyKey: on retry, the items that already applied return their original result with "replayed": true instead of transitioning again.

curl -X POST https://orchestate.wentzel.ai/api/v1/events/batch \
  -H "Authorization: Bearer orch_YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "items": [
    { "instanceId": "ins_5a6b7c8d9e0f1a2b", "type": "SUBMIT", "payload": { "amount": 4200 } },
    { "instanceId": "ins_0000000000000000", "type": "SUBMIT" }
  ] }'

// 200 OK
{
  "results": [
    { "index": 0, "ok": true, "status": 200, "result": { "fromState": "cart", "toState": "paid", "final": true, … } },
    { "index": 1, "ok": false, "status": 404, "error": { "error": "Instance not found" } }
  ],
  "succeeded": 1,
  "failed": 1
}

Webhooks

Transitions whose machine definition carries an emit action POST a signed JSON payload to every enabled webhook endpoint configured for your organization. Verify the X-Orchestate-Signature header: sha256=<hex>, the HMAC-SHA256 of t=<unix seconds>.<raw body> keyed with the endpoint secret. The matching unix seconds are in X-Orchestate-Timestamp. X-Orchestate-Event-Id is the same on every retry of one event, so use it as your idempotency key after the signature and timestamp check. The payload carries type: "machine.transition", the instance and machine ids, the event type, from/to states, final, the post-transition context, the emit action params, and occurredAt. Each POST times out after 5 seconds. When the webhook queue is bound, a 5xx, 408, 429, or transport error is retried after 1 minute, 5 minutes, 15 minutes, 1 hour, and 6 hours; any other 4xx is not retried. Receivers should respond 2xx quickly and process asynchronously. Manage endpoints under Settings → Webhooks, or with /api/v1/webhooks. POST /api/v1/webhooks/{id}/rotate-secret replaces the signing secret and returns the new one once. Creating, updating, deleting, and rotating require an organization owner or admin signed in to the console; members and API keys can read endpoints and delivery attempts and receive 403 on changes.

GET /api/inspect/{instanceId}

A WebSocket upgrade endpoint for the live inspector. Once connected, the server pushes a JSON message on every transition:

{ "type": "transition", "toState": "paid", "context": { "cartId": "cart_123" } }

Note — This endpoint is authenticated by the logged-in browser session cookie, not by an API key, so it is intended for use from an authenticated browser context. The SDK's client.instances.subscribe() opens this socket (it appends a ?key= parameter that the server currently ignores in favor of the session) — see the SDK reference.

GET /api/health

Internal health envelope. It is not an API-key route. A request with a valid Cloudflare Access assertion (Cf-Access-Jwt-Assertion) or X-Wentzel-Health-Binding equal to the Worker secret receives the body below. Every other request gets 404 with an empty body, and no check runs.

curl https://orchestate.wentzel.ai/api/health \
  -H "Cf-Access-Jwt-Assertion: $CF_ACCESS_JWT"

200 OK — an authorised caller always receives 200. Degradation is reported in bindings and checks, not in the status code. An anonymous caller does not receive this body.

{
  "service": "orchestate",
  "version": "<git sha>",
  "deployed_at": "<iso-8601>",
  "bindings": { "D1": "ok", "ANALYTICS_ENGINE": "ok", "KV_RATE_LIMIT": "ok" },
  "checks": { "d1_ping": { "ok": true, "latency_ms": 7 } }
}

Rate limits

Limits are applied per organization, per minute. Exceeding a limit returns a 429 response. Instance creates and event sends use a token bucket: the full per-minute budget is available as a burst and refills evenly over the minute (one create per second, five events per second). Each batch item counts as one request against the same budget as the single endpoint.

EndpointLimit
POST /api/v1/machines100 requests / minute / org
POST /api/v1/instances + /api/v1/instances/batch items60 / minute / org, shared
POST /api/v1/instances/{id}/events + /api/v1/events/batch items300 / minute / org, shared

Errors

Errors are returned with the appropriate HTTP status and a JSON body of the shape { "error": "<message>" }.

StatusMeaning
400Invalid request body.
401Missing or invalid API key.
404Machine or instance not found.
409Instance is not active (already done, error, or cancelled).
429Rate limit exceeded.
502Upstream runtime error while starting or stepping an instance.
503Service unavailable — the rate limiter could not be consulted on an instance-create or event-send request (Rate limiter unavailable; safe to retry). GET /api/health does not return 503.

See also