AGENT API

One endpoint in, everything out. Clean REST paths, live SSE, rich JSON conversations. No key, no signup, no branding — drop into public_html and wire your bot. Don't understand something? Read SETUP.md — it's the manual.

▸ THE endpoint

SSE POST /api/chat

Send a task. Receive the agent working live: plan, tool calls, thinking, text, auto-approvals, media generation, files — finished with one done event containing the full conversation as JSON. Key rotation, credit management and pool refills are all internal; a request never waits on anything.

body fieldtypenotes
messagestringrequired — the task (max 6000 chars)
session_idstringcontinue a conversation
searchboolweb-ground the task
tierstringfast (default)
budget_secintmax stream seconds (default 170, cap 280)
curl -N -X POST "https://YOUR-HOST/api/chat" \
  -H "Content-Type: application/json" \
  -d '{"message":"generate an image of a fox in a snowy forest"}'
event: open      data: {"engine":"agent","tier":"fast","search":false}
event: key       data: {"credits":100}
event: run       data: {"session_id":"sess-…","status":"running"}
event: thinking  data: {"delta":"…"}
event: tool      data: {"id":"call_…","name":"google_search","state":"running"}
event: tool      data: {"id":"call_…","state":"success"}
event: hitl      data: {"auto":true,"question":"…","choices":{…}}     (answered with the agent's own defaults)
event: media     data: {"media_task_id":"…","media_type":"image","status":"PENDING"}
event: media     data: {"media_task_id":"…","status":"SUCCEEDED","urls":["https://….png"]}
event: file      data: {"filename":"…","downloadUrl":"https://…"}
event: text      data: {"delta":"…"}
event: usage     data: {"input_tokens":…,"output_tokens":…}
event: credits   data: {"left":86}
event: rotate    data: {"attempt":1,"reason":"key ran dry — rotating"}   (rare; task replays silently)
event: done      data: {"ok":true,"conversation":{
                  "id":"sess-…","message":"…","reply":"…",
                  "tools":[…],"files":[…],"media":[…],"usage":{…},
                  "approvals":2,"credits_left":86,"error":null } }

No model pickers, no preset configs — the agent chooses its own tools and settings; any question it raises mid-task is approved with its own defaults.

▸ Wire your own bot

callpurpose
GET /api/sessionsmerged task history across the pool (newest first)
GET /api/sessions/{id}full message list of one conversation
GET /api/sessions/{id}/statuslive state: IDLE / QUEUED / RUNNING
POST /api/sessions/{id}/stopabort a running task (verified: RUNNING → IDLE)
DELETE /api/sessions/{id}delete a conversation
GET /api/media/{taskId}raw media-task record + URLs
GET /api/creditspool snapshot: keys, buffered credits, keeper state
GET /api/info · /api/modelsbanner + capabilities
# stop a runaway task from your bot
curl -X POST "https://YOUR-HOST/api/sessions/sess-…/stop"

# poll while your user waits
curl "https://YOUR-HOST/api/sessions/sess-…/status"

▸ How the pool never runs dry

Two workers, zero waiting. Your request instantly grabs a funded key from the buffer — it never farms, never waits on claims. The second worker (the keeper) runs in the background: it watches request stats (demand per hour) and grows the buffer ahead of usage (6 keys calm → up to 24 under load).

Where the credits come from — every verified source, all automated:
  1. fresh anonymous keys claim +100 on arrival (fast path, seconds per key)
  2. claims are minted in parallel batches, and rotate through fresh network exits when a region's pot is dry
  3. a captcha-proof mailbox path backfills when the fast path is throttled
  4. existing keys re-claim daily on their own
  5. a key that hits the wall mid-task is rotated out and the task replays silently

• Deploy: upload everything into public_html (Apache rewrite included). Local dev: PHP_CLI_SERVER_WORKERS=8 php -S 0.0.0.0:8080 router.php.

• Errors: JSON {"ok":false,"error":"…"} with proper HTTP codes; stream failures arrive as event: error.

• Stored server-side: anonymous key state and a session map only. Nothing about you, nothing identifiable.