Skip to content

REST API

The API is a Cloudflare Worker. A client sends a prompt to one route and reads the run back as a stream of server-sent events. With thread storage configured, the conversation can live on the server instead of in the client, and each run continues from the server’s copy.

Paths are relative to the API origin. Every route is listed in the route index.

The run and thread routes take the deployment’s API token as a bearer token:

authorization: Bearer …

The token is the Worker’s FELIX_API_TOKEN; see Models and embeddings. A missing or wrong token is refused with HTTP 401. GET /health, GET /ready and GET /demo need no token.

On a deployment with sign-in, a person’s session token is sent the same way, and a member reaches only their own threads; see Sign-in and sessions and Auth.

POST /v1/runs/stream with a JSON body (content-type: application/json) of at most 128 KiB. There are two forms, and a hosted thread can also be continued. The route’s earlier name, POST /v1/chat/stream, is still accepted and answers identically, so older clients keep working; new clients should send /v1/runs/stream. Likewise, GET /health still sends chat beside model. The error code for a missing model is now model_not_configured; it was chat_not_configured.

Stateless. The client keeps the history and sends it with each prompt.

{ "prompt": "What changed?", "history": [{ "role": "user", "text": "Hello" }] }

Hosted. The server keeps the history. The client names a thread and the revision it last saw, and must not send history.

{ "prompt": "What changed?", "threadId": "…", "revision": 4 }

Continue. Run a hosted thread again with no new message, after a run that failed or was stopped before or partway through its reply. It takes no prompt, history or images; 409 nothing_to_continue when the last turn already has its finished reply.

{ "continue": true, "threadId": "…", "revision": 4 }
Field Form Rule
prompt Both Required, except to continue. At most 32,768 characters, not only whitespace; it may be empty when images are attached.
history Stateless Optional. At most 200 messages.
threadId Hosted Letters, digits, - and _, 1 to 100 characters.
continue Hosted Optional. Only true, with threadId and revision and no prompt. See Continue above.
revision Hosted Required with threadId. A non-negative integer: the thread’s revision from your last read or thread frame. It moves forward on every change to the conversation (a message, a rewind, a compaction) and never repeats, so a request made from an out-of-date view is refused with 409 stale_revision. messageCount is how many messages the active branch holds.
images Both Optional. At most 8 images uploaded first to /v1/images, each { mimeType, ref }. Only images you uploaded, or that were sent on one of your threads, can be sent (an admin can send any); another is refused as unknown_image.
model Both Optional. A model id from GET /v1/models; 400 unknown_model for any other, and 403 model_not_allowed for a model kept for admins when the caller is not one. The deployment’s default without it.
agent Stateless Optional. An agent id from GET /v1/agents; 400 unknown_agent for any other. The default agent without it. A hosted thread runs as its own agent.
outputStyle Stateless Optional. One of the agent’s output styles; its default when absent or not one it declares. A hosted thread writes in its own (PATCH /v1/threads/<id>).
clientTools Hosted Optional. Up to 16 tools the client runs itself, each { name, description, parameters } with an object JSON Schema. See client_tool_call below.
reasoning Both Optional. off, low, medium, high, xhigh or max. The deployment’s FELIX_REASONING without it.
background Hosted Optional. Only true. Your client will not follow this run, so when it finishes or fails, the conversation’s owner gets a push notification (see Notifications). A run stopped with the stop route sends none.
requestId Hosted Optional. 1 to 128 letters, digits, - and _, chosen by your client. If a response is lost on the way, send the same request again with the same id: while the run it started is the thread’s latest, you get that run’s stream from its start instead of 409 stale_revision or run_in_progress.

Any other field is refused. The model, system prompt and tools are chosen by the server, not the request.

A message in history is one of:

role Fields
user text, optional images
assistant text, calls: a list of { id, name, arguments }, optional reasoning: a list of { text, signature?, redacted? }
tool callId, text, error (boolean), optional images

A system message is refused.

curl -N https://api.example.com/v1/runs/stream \
-H 'authorization: Bearer …' \
-H 'content-type: application/json' \
-d '{"prompt":"Hello"}'

