Skip to content

Build your own UI

The widget is built on the same API you can call yourself. With an end-user token, send it as Authorization: Bearer <token>. From a backend you can also call these endpoints with the app’s X-API-Key; the conversations then belong to the app itself rather than to one user.

POST /api/agent-runs starts a run: the agent answering one message.

Field
agentId The agent to talk to.
input The user’s message.
sessionId Continue a conversation. Leave it out to start a new one.

It returns the run right away, with its id and sessionId. Keep the sessionId for the next message.

GET /api/agent-runs/:id/events is a Server-Sent Events stream until the run ends:

Event Data
text_delta { text }: the next piece of the answer as it’s written.
message A complete message: the assistant’s reply, a plugin call or a plugin result. Its SSE id is the message id.
run_finished The run, with its final status: completed, failed, cancelled or max_turns.

If the connection drops, reconnect with the Last-Event-ID header set to the last message id you got; the stream resumes after it.

Terminal window
curl -X POST https://snipet.example.com/api/agent-runs \
-H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
-d '{ "agentId": "<agent id>", "input": "Where is my order?" }'
# { "id": "<run id>", "sessionId": "<session id>", "status": "running", ... }
curl -N https://snipet.example.com/api/agent-runs/<run id>/events \
-H "Authorization: Bearer $TOKEN"
Endpoint
GET /api/agent-sessions The user’s conversations. Filter by agentId.
GET /api/agent-sessions/:id/messages A conversation’s messages, newest first. Page back with before=<message id>.
DELETE /api/agent-sessions/:id Deletes a conversation.
POST /api/agent-runs/:id/cancel Stops a run that’s still going.

A conversation runs one message at a time: starting a run while another is still going in the same session fails with 409.