Skip to content

HTTP API

Five routes list and run Scrapers and read results. Every request carries the run token, and a Run answers with its result record.

Any HTTPS client can use an instance. The typed client and the MCP server are built on the routes on this page.

Authentication ​

Every request carries the run token:

text
Authorization: Bearer <run token>

A missing or wrong token answers 401 with the error body, and so does the deployer token. The run token can run every installed Scraper and read every result, but it cannot deploy. Keep it on servers or in your own browser tab, as the dashboard does. Tokens lists which token each route takes.

An instance can also hold named run tokens, each optionally limited to some Scrapers. Such a token sees only those Scrapers: GET /scrapers lists only them, and every other Scraper's description, run, runs list, results and items answer 404, as if it were not installed.

Routes ​

RequestAnswer
GET /scrapersThe generation and the installed Release identities.
GET /scrapers/<id>One Scraper's Release, schemas, grants and maximum Run duration.
POST /scrapers/<id>/runRuns a Scraper and returns its result record.
GET /scrapers/<id>/runsOne Scraper's stored Runs, newest first, a page at a time.
GET /results/<resultId>A result record.
GET /results/<resultId>/itemsA result's items as NDJSON.

The deployment routes, /deployments and /platform-deployments, are described in Deployment service.

GET /scrapers ​

json
{
  "generation": "…",
  "scrapers": [
    { "deployedAt": 1764852000000, "digest": "…", "id": "earthquakes", "revision": "v1" },
    { "deployedAt": null, "digest": "…", "id": "quotes", "revision": "v1" }
  ]
}

generation identifies everything installed and changes with every deploy. Every result record carries the revision and digest of the Release that produced it. deployedAt is when that Release was installed, in milliseconds since the epoch, or null for a Release installed before the instance recorded it.

GET /scrapers/<id> ​

json
{
  "deployedAt": 1764852000000,
  "digest": "…",
  "errorSchema": { "…": "…" },
  "grants": ["proxy:apify"],
  "id": "earthquakes",
  "inputSchema": { "…": "…" },
  "maxRunDuration": 600000,
  "outputSchema": { "…": "…" },
  "revision": "v1"
}

The installed Release of one Scraper: its identity and deployedAt as in GET /scrapers, the input, output and error JSON Schemas of its Definition, the Capabilities the grants table gives it, and its maximum Run duration in milliseconds. A Scraper that is not installed, or that the token may not use, answers 404. A Release that cannot describe itself answers 503 with release_unavailable.

POST /scrapers/<id>/run ​

The body is the raw JSON input of the Scraper.

sh
curl -sS -X POST "$SCWRAP_INSTANCE_URL/scrapers/earthquakes/run" \
  -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN" \
  -H "content-type: application/json" \
  -d '{"minMagnitude": "significant", "period": "week"}'

The answer comes at once: status 202, the running result record, and a location header naming /results/<resultId>. The Run continues on the instance whether or not the caller stays. Read the record until its status is completed or failed, then read the items.

StatusMeaning
202The Run started. The body is its running record.
200A repeat of an earlier request with the same Idempotency-Key. The body is that Run's record as stored now; nothing new ran.
400The input does not match the Definition, or the Idempotency-Key is malformed. Nothing ran.
404No Release with this ID is installed.
409The Run for this Idempotency-Key is still being handed to its owner. Retry after the retry-after seconds with the same key.
422This Idempotency-Key was already used with a different input. Nothing ran.
503The Run could not be handed to its owner. Nothing ran.

Idempotency-Key ​

Send an Idempotency-Key header to make the request safe to retry. The key is 1 to 255 printable ASCII characters without spaces; a scheduler can use the job name and its planned time, such as nightly-2026-11-28.

