The REST API
The same server over HTTP, so any language can drive it. Twenty-one routes, one per operation, plus the job routes that let you follow a long crawl without holding a connection open for it.
Everything here runs on your machine. The API calls nothing external, binds loopback by default and carries a key it generated itself.
svipall serve --port 8788curl -sH "Authorization: Bearer $KEY" -H 'content-type: application/json' \ -d '{"url":"https://example.com","query":"pricing"}' localhost:8788/v1/fetchsvipall-mcp mounts the same router when rest_port is set, on its own listener. It shares one
browser pool, one page cache and one set of learned tiers with the MCP tools. Two ways in, one
server behind them.
What a status code means
Section titled “What a status code means”A page that came back blocked is a 200. The call ran; the page did not.
REST inherits the CLI’s contract verbatim. In the CLI’s own words: “the exit code … never depends
on what a site said: a page that was blocked is a successful report of a block”. A client that read
a wall as a 5xx would sit in a retry loop against something that is never going to move.
| Status | Means |
|---|---|
| 200 | the call ran, including every unhappy page: blocked_reason, quality: "thin", count: 0 |
| 202 | an asynchronous job was queued; Location names it |
| 400 | the body is not this endpoint’s shape, or names a parameter the operation does not have |
| 401 | missing or wrong bearer key |
| 403 | the request carried a browser Origin, or a Host that is not loopback on a loopback bind |
| 404 | unknown path, or a job id that does not exist |
| 413 | body over 2 MB |
| 500 | this installation could not carry the request out: no page cache, no browser, an unknown country code. Something the operator can fix — never a wall |
Unknown body fields are ignored, which is what MCP clients already get. A typo’d field is therefore silent. That is deliberate: it is the price of one behaviour across both protocols.
The key, and why loopback is not a boundary
Section titled “The key, and why loopback is not a boundary”Every route needs Authorization: Bearer <key>, including on loopback. Svipall carries logged-in
browser profiles, cookies and your exit address, so an unauthenticated port is a proxy wearing your
identity, reachable by every process on the machine.
The key is resolved in this order:
SVIPALL_API_KEY: beats everything, and needs no writable home. The container and CI path.api_keyin~/.svipall/config.toml, if you pinned one.~/.svipall/api_key, written by an earlier run.- Otherwise one is generated, written to
~/.svipall/api_keyat0600where the platform allows, and printed once on the run that made it.
It lives in its own file beside config.toml because Config is not serialised: writing a
generated key back would mean rewriting a file you edit by hand, comments and all. secrets.env,
pools.json and domain_tiers.json are already the same pattern.
Two checks run before the key, and they are what makes a loopback bind mean something. A page
you have open at evil.test can be served a DNS answer of 127.0.0.1. Its script then posts to
http://evil.test:8788/v1/route and the browser delivers it to loopback. Binding to 127.0.0.1
does not help, because the request originates on your box. The key is the real defence, since a page
cannot read it, but a POST with a text/plain body is preflight-exempt and is therefore sent
regardless, which is enough for an endpoint with side effects. So:
- any request carrying an
Originheader is 403. No browser page is a legitimate client of this API. There is no CORS layer and there will not be one. - on a loopback bind, a
Hostthat is notlocalhost/127.0.0.1/[::1]is 403. The attacker’s page has to sendHost: evil.test, and that is the tell.
On a non-loopback rest_bind the Host check is skipped (your LAN address is a legitimate host)
and a warning is printed at startup saying the key is now the only thing between the network and
this machine’s profiles.
Routes
Section titled “Routes”The MCP server lists twelve tools since 2.0, and several of them have modes. The routes did not follow: each one is still a single operation and takes the body that operation took in 1.x.
| Route | Body |
|---|---|
POST /v1/fetch | web_fetch’s params |
POST /v1/fetch_many | several URLs in parallel (over MCP, web_fetch with urls) |
POST /v1/probe | whether each URL exists (over MCP, web_fetch with urls and probe=true) |
POST /v1/video | web_video’s |
POST /v1/crawl | web_crawl’s, plus "async": true |
POST /v1/search · /v1/site_search · /v1/map | finding things |
POST /v1/snapshot · /v1/act · /v1/capture · /v1/screenshot | a real browser |
POST /v1/solve_and_continue | the captcha, answered on the blocked page |
POST /v1/diff · /v1/watch · /v1/notes · /v1/log | memory |
POST /v1/route · /v1/profile · /v1/browser_setup | configuration |
GET / POST /v1/status | GET is read-only by construction: WebStatusParams carries four clearing fields, and a GET takes only ?sections= and cannot reach them |
GET /v1/health | the one route with no key, so a container healthcheck does not need one |
Every POST a tool route answers goes into the journal, with the request’s User-Agent as the
client; /v1/log with {"view": "calls"} reads it back, and {"view": "calls", "id": N} returns
one call with its content.
/v1/screenshot returns the JSON web_view with image=true returns (including path, since the PNG is
written to disk either way) plus image_base64 when the picture is small enough to be worth
carrying. That threshold is decided once, in the seam, so MCP and REST cannot disagree about it.
Not routes, and why
Section titled “Not routes, and why”rest::NOT_IN_REST records the reason beside each operation, and a conformance test fails the
build if a new one is neither a route nor listed there. Sessions, login and token solving have no
route. They are named below by their 2.0 MCP call.
browserwithopen=true,session_idorclose=true: a session is a resource HTTP cannot bound. It would work: the browser pool is shared, so a session opened by one request is visible to the next. That is the problem. A client that dies betweenopenandcloseleaks a real browser process with no TTL and no cap./v1/act(over MCP,browserwithurlandactions) covers the single-shot case, which is what a REST caller almost always wants.web_setupwithdo=login: opens a visible window on your desktop and waits up to an hour for a person. An HTTP request must not be able to do that.captchawithkind,imageortask_id: the token family already answers ondashboard_portin the 2captcha wire shape. Two contracts for one queue, with two auth schemes and two error conventions, is how a caller ends up unsure which one it is talking to.
Long crawls
Section titled “Long crawls”A crawl of two hundred pages is minutes. Synchronous is still the default (it is what MCP does and
what a script expects), but "async": true hands back an id instead.
curl -sH "Authorization: Bearer $KEY" -H 'content-type: application/json' \ -d '{"url":"https://docs.example/","max_pages":200,"async":true}' localhost:8788/v1/crawl# {"job_id":"9f2c…","kind":"crawl","state":"queued","stream":"/v1/jobs/9f2c…/stream"}| Route | |
|---|---|
GET /v1/jobs?state=&limit= | a listing. Never carries result — ten finished 200-page crawls would be tens of megabytes of pages nobody asked for twice |
GET /v1/jobs/{id} | the row, plus result once it is terminal. While it runs, pages_done is the honest partial answer; you are never handed a fabricated result |
GET /v1/jobs/{id}/stream | the same job as Server-Sent Events |
DELETE /v1/jobs/{id} | ask it to stop |
The id is the crawl id
Section titled “The id is the crawl id”For a crawl, job_id is crawl_id. There is one handle to learn, one id in every log line, and
resuming is the vocabulary the MCP tool and the CLI already use:
curl -sH "Authorization: Bearer $KEY" -H 'content-type: application/json' \ -d '{"crawl_id":"9f2c1a4be7d0435a","max_pages":400,"async":true}' localhost:8788/v1/crawlThe server mints the id, and POST /v1/crawl does not accept a new one. resume_or_start does not
validate a supplied id (an unknown one silently starts a fresh crawl under it), so letting a client
choose would be letting it choose this server’s primary key.
States
Section titled “States”queued ──claimed──> running ──┬── finished the frontier drained ├── stopped a budget: max_pages, time, tokens, saturation, │ or over_budget — this address has spent its │ standing with the site (docs/exits.md) ├── cancelled the crawl saw the flag ├── interrupted the process that owned it is gone └── failed the task panickedinterrupted is the state this whole design exists for. A crawl was always resumable
(crawl_queue has survived a kill since crawls were written), but crawl.status is set to running
per batch and nothing ever clears it, so there was no way to tell a crawl that died from one that
finished. The job row is that missing fact. It is detected by two things together: the row is owned
by another run, and its heartbeat has gone quiet for five minutes. Both halves are needed,
because two Svipall processes can share one database, and because crawl.updated_at is written per
batch: a level of two hundred pages can be half an hour between writes. The heartbeat is written
per page.
An interrupted job is resumed like any other: submit its id again.
Cancelling
Section titled “Cancelling”DELETE sets a durable flag in the row that survives a restart and, if the job is running here,
flips the one the crawl reads. The crawl checks it at two points, both places it is already between
things: the top of a batch, and the end of a page after that page’s links have been queued. It
then leaves through its ordinary exit, so the frontier is written and the id can be picked up again.
It never aborts the task. A one-shot browser call and web_capture close their browser page on the normal path
only, so killing a fetch mid-flight would leak a CDP page into the pool.
DELETE answers 200 with the state the job was in, including for a job that had already
finished: you wanted to know whether you stopped a running crawl or reaped a finished one, and both
are answers.
The stream
Section titled “The stream”event: snapshotdata: {"id":"9f2c…","state":"running","pages_done":41,"pending":118, …}
event: progressdata: {"job_id":"9f2c…","kind":"page","pages_done":42,"total":200,"queued":117, "url":"https://docs.example/guide","tier":"http","status":200}
event: donedata: {"id":"9f2c…","state":"finished","pages_done":57,"pending":0}The first frame is always a snapshot built from the store, never from the channel. That is the
one way this stream could lie: a subscriber joining at page forty and inferring “this started at
zero” from the first live event would draw a bar from the beginning of work that is nearly done.
It is a snapshot rather than a replay, deliberately. Full replay needs a durable event log written
per page and trimmed by the housekeeper (a real cost for a consumer that is a progress bar), and what
a late subscriber actually needs is where the job is now, which is already durable and exact.
There is no Last-Event-ID.
A progress event never carries the page. A crawl of two hundred pages that put its markdown in
every event would stream its whole result twice. Each event stays under half a kilobyte, and a test
enforces that.
A subscriber that falls behind gets event: lagged with how many it missed, not a closed
connection. And a listener can never slow or stop a crawl: the send is non-blocking and errors when
nobody is listening, which is the ordinary case.
Subscribing to a job that has already ended gives you snapshot then done, then the stream closes.
It never hangs. An unknown id is a 404 before any stream is opened.
One crawl per site
Section titled “One crawl per site”max_jobs (default 2) caps how many jobs run at once. Deliberately not parallelism, which bounds
requests inside one job: two crawls at parallelism 4 is eight in-flight fetches and, on a browser
tier, eight Chrome pages, which is more than capacity::concurrency would ever grant one crawl.
On top of that, a queued job whose site already has a job running is not started. The pacer
already prevents a burst (throttle keys (domain, exit) and concurrent callers each reserve the
next free slot), but what it cannot prevent is two jobs spending one address’s reputation with one
host twice as fast. That is the scarcest thing a local-only tool has: this project’s own benchmark
lost a target by running its lists eight times against one address in a day. The rule is decided by
the database, from the domain recorded when the job was queued, so a restart cannot forget it.
That incident now has a mechanism behind it as well as a rule: core::reputation keeps what
each address has spent with each host, lets it decay with a half-life, and slows down before
declining. See docs/exits.md. max_jobs and the one-crawl-per-site rule still
matter, since they stop two jobs spending the same budget twice as fast. The budget is what bounds
the total.
Configuration
Section titled “Configuration”rest_port = 0 # 0 = off. `svipall serve` starts it anyway; this is what makes # svipall-mcp mount it too.rest_bind = "127.0.0.1"api_key = "" # empty = ~/.svipall/api_key, generated on first usemax_jobs = 2SVIPALL_REST_PORT and SVIPALL_API_KEY override the first and third.
What svipall serve does not do yet
Section titled “What svipall serve does not do yet”The 60-second housekeeping loop that reaps idle browsers, trims the request log and evicts old
profiles lives in svipall-mcp’s main, and has not been moved yet. Under svipall serve the job
runner keeps its own house (orphan adoption, job expiry), but browsers are not reaped and the log
is not trimmed. Run the REST API from svipall-mcp with rest_port set if that matters to you.
/v1/solve_and_continue under svipall serve also has no human dashboard behind it: the CLI opens no
solver database. Local models still answer, but a challenge none of them can answer has nowhere to go.
Written from docs/rest.md at v2.10.0.