HTTP API¶
Every route the gateway serves. All of them are on the one farm URL.
Conventions¶
- Auth. Routes marked key need an API key, sent as
Authorization: Bearer <key>, as the password of HTTP basic auth, asx-hearth-key: <key>, or as?token=<key>. The web UI'shearth_sessioncookie (fromPOST /api/auth/login) works on the same routes, but a cookie-authenticated request that is not aGET, or that opens a WebSocket, must come from the farm's own pages (Sec-Fetch-Site: same-originor a matchingOrigin), else403 cross_origin. Everything is scoped to the key's team; another team's objects answer404. - Errors. JSON routes answer
{"error": {"code": "...", "message": "..."}}with an HTTP status. WebDriver routes answer in W3C form:{"value": {"error", "message", "stacktrace"}}. Refusals that are worth retrying carryRetry-After. Codes are listed in Troubleshooting. - Bodies. Up to 64 MiB, except app uploads (2 GiB) and agent artifact uploads (no limit).
- Times are milliseconds since the Unix epoch.
Health and metrics¶
| Route | Auth | Answer |
|---|---|---|
GET /healthz |
none | 200 ok |
GET /readyz |
none | 200 ready, or 503 redis unreachable |
GET /metrics |
none | Prometheus text; see Operations |
Playwright and CDP¶
| Route | Auth | What |
|---|---|---|
GET /playwright/{engine} (WebSocket) |
key | A Playwright session. engine: chromium, firefox, webkit |
GET /cdp/{engine} (WebSocket) |
key | A CDP session; engine must be chromium |
Query parameters: token (the key), version (major.minor, overrides the User-Agent), pool
(a pool by name).
Headers read: User-Agent (client version), x-playwright-browser (must match engine),
x-playwright-launch-options (JSON launch options; see Playwright).
Every x-playwright-* header is passed on to the browser pod.
The gateway holds the upgrade while the request is queued. Refusals happen before the upgrade, as
plain HTTP answers: 400 not_websocket, 400 engine_mismatch, 401 bad_key | missing_key,
404 unknown_engine | no_cdp, 428 no_pool, 429 team_limit | pool_busy, 502 pod_unreachable.
WebDriver (Selenium and Appium)¶
Served under /wd/hub and at the root, as Selenium Grid 4 does:
| Route | Auth | What |
|---|---|---|
GET /wd/hub/status, GET /status |
none | {"value": {"ready": bool, "message": string}} |
POST /wd/hub/session, POST /session |
key | New session. The body is a W3C new-session request (capabilities.alwaysMatch merged with the first firstMatch, or legacy desiredCapabilities) |
* /wd/hub/session/{id}, * /session/{id} |
key | DELETE ends the session; other methods are forwarded |
* /wd/hub/session/{id}/{rest...}, * /session/{id}/{rest...} |
key | Any WebDriver or Appium command, forwarded to the session's browser or device. Paths with .., ., ?, #, \ or % answer 400 invalid argument; blocked device commands answer 403 unsupported operation |
The key is checked before the request body is read; a missing or unknown key answers a W3C
session not created error with status 401. The new-session answer is the driver's own, with value.sessionId replaced by the farm's session
id. Capabilities the gateway reads: browserName, platformName, appium:deviceName,
appium:platformVersion, appium:app, and hearth:options ({"pool": "<name>"}). See
Selenium and Mobile devices.
The JSON API¶
POST /api/auth/login¶
Signs a browser in. Body {"key": "hth_..."}. Answers {"team": "checkout"} and sets the
hearth_session cookie (HttpOnly, SameSite=Strict, 12 hours, Secure when
X-Forwarded-Proto: https). 401 bad_key for an unknown key.
POST /api/auth/logout¶
Ends the cookie session. 204.
GET /api/me (key)¶
maxSessions is 0 for no limit.
GET /api/pools (key)¶
Browser pools, then device pools:
[
{"name": "chromium", "kind": "browser", "engine": "chromium", "protocol": "playwright",
"playwrightVersion": "1.65", "maxSessions": 50, "ready": 2, "leased": 1, "queued": 0},
{"name": "selenium-chrome", "kind": "browser", "engine": "chromium", "protocol": "webdriver",
"maxSessions": 20, "ready": 1, "leased": 0, "queued": 0},
{"name": "pixel8", "kind": "device", "platform": "android", "protocol": "appium",
"deviceName": "Pixel 8", "osVersion": "15", "maxSessions": 10, "ready": 1, "leased": 0, "queued": 0}
]
leased is the number of browsers or devices serving a session.
GET /api/sessions (key)¶
The team's sessions, newest first. Query: limit (1 to 500, default 100), state (queued,
running, finishing, done, failed), name (exact session name; see
Name the session). name is left out when the client gave none.
[
{
"id": "0193c1d2e3f4...",
"team": "checkout",
"pool": "chromium",
"engine": "chromium",
"protocol": "playwright",
"state": "done",
"pod": "chromium-x7k2p",
"client": "Playwright/1.65.1 (arm64; macOS 27.0) node/22.12",
"name": "checkout applies a coupon",
"createdMs": 1796000000000,
"startedMs": 1796000000420,
"endedMs": 1796000031000,
"error": null,
"artifacts": ["video.mp4"],
"artifactPrefix": "checkout/2026-11-30/0193c1d2e3f4..."
}
]
engineholds the platform (android,ios) for device sessions;podholds the device id.protocolisplaywright,cdp,webdriverorappium.- Session records are kept for 7 days.
GET /api/sessions/{id} (key)¶
One session, as above. 404 not_found for an unknown id or another team's session.
DELETE /api/sessions/{id} (key)¶
Stops a running session. 202 when accepted; 409 not_running if it ended or has no browser
yet; 502 pod_unreachable | pod_error if its pod did not take the request. The session ends as
failed with the error stopped by a user.
GET /api/sessions/{id}/live (key)¶
The live screen as MJPEG (multipart/x-mixed-replace), ready for an <img>. With ?frame=1,
one JPEG. 409 not_running for a session that ended; 502 no_stream if the pod or agent did not
serve a stream.
GET /api/sessions/{id}/control (key, WebSocket)¶
Sends input to a running session. The server's first message describes the screen:
Then send one JSON message per input. Coordinates are fractions of the screen, from 0 to 1.
For browser sessions:
{"type": "mouse", "action": "move", "x": 0.5, "y": 0.25}
{"type": "mouse", "action": "down", "x": 0.5, "y": 0.25, "button": "left"}
{"type": "mouse", "action": "up", "x": 0.5, "y": 0.25, "button": "left"}
{"type": "mouse", "action": "wheel", "x": 0.5, "y": 0.5, "deltaY": 120}
{"type": "key", "action": "down", "key": "Enter"}
{"type": "key", "action": "up", "key": "Enter"}
{"type": "text", "text": "typed by a person"}
key is a DOM KeyboardEvent.key value.
For device sessions the hello has "kind": "device" and the device window size in points, and the
gateway turns each input into an Appium call on the running session:
{"type": "tap", "x": 0.5, "y": 0.5}
{"type": "swipe", "x1": 0.5, "y1": 0.8, "x2": 0.5, "y2": 0.2, "ms": 300}
{"type": "text", "text": "hello"}
{"type": "button", "name": "home"}
{"type": "key", "key": "Enter"}
{"type": "rotate", "to": "landscape"}
swipe.msis clamped to 50 to 3000 (default 300).button.name:homeandbackon Android,homeon iOS.key:Backspace,Tab,Enter,Escape, the arrow keys,Delete, or a single character.rotate.to:landscape, anything else means portrait.
GET /api/sessions/{id}/artifacts/{name} (key)¶
Streams one artifact, for example video.mp4 or device.log, with its content type,
X-Content-Type-Options: nosniff, and Content-Disposition: inline for videos and images or
attachment for everything else. 404 not_found if the session has no such artifact.
GET /api/apps (key)¶
The team's uploaded apps:
[{"sha256": "9f2c...", "name": "app-debug.apk", "size": 5242880, "uploadedMs": 1796000000000, "ref": "hearth:app:9f2c..."}]
POST /api/apps (key)¶
Uploads an app. The body is the raw file; the x-filename header is its name (.apk, .zip or
.app.zip; letters, digits, spaces, ., - and _). hearth app upload <file> does the same. Answers the app record as above. Errors: 400 bad_app_name, 400 empty,
413 too_large (over 2 GiB), 503 no_storage.
Agent routes¶
Used by hearth-agent; authenticated with Authorization: Bearer <agent token>. See
Device agents on hosts for the bodies.
| Route | What |
|---|---|
POST /internal/agent/heartbeat |
Reports the host's devices. {"ok": true} |
GET /internal/agent/apps/{sha256} |
Downloads an uploaded app |
PUT /internal/agent/sessions/{session}/artifacts/{name} |
Uploads a session artifact (up to 8 GiB). 201 |
Heartbeat refusals: 403 wrong_host, 403 wrong_device, 403 unknown_pool,
400 bad_agent_url.
Browser pod routes¶
Used by hearth-node inside browser pods; authenticated with Authorization: Bearer <pod token>
(the HEARTH_POD_TOKEN the operator gave the pod). Each call is limited to that pod and the one
session it was given; another session id answers 404.
| Route | What |
|---|---|
POST /internal/node/register |
{"addr": "host:port", "token": "<secret for the gateway, 32+ chars>"}. 204; 409 used if the pod already served a session, 409 busy if it is not idle, 400 bad_registration |
POST /internal/node/heartbeat |
{"known": bool, "state": "ready" \| "leased" \| ..., "session": id \| null} |
POST /internal/node/retire |
An idle pod is shutting down. 204 |
POST /internal/node/sessions/{id}/running |
The session started. 204 |
PUT /internal/node/sessions/{id}/artifacts/{name} |
Uploads an artifact (up to 8 GiB). 201 |
POST /internal/node/sessions/{id}/finish |
{"error": string \| null}: records the outcome and frees the team slot. 204 |
The web UI¶
Any other GET serves the web UI: a file from the UI build, or index.html for app routes such as
/sessions/<id>, /pools, /apps and /connect.
Not built yet¶
GET /api/queue (queue position and ETA) and signed artifact URLs are described in the design but
not implemented.