HTTP API
The daemon has one HTTP port on 127.0.0.1. The command line, the terminal client, and the window client use the API with the token. The web page uses it with a session.
Authentication
Each route under /api/ needs one of these:
- The header
Authorization: Bearer TOKEN, with the token of the filetokenof the state folder. A request with the token and anOriginheader is refused: the token is not for a page. - The session cookie of a passkey sign-in. Each POST also needs the header
Originof the daemon and the headerX-CSRFwith the CSRF token of the session.
Each request needs the header Host: localhost:PORT or Host: 127.0.0.1:PORT, else the status is 421.
curl -s -H "Authorization: Bearer $(cat ~/.local/state/jcode/token)" http://localhost:7717/api/agents/a1/cost
{"id":"a1","model":"us.amazon.ergo-1.0","priced":true,"rows":[{"kind":"in","tokens":3429,"usd":0.0038},{"kind":"out","tokens":266,"usd":0.0009},{"kind":"cache_read","tokens":0,"usd":0.0000},{"kind":"cache_write","tokens":1035,"usd":0.0014}],"usd":0.0061,"calls":5,"wall_ms":9679,"model_ms":9550,"tool_ms":35,"idle_ms":1}
Routes
| Route | What it does |
|---|---|
GET /api/agents |
{"agents":[AGENT,…]}. |
POST /api/agents |
Starts an agent. The body: model, dir, brief (the text), and the optional level, net, run, max_turns, max_tokens, max_out, idle_timeout, exec_timeout, mem, write (a list), env and checks (objects), and base. Gives {"id":…}. |
GET /api/agents/ID |
AGENT. |
GET /api/agents/ID/read?since=N&wait=S |
{"state":…,"last":N,"entries":[…]}: the entries after N. With wait, the reply waits up to S seconds (30 at most) for a new entry. |
GET /api/agents/ID/wait?timeout=S |
{"timeout":BOOL,"agent":AGENT} when the state is not running, or after S seconds (60 at most). |
POST /api/agents/ID/send |
{"text":…}. Gives AGENT. |
POST /api/agents/ID/interrupt |
Kills the running command. Gives AGENT, or 409 with no command. |
POST /api/agents/ID/stop |
Stops the agent. Gives AGENT. |
GET /api/agents/ID/cost |
The tokens and the USD of each kind, the count of calls, and the times in ms. |
AGENT is the object of meta.json: id, model, dir, level, net, run, state, reason, question, report, turns, max_turns, tokens, max_tokens, max_out, in, out, cache_read, cache_write, created, updated, and the limits of the start.
An error is {"error":TEXT} with the status 400, 401, 403, 404, 405, or 409 (Errors).
Sign-in routes
The web page uses these routes. Each is a POST with the Origin of the daemon. A route of a signed-in page also needs the CSRF token.
| Route | What it does |
|---|---|
GET /auth/state |
{"registered","signedIn","missing","name"}, and csrf for a session. |
POST /auth/register/begin |
{"code"}: the one-time code, or a session. Gives the options of navigator.credentials.create. |
POST /auth/register/finish |
The attestation. Adds the passkey. |
POST /auth/login/begin |
Gives the options of navigator.credentials.get. |
POST /auth/login/finish |
The assertion. Sets the session cookie, and gives csrf. |
POST /auth/logout |
Ends the session. |
Limits of the server
- At most 64 open connections. The server closes each one past the cap with no reply.
- The head of a request: 16 KiB. The body: 1 MiB. The time of a request: 30 s, except a long poll.
- Each connection carries one request.