API
Use this page to inspect the WebSocket methods, events, and errors exposed by the engine.
The engine is driven through one API. The afe command line and the web UI are its clients.
The protocol
The API is JSON-RPC 2.0 over a WebSocket at /rpc. The
handshake must carry Authorization: Bearer <token>, or a valid session cookie from the server's
own Origin. The token is the bootstrap token, a service account token or an OpenID Connect access
token. See Identity and audit.
| Method | Params | Result |
|---|---|---|
caller.get | — | {caller, everything, roles, capabilities}: the caller, whether it reaches everything, its roles per project and what it may reach |
flow.list | — | flows with their input Schema, the workspace they need, their projects, the current revision and can_start |
flow.bpmn | flow, revision? | {xml, nodes}: the flow as BPMN 2.0 XML, with no layout, and each clickable element's domain kind (agent, human, script, lane, map, start, end, when, choose, join, pause) |
ticket.start | flow, input, project?, revision?, traceparent? | {ticket_id} as soon as it is accepted |
ticket.rerun | ticket_id | {ticket_id} of a new ticket on the same flow, input, project and revision |
revision.get | revision_id | {id, manifests, manifest_count, current}: the frozen configuration |
ticket.start_form | flow, rerun_of? | {flow, revision, input_schema, initial, projects, project_required}: the form that starts a flow, at a ticket's revision on a rerun |
meta.get | — | {states, open_states, waiting_states, sort_columns, search_max, audit_actions, audit_outcomes}: the engine's own catalogues |
ticket.resume | ticket_id, answer? (action, comment?) | {ticket_id} |
ticket.pause, ticket.cancel | ticket_id | null |
ticket.clean | ticket_id | a note naming the repository whose branches stayed, or null: the worktrees, branches, sandbox and bundles of a finished ticket go, repeatable |
ticket.get | ticket_id | state, round, revision, artifacts, totals, pending question, last error, last and highlighted node, actions |
ticket.list | state?, flow?, search?, sort?, descending?, pending_request?, cursor?, limit? | {items, next}: a page of tickets, newest first, with their totals, actions, and the pending question of the waiting ones |
ticket.counts | none | {states: {state: count}, total, pending_requests}: the tickets the caller sees per state, their total, and how many wait on a person |
ticket.events | ticket_id, cursor?, limit?, node?, descending? | {items, next}: a page of the ticket's events, in order, or newest first |
events.subscribe | ticket_id?, after? | {subscription}, then events.event notifications |
events.unsubscribe | subscription | true or false |
workers.status | — | queue metrics (waiting, claimed) and the live workers, each with its tickets and active_tickets |
audit.list | since?, until?, actor?, action?, object_id?, project?, outcome?, before?, limit? | a page of the audit trail, newest first (global administrators, or project administrators for their projects) |
service_account.create | name, expires_at? | {account, token}, the token shown once (administrators only) |
service_account.list | — | the service accounts, with no tokens (administrators only) |
service_account.revoke | name | null (administrators only) |
caller.get returns {caller, everything, roles, capabilities}. roles maps each project to the roles
the caller holds there, and everything is true for a global administrator and for local. It is a
read and leaves no entry.
capabilities says what the caller may reach, so a client hides a page without working it out.
workers: the caller reads the workers and the queue.revisions: the caller reads a configuration revision.audit: the caller reads some part of the audit trail.audit_projects: the projects whose trail it reads, sorted.sees_projects: the caller sees at least one project, or every ticket because it has every right.
actions on a ticket lists what the caller may do now, from pause, cancel, resume, answer and
rerun. It depends on the caller's role in the ticket's project and on the ticket's state. A client
shows a button only when its action is there. The role matrix is in the
Project reference.
flow.list lists every flow, and each flow's projects holds only the projects where the caller may
start it. A ticket of a project the caller cannot see answers -32001, as an unknown ticket does.
can_start is true when ticket.start would accept the flow for this caller now. It follows the same
checks: the role, the flow limits of the grant, and the project's folder or repository.
A grant limited to some flows counts only for those, in every list, read and command.
ticket.list and ticket.events return one page. limit is 1 to 1,000 and defaults to 100. Any
other value answers -32002. next is an opaque cursor: pass it as cursor to read the next page,
and it is null on the last. Events come ordered by seq. A client that needs
everything reads pages until next is null.
ticket.list filters and sorts on the server:
statekeeps one state,flowkeeps one flow.searchkeeps the tickets whose id, uid or project contains the text, ignoring case. It is at most 100 characters.sortis one ofid,flow,state,round,revision,projectandcost. The default isid, and ids order numerically (T-0010afterT-0009). Ties break by id.descendingis optional: left out, the server picks the order, newest first except on the Approvals list. When sent, it wins either way.pending_requestkeeps only the tickets with an unanswered request, filtered before the page: the Approvals list, whereidascending puts the longest wait first.- A
cursorcarries itssortanddescending. Reused with anothersortordescending, it answersINVALID_INPUT(-32002). It does not carry the filters: send the samestate,flowandsearchwith it, since the server does not check them.
ticket.events takes node, which keeps one node's events, and descending, which returns the
newest first with the cursor walking the earlier events.
ticket.counts takes no parameters and counts every ticket the caller sees, whatever page a client
has loaded. A state with no ticket is absent from states. total counts them all and
pending_requests counts the tickets with an unanswered request, the Approvals badge.
ticket.clean takes a finished ticket. It removes the worktrees, branches, sandbox and stored bundles,
and writes a ticket.clean audit entry. An open ticket answers INVALID_INPUT (-32002). A second
call finds nothing and succeeds. The result is null, or a branches kept: <repository> note when
the repository is not a clone the engine made. See afe clean.
ticket.start_form returns what a form needs: the input Schema, the initial values (the original input on a
rerun), the projects the caller may pass and project_required. Pass rerun_of to read the Schema at that ticket's revision.
meta.get returns the engine's own catalogues, so a client does not copy them. They are the ticket
states, the open and waiting ones, the sortable columns, the search limit, and the audit actions and
outcomes.
The pending question of a ticket, in ticket.get and ticket.list, carries kind, node, question,
actions and require_comment. For a budget, loop or hand-over question it also carries a message
code and its raw params, so a client translates it. question stays the English line. A flow's own
question has code: null and empty params.
budget.ticket,budget.branch,budget.activation:dimension,threshold,used,limit,nodeandbranch.loop.repeated:nodeandrepeats.handover.<cause>:node, pluscommentforrejected,reasonforgave_upanddetailfor every other cause.handover.error:nodeanddetail.
The hand-over causes are rejected, taken_over, gave_up, budget_exceeded, loop_handover,
artifact_invalid, harness_failed, feedback_exhausted, stalled, write_conflict and
merge_not_approved. Any other cause answers handover.error.
revision.get adds manifest_count, the number of manifests, and current, true when the revision is
the one the engine runs now.
ticket.get carries cleanup: "pending" when a cancelled ticket's sandbox removal has failed and
is being retried, and nothing otherwise. last_node is the node of the newest event that has one.
highlight_node is the pending request's node, else last_node, else null. totals carries
total_tokens and fresh_tokens beside the billed counts.
Tickets run in the background. Their progress arrives as events.event notifications on the same
connection. A late subscriber first gets the ticket's past events, then the live ones, with no
duplicates.
events.subscribe takes after, the last seq the client saw, and replays only what follows it.
A connection holds at most 32 subscriptions, and one caller at most 256 across all its
connections. A request past either answers -32009 and starts no stream. Unsubscribing, closing
the connection or a stream that ends frees the slot. A subscriber that cannot keep up (its queue of
1,000 events is full) is stopped, not skipped: the server closes the socket with code 4008. The
CLI and the web UI reconnect and pass their last seq as after, so no event is lost.
Event kinds
| Kind | Meaning |
|---|---|
ticket_started | The ticket was accepted and the engine started it. |
ticket_resumed | A person answered, or the ticket was restarted. |
ticket_recovered | A worker took over a ticket whose worker died. |
ticket_cancelled | The ticket was cancelled. |
ticket_done | The flow reached END. |
node_started | A node began an activation. |
node_finished | A node finished an activation. |
budget_alert | A budget crossed an alert fraction or a limit; waits for a person. |
loop_detected | The same tool call repeated; waits for a person. |
human_request | A human node asks a person. |
human_response | A person answered a human node. |
cleanup_failed | Removing a cancelled ticket's sandbox failed, and it is retried. The payload carries error_class and error. |
cleanup_done | A cancelled ticket's sandbox and bundles were removed. |
needs_human | A hand-over; the ticket stops for a person. |
error | The ticket failed; the payload carries state and error. |
Errors
| Error code | Meaning |
|---|---|
-32602 | Invalid params |
-32001 | Unknown flow or ticket, or a ticket of a project the caller cannot see |
-32002 | Invalid input; data.fields names the field that is wrong |
-32003 | Action not offered |
-32004 | The ticket is running, or closed |
-32005 | Unknown revision |
-32006 | The ticket has no revision (created before revisions existed) |
-32007 | The ticket was started by an earlier engine version (finish it there, or rerun it) |
-32008 | The caller is not allowed to do this |
-32009 | The caller holds too many event subscriptions (32 per connection, 256 per caller) |
See also
- CLI for commands that call the API.
- Ticket states for ticket lifecycle values.
- Operations for health and metrics endpoints.