API reference
The HeyBug API is JSON over HTTP under `/api`.
The HeyBug API is JSON over HTTP under /api. Bodies and fields are camelCase, lists are never null, and ids are prefixed strings (prj_…, exp_…, run_…, art_…).
Authentication
| Method | How | Use it for |
|---|---|---|
| Session cookie | ot_session, set by POST /api/auth/verify or /api/auth/dev-login | The web app |
| API key | Authorization: Bearer ot_… | CLI, CI, MCP, scripts |
Create a key at POST /api/tokens. The secret is shown once. The CLI reads HEYBUG_TOKEN and HEYBUG_SERVER.
curl -H "Authorization: Bearer $HEYBUG_TOKEN" $HEYBUG_SERVER/api/projectsPublic routes (no session or key) are more than the kernel's seven (GET /api/healthz, GET /api/version, GET /api/auth/config, POST /api/auth/magic-link, POST /api/auth/verify, POST /api/auth/dev-login, POST /api/auth/sign-out). Modules add about forty more under /api:
- sign-in: password, passkey login, OAuth and SSO start and callback, 2FA status and verify, device-code flow;
- invitations: look up and accept;
- signed links: shares, report assets, fixture downloads, the OTP inbox;
- the changelog admin route, which checks its own guard in the handler.
Root routes (/webhooks/*, /scim/v2/*, /t/{id}/*) check their own signatures or tokens. Everything else needs a session or key.
API keys never reach passkey, 2FA-setting or account-export routes, and act only on their own workspace. A session that has passed only the first factor gets two_factor_required until POST /api/auth/2fa/verify. Sign-in answers carry twoFactorRequired and a redirect to the code screen.
Errors
Every failure is {"error":{"code","message","field?"}}.
| Status | code |
|---|---|
| 401 | unauthorized |
| 403 | forbidden |
| 404 | not_found |
| 409 | conflict |
| 422 | invalid (field names the bad input) |
| 429 | rate_limited |
| 503 | unavailable (also "Email is not configured" when no mail provider is set) |
| 500 | internal |
Other codes you may see: two_factor_required (401), token_expired (401), insufficient_scope (403), sso_required (403), feature_gated (403), insufficient_credits (402), link_expired (403), not_implemented (501).
Account and keys
| Endpoint | Request | Response |
|---|---|---|
GET /api/me | MeResponse: user, workspace, role, llm, limits | |
GET /api/tokens | {tokens} | |
POST /api/tokens | {name} | {token, secret}: follows the workspace token policy (cap and maximum lifetime) |
DELETE /api/tokens/{tokenId} | revokes the key: its owner, or an owner or admin |
Projects
| Endpoint | Request | Response |
|---|---|---|
GET /api/projects | {projects}; each has lastRun, caseCount | |
POST /api/projects | {baseUrl, name?, description?} | the project |
GET /api/projects/{projectId} | {project, currentPlan?, latestExploration?, recentRuns, hasCredentials} | |
PATCH /api/projects/{projectId} | {name?, baseUrl?, description?} | the project |
DELETE /api/projects/{projectId} | archives it | |
GET /api/projects/{projectId}/credentials | {username, hasPassword, loginUrl, notes, updatedAt?} | |
PUT /api/projects/{projectId}/credentials | {username, password?, loginUrl, notes} (omit password to keep it) | same as GET |
DELETE /api/projects/{projectId}/credentials | removes them |
Explorations
| Endpoint | Request | Response |
|---|---|---|
POST /api/projects/{projectId}/explorations | {url?, instructions?} | the exploration |
GET /api/projects/{projectId}/explorations | {explorations} | |
GET /api/explorations/{explorationId} | {exploration, pages, steps, lastSeq} | |
POST /api/explorations/{explorationId}/cancel | the exploration | |
GET /api/explorations/{explorationId}/events | ?after= | SSE |
Plans
| Endpoint | Request | Response |
|---|---|---|
GET /api/projects/{projectId}/plan | the current plan | |
POST /api/projects/{projectId}/plan | {baseVersion, cases, run, runCaseKeys?} | {plan, run?} |
GET /api/projects/{projectId}/plans | {versions}: id, version, source, caseCount, useCaseCount, createdAt | |
GET /api/plans/{planId} | the plan |
A case is {key?, useCase, title, priority, goal, steps}. Leave key empty for a new case. Each apply saves a new version. run: true also starts a run.
Runs and results
| Endpoint | Request | Response |
|---|---|---|
POST /api/projects/{projectId}/runs | {planId?, caseKeys?, targetUrl?} | 202, the run |
GET /api/projects/{projectId}/runs | {runs, nextCursor?} | |
GET /api/runs/{runId} | {run, project, cases, lastSeq} | |
POST /api/runs/{runId}/cancel | the run | |
GET /api/runs/{runId}/events | ?after= | SSE |
GET /api/case-results/{caseResultId} | {result, run, steps, case?, script?}; script is Playwright code | |
GET /api/artifacts/{artifactId} | the file bytes (screenshots, video, traces) | |
POST /api/quick-runs | {url, projectId?, instructions?} | {id, status, project, exploration?, run?, cases?, url} |
GET /api/quick-runs/{quickRunId} | same shape; status is exploring, running, done or failed |
Events (SSE)
Both event routes stream text/event-stream. Frames look like id: <seq>, event: <type>, data: <json>. A : ping comment arrives every 15 s.
- Resume: pass
?after=<seq>, or let the browser sendLast-Event-ID(it wins). UselastSeqfrom the detail response as the starting value. A negative or non-numeric value returns 422. - Close: the server ends the stream after the terminal status (run
passed,failed,errororcanceled; exploration finished or canceled).
curl -N -H "Authorization: Bearer $HEYBUG_TOKEN" "$HEYBUG_SERVER/api/runs/$RUN/events?after=0"Chat
The project assistant (see the Chat guide). All routes are
under /api, authenticated like the rest of the API; sessions are private to
your user, and sending or resolving a card needs edit access to the project.
| Route | What it does |
|---|---|
POST /projects/{id}/chat/sessions | Start a session: {title?} → the session object. |
GET /projects/{id}/chat/sessions | Your sessions in the project, newest first, each with its status. |
GET /chat/sessions/{sid} | One session: status, pendingCard, activeTurn, usage (session tokens, workspace daily budget). |
PATCH /chat/sessions/{sid} | Set the session's model: {modelProviderId: "…"|null} (paid models gated by plan) or rename it. |
GET /chat/sessions/{sid}/messages | The stored messages. |
POST /chat/sessions/{sid}/messages | Send text (1..8000 chars; secrets are refused). Returns 202 {turnId} at once — the turn runs in the background and streams as events. 409 {code:"card_pending"} while a card waits. |
GET /chat/sessions/{sid}/stream | SSE of the session's events; resume with ?after=<seq> or Last-Event-ID. |
GET /chat/sessions/{sid}/events?after= | The same events as JSON, for polling clients. |
POST /chat/cards/{cardId}/resolve | Answer a card: {action, input?}. Actions: confirm, decline, apply, apply_and_run, reject, answer. Exactly-once per card; a repeat with the same action replays the stored result, with a different action it is 409 {code:"already_resolved"}. Starts the continuation turn. |
Chat events (kind): token, step_start, step_end, tool_call,
tool_result (with an optional link — "View browser"), card,
card_resolved, message, done (status of done, waiting_card,
paused or failed) and error. The turn survives closing the tab: reopen
the session and the stream resumes from your last seq.
MCP
POST /api/mcp is a remote MCP server (JSON-RPC 2.0, Streamable HTTP, JSON responses). Send Authorization: Bearer ot_…. GET and DELETE return 405. GET /api/mcp/tools lists the tools without auth. Setup steps are in MCP. The stdio server is heybug mcp.