The response is text/event-stream. Each event is one data: line holding a JSON envelope:

data: {"version":1,"event":{"type":"text","text":"Hello"}}

After 15 seconds with no event to send, as during a long tool call, the stream sends a comment line, : keep-alive. SSE readers skip comments. A client can treat a stream that has sent one and then stays silent much longer, say 45 seconds, as dropped, and rejoin it.

How a run becomes server-sent frames, and how a client rejoinsA run request runs one of two ways. Stateless, or on a deployment without RUNS, eventResponse writes each event as a data frame with no id straight to the response, and a disconnect aborts the run, leaving a hosted thread interrupted. A hosted request on a deployment with RUNS runs in the thread's ThreadRuns Durable Object. Its run host records the run in the object's storage before it starts, so a restart finds it and either resumes it with FELIX_RESUME_RUNS=on or releases its lease. The host pumps the run's frames into a buffer kept in the object's memory, at most 8 MiB, from which streamed text and reasoning are dropped once the message they belong to commits. Every client reads that buffer through a subscription whose frames carry an SSE id, the position run.seq; closing a subscription detaches that client and the run goes on. A client rejoins with GET /v1/threads/ID/events and after= the last position, or the Last-Event-ID header, and gets the frames after it and then live ones until the run ends; a position from an earlier run replays the latest run from its start, there being no run answers 404 no_run, and a malformed position 400 invalid_position. The run socket, with FELIX_RUN_SOCKET=on, reads the same events route in-process. POST /v1/threads/ID/stop aborts the run and ends the command it was running, with its whole process group, but leaves the thread's sandbox running; every stream ends with an error frame run_stopped.noa disconnect aborts the runyessaved before the run, clearedafterid: run.seq on every frameclosing it detaches;the run goes onGET/v1/threads/ID/events?after=POSor Last-Event-IDsame route, in-processframes after POS, then live404 no_run, 400invalid_positionPOST /v1/threads/ID/stoperror run_stoppedPOST/v1/runs/streamhosted thread,RUNS bound?eventResponse inthe requestdata: frames, noidClientThreadRuns runhostpumps the run'sframesrun-in-flightrecordobject storageKept frames, inmemory, ≤ 8 MiBtext dropped onceits messagecommitssubscriptionhost.eventsrun socketFELIX_RUN_SOCKET=onNothing to rejoinstop: abort therun and itscommand;the sandboxkeeps runningRun stream frames and rejoining
How does a run become server-sent frames, and how does a client rejoin?Drawn from docs/diagrams/stream-path.mmd, which follows apps/api/src/http/events.ts:eventResponse, apps/api/src/runs/run-host.ts:createRunHost (pump, subscribe, events, stop), apps/api/src/runs/run-object.ts:ThreadRuns, apps/api/src/app.ts:runControl..

version is always 1. A client should refuse any other version and any event type it does not know.