sh
curl -sS -X POST "$SCWRAP_INSTANCE_URL/scrapers/earthquakes/run" \
  -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN" \
  -H "Idempotency-Key: nightly-2026-11-28" \
  -H "content-type: application/json" \
  -d '{"minMagnitude": "significant", "period": "week"}'
  • Same key, same input: one Run. The first request answers 202; every repeat answers 200 with the same resultId and an idempotent-replayed: true header.
  • Same key, other input: 422. Inputs compare as JSON values, so key order and whitespace do not matter.
  • Scope: a key belongs to one run token name and one Scraper. Another named token, or another Scraper, using the same key starts its own Run.
  • Retention: a key is kept for 24 hours after its first request. After that, the same key starts a new Run.
  • Failed hand-off: when the first request answers 503, the key is released, and a retry with it starts the Run.

WARNING

Without an Idempotency-Key, do not retry a Run whose response was lost. The Run may already have executed, and its result ID is unknown to you.

GET /scrapers/<id>/runs ​

The Scraper's stored Runs, newest first by startedAt, one page at a time.

sh
curl -sS "$SCWRAP_INSTANCE_URL/scrapers/earthquakes/runs?limit=20" \
  -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN"
QueryMeaning
limitOptional. 1 to 50 Runs per page. Defaults to 50. Anything else answers 400.
cursorOptional. The nextCursor of the previous page.

The answer is { "runs": [ <result record>, … ], "nextCursor": "…" }, with nextCursor: null on the last page. Each record is the same as GET /results/<resultId> answers. A Run whose result has expired is no longer listed.

GET /results/<resultId> ​

json
{
  "count": 12,
  "digest": "…",
  "endedAt": 1795100000000,
  "error": null,
  "implementationDigest": "…",
  "input": { "minMagnitude": "significant", "period": "week" },
  "resultId": "…",
  "revision": "v1",
  "scraper": "earthquakes",
  "startedAt": 1795099990000,
  "status": "completed",
  "tokenName": "default",
  "traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
  "traceUrl": "https://app.axiom.co/jakob-kruse-yy9n/trace?traceDataset=scwrap-traces-production&traceId=4bf92f3577b34da6a3ce929d0e0e4736"
}
FieldMeaning
statusrunning, completed or failed.
countThe number of items checked and stored so far. While running, it trails the Run by up to 100 items or 5 seconds, because items are stored in chunks.
errornull, or the failure as a string of at most 2,000 characters.
failureOnly on a Run that failed with an error from the Definition's error union, or with one the platform raises whether or not the Definition declares it: that error encoded with its schema, such as { "_tag": "InvalidInput", "reason": "…" }. The platform raises SchemaDrift for an item that fails the output schema, as { "_tag": "SchemaDrift", "reason": "…", "sample": "…" }; InvalidInput for an input the schema rejects; RunTimeout for a Run that ran out of time, as { "_tag": "RunTimeout", "reason": "Run exceeded its maximum duration of 10m" }; and RequestLimitExceeded for a Run whose requests reached Cloudflare's subrequest limit (Known gaps).
digestThe digest of the Release's Worker module.
implementationDigestThe digest of the code that ran, the same as digest.
startedAt, endedAtMilliseconds since the epoch. endedAt is null while running.
tokenNameThe name of the run token that started the Run: default for the instance's run token, or a named token. Records written before named tokens existed have none.
traceId, traceUrlThe Run's trace: its 32-hex OTLP trace ID, and a link to it when the instance has a trace link. Only on records of an instance that exports traces.

A running record belongs to a Run that is still executing. Reading it asks the Run's owner; when the owner has died or never existed, the record is first marked failed with the error Run abandoned: its owner stopped before the Run ended. Its stored items are kept; the items of its last unstored chunk are lost. A Run that a forced deploy stopped is failed with an error that starts Run stopped by deploy <deploymentId>, and keeps every item it produced. One whose owner Cloudflare reset during a deploy anyway is failed with an error that starts Run cut by a deploy.

An unknown or expired ID answers 404. Results are deleted when the instance's retention runs out, 30 days after they were written by default; export them to keep them longer.

Run duration ​

A Run starts as soon as POST /scrapers/<id>/run accepts it, each in its own Run owner, so there is no queue and no wait for a slot. How long it may run is set per Release:

