Skip to content

HTTP API Reference

Starting the server

bash
ra --http                        # default port 3000
ra --http --http-port 8080       # custom port
ra --http --http-token secret    # with authentication

Authentication

When a token is configured, all requests require a Bearer token header:

Authorization: Bearer <token>

Requests without a valid token receive 401 Unauthorized.

POST /chat

Stream a response via Server-Sent Events (SSE).

Request:

json
{
  "messages": [
    { "role": "user", "content": "Hello" }
  ],
  "sessionId": "optional-session-id"
}
FieldTypeRequiredDescription
messagesarrayYesArray of message objects with role and content
sessionIdstringNoResume a previous session. Omit to start new

Response (SSE stream):

data: {"type":"text","delta":"Hello"}
data: {"type":"text","delta":"!"}
data: {"type":"done","usage":{"inputTokens":150,"outputTokens":42}}

SSE event types:

TypeFieldsDescription
textdeltaText content token
thinkingdeltaThinking/reasoning token
tool_call_startid, nameTool invocation begins
tool_call_deltaid, argsDeltaTool argument streaming
tool_call_endidTool invocation complete
AskUserQuestionquestion, sessionIdAgent needs user input — loop suspended
doneusage (optional)Stream complete

When AskUserQuestion is emitted, the agent loop is suspended. Send a new /chat request with the same sessionId to continue the conversation.

POST /chat/sync

Same request body as /chat. Returns the full response as JSON after the agent loop completes.

Response:

json
{
  "response": "Hello!",
  "sessionId": "ses_abc123"
}
FieldTypeDescription
responsestringThe agent's complete text response
sessionIdstringSession ID for resuming later

GET /sessions

List stored sessions.

Response:

json
{
  "sessions": [
    {
      "id": "ses_abc123",
      "createdAt": "2026-01-01T00:00:00Z",
      "messageCount": 12
    }
  ]
}

Examples

Streaming with curl:

bash
curl -N http://localhost:3000/chat \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer secret" \
  -d '{"messages": [{"role": "user", "content": "Hello"}]}'

Synchronous with curl:

bash
curl http://localhost:3000/chat/sync \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer secret" \
  -d '{"messages": [{"role": "user", "content": "Hello"}]}'

Resuming a session:

bash
curl http://localhost:3000/chat/sync \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Continue"}], "sessionId": "ses_abc123"}'

See also

Released under the MIT License.