Each frame links to itself (#event-<type>). The dot is the run’s state while that frame is the newest, as on the home page: in flight, waiting on someone, finished, failed. Frames with no dot do not change it.

text
Reply text as it streams. For display; it is not a saved message.
text
reasoning
The model’s reasoning as it streams. For display; the saved assistant message carries it.
text
reasoning_reset
The reasoning sent since the last assistant message is withdrawn: the model call it belonged to failed before any text or tool call and is being made again. Clear it and draw what follows.
approval_required
A tool call is waiting for a decision. Decide it with POST /v1/approvals/<approval_id>/decide; the run continues, or the call is refused, when it is decided or its deadline passes.
data: { approval_id, tool_name, args, rule_id, reason, thread_id, tool_call_id, expires_at, one_shot? }
client_tool_call
The model called one of your clientTools. Run it and post { callId, text, error? } to POST /v1/threads/<id>/tool-results; after 5 minutes without an answer the call fails.
callId, name, input
mcp_skipped
Configured MCP servers this run could not use: missing_secret, timeout or unreachable.
servers: [{ server, reason }]
approval_resolved
A waiting call was approved, denied, or lapsed (timeout). Its tool result follows.
data: { approval_id, tool_call_id, outcome, note? }
message
A finished assistant or tool message, in the shape above.
message
tool_start
A tool call is starting. It can still be refused or fail.
callId, name
usage
Token counts for one model call. modelTurn starts at 1. Sent only when the provider reports them. With unfinished: true the call was stopped or failed after the provider had counted it: it is still billed, so it is still reported, and a retried call sends one for each failed attempt.
modelTurn, usage: { inputTokens, outputTokens, cachedInputTokens? }, unfinished?
steer_dropped
Hosted only: ids of steers sent to this run that it ended without taking. Sent before thread.
steers
gap
Rejoining only: events after your position were dropped from what the run keeps (8 MiB at most). The stream goes on from the oldest event kept; read the thread for what you missed.
none
thread
Hosted only: the thread summary after the run, with its new revision.
thread
end
The run is over. limit means it stopped at a limit, not with a finished reply.
reason: complete or limit
error
The run failed after the stream started, or was stopped with POST /v1/threads/<id>/stop.
code: run_failed or run_stopped, message

The prompt itself is saved as a user message but is not sent back as a message frame. A successful hosted run sends thread and then end. A failed run sends error instead of end, possibly after some text. A stream that closes with neither end nor error is incomplete.

A run takes at most 20 model turns and ten minutes. Closing the connection stops the run, except a hosted run on a deployment with the RUNS binding: that run keeps going, can be rejoined with GET /v1/threads/<id>/events, and stops with POST /v1/threads/<id>/stop.

Errors found before the stream starts are HTTP responses with a JSON body:

{ "error": { "code": "unauthorized" } }
Status code When
400 invalid_request The body is not valid JSON or breaks a rule above.
401 unauthorized The bearer token is missing or wrong.
404 thread_not_found Hosted: no thread has that id.
405 Not POST. Plain text, with allow: POST.
409 stale_revision Hosted: the thread is not at the revision sent.
429 rate_limited Over the rate limit; retry-after says how many seconds to wait. See below.
409 run_in_progress Hosted: another run holds the thread.
413 request_too_large The body is over 128 KiB.
415 expected_json The content type is not application/json.
503 model_not_configured The Worker has no token or no usable model configured.
503 threads_not_configured Hosted: thread storage is not configured.
503 storage_unavailable, corrupt_thread_log, unsupported_format Hosted: storage failed, the stored thread does not add up, or it was written by a newer Felix than the one running (after a rollback).
503 jurisdiction_misconfigured FELIX_JURISDICTION is set to something other than eu, us or fedramp. See Data location.
409 jurisdiction_data_elsewhere FELIX_JURISDICTION is set, and the deployment’s data is not yet in that jurisdiction.

Once the stream has started, a failure is an error frame with code run_failed and a fixed message. Provider and storage error text is never sent to the client.

When the deployment binds a rate limiter, every /v1/ route shares one budget of 300 units a minute, sign-in included, counted per signed-in person, for the operator token, or per client address for a request without a valid token. A person and the operator token each have that budget twice: once for reads (GET and HEAD) and once for every other request. A run request, an MCP call or starting a sign-in costs 10 units and anything else 1, so 30 run requests a minute fit. Over it, the API answers 429 rate_limited with retry-after: 60. /health, /ready and /demo are not limited.

Thread routes need the token and thread storage. Without storage they answer 503 threads_not_configured.

Route Response
POST /v1/threads 201 with a new, empty thread. The server picks the id.
GET /v1/threads { threads, cursor? }: up to 100 summaries. ?asking=true returns only threads whose run waits on a person’s answer to a question.
GET /v1/threads?cursor=<id> The page after that id.
GET /v1/threads/<id> The thread with its messages.
PATCH /v1/threads/<id> Body { title?, mode?, outputStyle? }, at least one: the updated summary. title is 1 to 120 characters. mode is default, plan (only read-only tools run) or bypass (approval rules are skipped; 403 bypass_not_allowed unless the deployment sets FELIX_ALLOW_BYPASS=on and the caller is an admin). outputStyle is one of the thread’s agent’s output styles, or null for its default; another name is refused with 422 unknown_output_style.
DELETE /v1/threads/<id> { deleted, removedImages }. 409 run_in_progress while a run holds the thread. It cannot be undone.
GET /v1/thread-search?q=<text> { hits, cursor? }: threads whose title or messages contain the text, newest first, each { thread, snippet }. limit is 1 to 50 (20 by default). A cursor means there is more; pass it back, unchanged, to continue (it is opaque).
GET /v1/traces { traces, cursor? }: stored run traces, newest first; filter with name, errors=1, start_min, start_max, attr.<key>=<value>. Needs TELEMETRY.
GET /v1/traces/<traceId> One stored trace’s spans.
GET /v1/metrics?name=<metric> { metrics }: aggregates per series per ten seconds.
GET /v1/models { default, models }: the models a request may name, each { id, label?, provider?, access?, contextWindow?, maxOutputTokens?, vision?, reasoning? }. access: "admins" marks a model only admins may choose, and only admins see it listed.
GET /v1/threads/<id>/socket · POST …/socket/ticket With FELIX_RUN_SOCKET=on: one WebSocket for the thread’s runs. See The run socket.
GET /v1/threads/<id>/feed · POST …/feed/ticket A WebSocket that says when the thread changes, whoever changed it. See The change feed.
GET /v1/thread-feed · POST /v1/thread-feed/ticket A WebSocket that says when the list of your threads (every thread, for an admin) may have changed. See The change feed.
GET /v1/threads/<id>/events?after=<position> Needs RUNS. Rejoin the thread’s latest run: its events after position, then live ones until it ends. 404 no_run when there is none to rejoin; read the thread instead.
POST /v1/threads/<id>/stop Needs RUNS. { stopped }: stop the thread’s running run. Its streams end with error run_stopped.
GET /v1/threads/<id>/outputs/<outputId> Needs OUTPUTS. The whole text of a tool output the conversation kept because it was too long (the id in its [output:…] marker), as plain text.
GET /v1/threads/<id>/plans { plans }: the thread’s plans as the agent’s tools read them, each { id, plan, updatedAt }. PUT and DELETE on /v1/threads/<id>/plans/<planId> edit or delete one by hand, over the version read (expectedUpdatedAt); 409 plan_changed with current when it moved since.
GET /v1/threads/<id>/runs { runs, cursor? }: the thread’s runs, newest first, each with its outcome, the schedule that started it (if one did), model, turns, token counts, estimated cost and tool calls. cost is { priced: true, usd }, or { priced: false } when the model has no price; see Model prices. The newest 100 are kept. Pass cursor for the next page.
POST /v1/threads/<id>/tool-results Body { callId, text, error? }: 202. Answers a client_tool_call the running run waits for. 409 no_pending_call otherwise.
GET /v1/threads/<id>/schedules Needs RUNS. { schedules }: each { id, name?, prompt, nextAt, everyMinutes?, cron?, timezone?, createdAt, paused?, lastRunAt?, lastOutcome?, lastError? }.
POST /v1/threads/<id>/schedules Needs RUNS. Body { name?, prompt, paused?, at?, everyMinutes? }, with at (epoch milliseconds) or everyMinutes (5 to 10080) or both; or { name?, prompt, paused?, cron, timezone? }, a five-field cron expression read in an IANA zone (UTC when absent): 201 with the schedule. At most 10 per thread. If the thread is busy when one is due, it tries again a minute later. See Cron schedules.
PATCH /v1/threads/<id>/schedules/<scheduleId> Needs RUNS. Change any of name, prompt, at, everyMinutes, cron, timezone: the schedule as it now is, with nextAt worked out again for a change to when it runs. Audited as schedule_updated.
DELETE /v1/threads/<id>/schedules/<scheduleId> Remove a schedule.
POST /v1/threads/<id>/trigger Needs RUNS and FELIX_SIGNING_SECRET. No bearer token: the body { prompt } is signed instead, with felix-timestamp (Unix seconds) and felix-signature: sha256=<hex>, the HMAC-SHA256 of <timestamp>.<body>. Starts a run: 202. A signature works once across the deployment and for five minutes.
POST /v1/threads/<id>/steer Body { text } (1 to 32768 characters): 202 with { steer }, the steer’s id. The thread’s running run takes it as a user message at its next turn boundary, one steer per boundary, and its stream shows it as a message. 409 no_active_run when no run holds the thread; 429 steer_limit while 8 wait.
POST /v1/threads/<id>/ask Body { question }: { answer }, answered from the conversation without adding to it. Works while a run is going.
POST /v1/threads/<id>/fork Body { at, summarize? }: 201 with a new thread holding the first at messages. summarize: true appends a summary of the part left behind. A point that would split a tool call from its result is refused.

A summary is:

Field
id The thread id.
title New conversation until the first prompt, then its first 60 characters. A thread renamed before its first prompt keeps that name.
createdAt, updatedAt Epoch milliseconds.
revision The thread’s concurrency token: a counter every change advances (a message, a rewind, a compaction, a label or model change). It never repeats and is not a count.
messageCount How many messages the active branch holds.
status idle, running or interrupted.
mode plan or bypass; absent in the default mode.
asking true while the thread’s run waits on a person’s answer to a question (ask_user); absent otherwise.
owner Who created it (google:<id> or github:<id>), on a deployment with sign-in. Only they, or an admin, can reach it. Absent for threads the operator token created.
agent The agent its runs use, chosen when it was created or before its first run and kept after. Absent: the deployment’s default agent.
workspace codework or cowork, taken from its agent whenever the agent is set and kept after. Absent: a general conversation.
outputStyle The output style its runs write in, one its agent declares. Absent: the agent’s default.
ran true once a run has taken the thread, so its agent is kept even when a rewind left no messages.
workflow { workflowId, runId, step }: the workflow run step the thread belongs to. Lists and search leave such threads out unless include=workflow.
lastOutcome How its latest run ended: complete, limit (it reached its step limit), failed or stopped. Absent while it runs, before any, and after a run whose host went away.
lastFailedTool The first tool call in the latest run that errored, by tool name.
lastBlockedTool The first tool call in the latest run that was refused (a policy, an approval or the mode).

A full thread adds messages, whose length always equals messageCount. The list is ordered by id, not by activity, and is not a snapshot: threads created while you page may or may not appear.

Status code When
400 invalid_thread_request The id or cursor is not a valid thread id.
401 unauthorized The bearer token is missing or wrong.
404 thread_not_found No thread has that id.
405 Any other method. Plain text.
503 threads_not_configured, storage_unavailable, corrupt_thread_log, unsupported_format As for run requests.

A revision is a counter that every change to a thread advances: each message committed (one prompt can add several: the user message, then each assistant and tool message the run produces), and each rewind, compaction, label or model change. It never repeats for a thread.

A hosted run request carries the revision the client last saw. Before the stream starts, the server takes a writer lease on the thread at that revision. If the thread has moved on, the request gets 409 stale_revision; if another run holds the lease, 409 run_in_progress. Nothing is run in either case.

On a conflict, do not resend the prompt automatically. Read the thread again with GET /v1/threads/<id>, show it, and let the person decide what to send. The thread frame at the end of a run carries the new revision for the next request. Another client may move the thread on straight after, so a later read can be newer still.

A lease lasts fifteen minutes. While it is held the thread’s status is running. A run that ends with end: complete leaves it idle; a limit, a failure, a stop or (without RUNS) a disconnect leaves it interrupted. With RUNS, a disconnect leaves the run going: each event’s SSE id is a position, and GET /v1/threads/<id>/events?after=<position> picks up from there. A lease that runs out without being released also reads as interrupted, and the next request at the current revision can take the thread. The run that lost its lease can no longer write; its next write fails and the stream ends with run_failed.

When a run continues a thread whose last run was cut off mid tool call, each unanswered call is recorded as having an unknown outcome. Nothing is re-run.

A thread holds at most 1,000 entries and 1 MiB of messages in total across every branch, each message at most 128 KiB. A run that would go past that fails with run_failed.