LimitValue
Default10 minutes, counted from when the Run owner starts the Release.
Per ReleasemaxRunDuration on Deployment.worker, more than 0 and at most 14 minutes. The CLI refuses a Release outside that range.
Ceiling14 minutes. The Run owner runs a Run from a Durable Object alarm, which Cloudflare stops after 15 minutes.

A Run that reaches its limit is interrupted inside its sandbox: its Stream's scope closes, so a browser it opened is closed and a Browser Use session is stopped, before the sandbox reports the timeout. If the sandbox has not ended the Run 30 seconds after the limit, the Run owner ends it with the same failure, stops waiting for it, and stops the Browser Use sessions the Run still holds (Browser Use sessions end with their Run). The Run ends failed with failure { "_tag": "RunTimeout", "reason": "Run exceeded its maximum duration of <limit>" } and error starting with the same reason. Every item checked before the limit is stored, the last unstored chunk included, and count says how many. The instance writes RunTimeout whether or not the Definition declares it; declare RunTimeout so that client.scraper(Definition).stream fails with it instead of a ClientFailure.

The limit bounds the Release's own work in its sandbox, so a Run's endedAt minus startedAt is longer: it adds the hand-off to the Run owner and the sandbox start before it, and storing the last chunk and the result record after it, a few seconds in all.

GET /results/<resultId>/items ​

The items, one JSON document per line (application/x-ndjson), in the order they were produced.

sh
curl -sS "$SCWRAP_INSTANCE_URL/results/<resultId>/items" \
  -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN"

Every line has passed the Definition's output schema. For a failed result, the lines are the items checked before the failure. For a running result, they are a snapshot.

Errors ​

Every error answer from /scrapers, /results and /mcp has content-type: application/json and the same body:

json
{ "code": "unknown_scraper", "error": "Unknown scraper" }
FieldMeaning
codeA stable identifier to branch on. New codes can be added; treat an unknown one by its HTTP status.
errorA message for people. Its wording can change.
reasonOnly on 503 release_unavailable: why the Release could not answer, one of the codes below. New codes can be added.
StatuscodeWhen
400invalid_inputThe body is not JSON or does not match the Definition's input schema. Nothing ran.
400invalid_idempotency_keyThe Idempotency-Key header is malformed.
400invalid_limitThe runs list limit is not 1 to 50.
401unauthorizedThe bearer token is missing or wrong.
404unknown_scraperNo Release with this ID is installed, or the token may not use it.
404not_foundAn unknown or expired result, a Scraper the token may not use on the runs list, or an unknown route.
404unknown_session/mcp only: the Mcp-Session-Id is not one this instance issued.
409run_startingThe Run for this Idempotency-Key is still being handed to its owner. Retry after retry-after seconds with the same key.
422idempotency_key_reusedThe Idempotency-Key was already used with a different input. Nothing ran.
500instance_failureThe instance failed unexpectedly.
500stored_result_unreadableA stored result record does not decode.
503instance_not_initializedThe instance has no run token.
503release_unavailableThe Release's sandbox could not check the input. Nothing ran. reason says why: artifact_read_failed (the bucket read failed three times), artifact_missing, artifact_digest_mismatch, sandbox_failed (the sandbox loaded but failed), or no_sandbox (the instance runs no sandboxes).
503run_owner_unavailableThe Run could not be handed to its owner, or its owner did not answer. Nothing ran.
503result_storage_unavailableThe results bucket did not answer.

The schema is ErrorBody in @scwrap/client/protocol. The deployment routes answer with the same body, and an MCP tool that fails carries the same code.

Exporting results ​

Run records and items are deleted when the instance's result retention runs out: SCWRAP_INSTANCE_RESULT_RETENTION_DAYS days after they were written, 30 by default and at most 3650 (Variables). Changing the setting changes the lifecycle rule for objects already stored too. The instance keeps no archive, so to keep results longer, copy them out before then: page through a Scraper's runs list and save the items of every Run that has ended.

sh
scraper=earthquakes
cursor=""
mkdir -p "export/$scraper"
while :; do
  page=$(curl -sSf "$SCWRAP_INSTANCE_URL/scrapers/$scraper/runs?limit=50${cursor:+&cursor=$cursor}" \
    -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN")
  for id in $(jq -r '.runs[] | select(.status != "running") | .resultId' <<<"$page"); do
    [ -e "export/$scraper/$id.ndjson" ] && continue
    jq -c --arg id "$id" '.runs[] | select(.resultId == $id)' <<<"$page" >"export/$scraper/$id.json"
    curl -sSf "$SCWRAP_INSTANCE_URL/results/$id/items" \
      -H "Authorization: Bearer $SCWRAP_INSTANCE_RUN_TOKEN" >"export/$scraper/$id.ndjson"
  done
  cursor=$(jq -r '.nextCursor // empty' <<<"$page")
  [ -z "$cursor" ] && break
done

Each Run leaves its record as <resultId>.json and its items as <resultId>.ndjson. Run it more often than the retention, such as daily: it skips Runs it already saved, and a Run still running is saved on a later pass. The records' count tells you how many lines each items file must have. With the typed client, client.scraper(Definition).runs and items do the same (client).

Rate limits ​

An instance has no rate limiter and no quota of its own. Every request with a valid run token is served, and every accepted Run starts at once in its own Run owner, so a caller that starts a thousand Runs gets a thousand Runs, each costing what its Scraper costs (Monthly cost). Use named tokens to tell callers apart, and limit callers on your side.

What stops a request is a Cloudflare platform limit (Workers limits, Durable Objects limits). A caller sees one of these:

AnswerWhen
503 run_owner_unavailableThe Run could not be handed to its Run owner, for example while Cloudflare is overloaded or resets the object. Nothing ran; retry with the same Idempotency-Key.
503 release_unavailableThe Release's sandbox could not check the input. Nothing ran. Its reason says why (Errors).
503 result_storage_unavailableR2 refused a read or write.
A Cloudflare error page, such as error 1102 Worker exceeded resource limitsThe release Worker ran out of CPU time or memory for that request. It is HTML, not the instance's JSON.
A failed RunA limit hit inside the Run, such as the 10,000 subrequests a Run may make, the Run's maximum duration, or a vendor's limit such as Browser Run's concurrent browsers. The Scraper's error, or the error text, says which.

A Workers spending limit set on the account (Spend management) rejects new invocations once it is reached; callers then see Cloudflare's error instead of the instance's answers.

Browsers ​

A page on another origin can call /scrapers and /results only when the instance lists that origin in SCWRAP_INSTANCE_BROWSER_ORIGINS (Variables), a JSON array of HTTPS origins such as ["https://ops.example.com"]. For a listed origin those routes answer the OPTIONS preflight with 204 and add the CORS headers to every answer: the Authorization, Content-Type and Idempotency-Key request headers are allowed, and Idempotent-Replayed and Location are exposed. Any other origin gets no CORS headers, so its browser refuses the answers. The run token is still required; the list only lets browsers on those origins read the answers. /mcp and the deployment routes never answer browsers on other origins. The dashboard on the instance's own origin needs no entry.

Compatibility ​

Routes, answers and the result record change only by the rules in Shipping safely: new fields and routes can appear at any time, so ignore fields you do not know, and nothing is changed or removed without a deprecation through one SDK minor version.

Other paths ​

An instance serves no pages of its own, except the dashboard at /dashboard/ when it is turned on. Any other GET or HEAD answers 404 without a token, or, when the instance sets SCWRAP_INSTANCE_REDIRECT_ORIGIN (Variables), 301 to the same path and query on that origin. The production instance redirects to the docs at https://scwrap.dev. The API paths (/scrapers, /results, /mcp, /deployments, /platform-deployments, /internal) each require their bearer token and answer 401 without it.

Source ​