Skip to Content
CrawlersSchedules & Runs API

Schedules & Runs API

An API for your organization’s schedules (your cron-scheduled spiders) and runs (every job, with its metrics) — the same data the dashboard shows, available to your own systems and to your spiders. With a key that has run access, your backend can also start and cancel runs on demand.

Use it to build dashboards, alerting, a metrics-export spider that ships run stats to your own warehouse, or a backend that runs a spider per request (Start and cancel runs on demand).

Every credential on this page is scoped to one project of your organization: you see your own schedules and runs, never anyone else’s. Keys and the token handed to each job read; only an sp_ key created with run access can also start and cancel runs of its project. Nothing here changes your schedules or code. If you want an AI agent to read this data (and, with a separate write-scoped token, act on it), see Connect your AI agent (MCP).

Authentication

Two ways to authenticate, depending on where you’re calling from.

From your own systems — use a deploy API key. Create one in Deploy → API Keys (it’s shown once, starts with sp_). Send it as a bearer token:

curl -H "Authorization: Bearer sp_your_key" \ "https://<your-arachne-host>/api/v1/client/schedules"

X-API-Key: sp_your_key works too. A key is created for one project and reads only that project: a ?project= for another project is ignored.

To let your backend start and cancel runs, an organization admin turns on Allow starting and cancelling runs when generating the key. The key then carries the jobs:write scope, shown in the key list’s Access column. Keys without it get 403 on the start and cancel routes. Use a separate key per backend and environment, so you can revoke one without the others.

⚠️

Every sp_ key, with or without run access, can also create, update and delete the secrets of its project (that is how the CI secrets-sync step works; a secret’s value is never returned). Treat every key as a credential and revoke keys you no longer use.

From inside a spider — no setup. Every job is handed a short-lived, project-scoped, read-only token and the base URL as environment variables. It reads only the schedules and runs of the job’s own project: a ?project= for another project is ignored (the request is answered for the token’s own project), and fetching another project’s schedule or run by id returns 403 (metrics token can only read its own project). For an export across several projects, call the API from your own systems with one sp_ key per project.

import os, urllib.request, json base = os.environ["INSIGHT_METRICS_API_URL"].rstrip("/") token = os.environ["INSIGHT_METRICS_API_TOKEN"] req = urllib.request.Request( f"{base}/api/v1/client/jobs?limit=20", headers={"Authorization": f"Bearer {token}"}, ) runs = json.load(urllib.request.urlopen(req, timeout=30))["jobs"]

See Inside a Job for the full list of injected variables.

Endpoints

All endpoints are under /api/v1/client and return JSON with a "status": "ok" field. The two POST routes need a key with run access (see Start and cancel runs on demand).

EndpointReturns
GET /api/v1/client/schedulesYour schedules (schedules[], total).
GET /api/v1/client/schedules/{id}One schedule (schedule).
GET /api/v1/client/schedules/{id}/executionsA schedule’s recent fires (executions[]).
GET /api/v1/client/jobsRuns, newest first (jobs[], total).
GET /api/v1/client/jobs/{id}One run (job).
GET /api/v1/client/jobs/{id}/statsA run’s detailed stats (stats and stats_json, null until it ends).
POST /api/v1/client/jobsStart a run (job). Run access only.
POST /api/v1/client/jobs/{id}/cancelCancel a run. Run access only.
GET /api/v1/client/jobs/statsRun counts by status.
GET /api/v1/client/metrics/dashboardCounts + active schedules + online nodes.

Query parameters

schedules and jobs are paginated and sortable:

ParameterApplies toNotes
limit, offsetbothPage size (default 50, maximum 1000); page with offset and the returned total.
projectbothExact project name.
spiderjobsSubstring match on the spider name.
statusjobsExact run status: pending / running / finished / error / cancelled.
tagjobsExact tag; repeat it (?tag=a&tag=b) to get runs carrying all the given tags.
searchbothSubstring over the spider name (and, on either endpoint, the schedule name).
sort, dirbothSort column (see below) + asc / desc.

Sortable columns — schedules: next_run_at, last_run_at, run_count, name, project, spider, status, cron_expression, timezone, created_at. jobs: created_at (default, newest first), start_time, end_time, items_scraped, pages_scraped, error_count, status, priority, project, spider, schedule_name.

The schedules endpoint has no status filter (only jobs does). To see just active or just paused schedules, filter client-side on the status field — see the note under The next scheduled spiders.

Request bodies sent to the API are capped at 1 MiB; larger bodies are rejected.

The next scheduled spiders

Sort schedules by next_run_at ascending to get what’s coming up:

GET /api/v1/client/schedules?sort=next_run_at&dir=asc&limit=30
{ "status": "ok", "total": 42, "schedules": [ { "id": 7, "name": "Nightly catalogue", "project": "shop", "spider": "catalogue", "cron_expression": "0 3 * * *", "timezone": "America/Mexico_City", "status": "active", "next_run_at": "2026-07-08T09:00:00Z", "last_run_at": "2026-07-07T09:00:00Z", "run_count": 128 } ] }

Each schedule also carries args, settings, tags, priority, version, jitter_seconds, misfire_grace_seconds, coalesce, max_instances, retry_on_failure, retry_count, start_date, end_date, and pause_reason.

⚠️

Paused schedules can sort first. A paused schedule keeps its last next_run_at — a time in the past that doesn’t advance while paused. So sorting by next_run_at ascending can surface paused schedules ahead of the ones that will actually fire. Since the endpoint has no status filter, keep only status == "active" client-side to get “what will run next”:

page = get("/api/v1/client/schedules", sort="next_run_at", dir="asc", limit=200) upcoming = [s for s in page["schedules"] if s["status"] == "active"][:30]

Recent runs & their metrics

Runs come back newest-first by default:

GET /api/v1/client/jobs?limit=20
{ "status": "ok", "total": 5310, "jobs": [ { "id": "b3f1a2c4-...", "project": "shop", "spider": "catalogue", "status": "finished", "items_scraped": 12840, "pages_scraped": 1310, "error_count": 2, "warning_count": 5, "start_time": "2026-07-07T09:00:03Z", "end_time": "2026-07-07T09:14:51Z", "finish_reason": "finished", "schedule_id": 7, "schedule_name": "Nightly catalogue" } ] }

status is one of pending, running, finished, error, cancelled. The per-run counters (items_scraped, pages_scraped, error_count, warning_count) update live while a job runs and are final once it’s finished. schedule_name is present when the run came from a schedule.

Each run returns only these client-relevant fields (id, project, spider, version, status, priority, args, settings, tags, the counters, start_time, end_time, finish_reason, error_message, schedule_id, schedule_name, created_at, updated_at) — internal execution details are not exposed.

For the deeper breakdown of a single run — response codes, retries, dropped items, runtime — call its stats:

GET /api/v1/client/jobs/{id}/stats
{ "status": "ok", "stats": { "runtime_seconds": 888.4, "items_scraped": 12840, "items_dropped": 3, "pages_crawled": 1310, "response_200": 1290, "response_404": 12, "response_429": 4, "response_500": 0, "retry_count": 18, "error_count": 2, "finish_reason": "finished" } }

stats and stats_json are null while a run is pending or running; read the live counters from the run object itself (/jobs/{id}). Once the run’s status is finished, error or cancelled, both are always present, so the first poll that sees the final status can read the stats.

Start and cancel runs on demand

With a key that has run access (see Authentication), your backend can run a spider per request — a store, a URL, a customer — and track each run by its own id. A key starts and cancels runs of its own project only.

Start a run

POST /api/v1/client/jobs Authorization: Bearer sp_your_key Idempotency-Key: store-4711:2026-11-13T10:00Z Content-Type: application/json { "project": "shop", "spider": "catalogue", "args": {"store_id": "4711"}, "settings": {"CLOSESPIDER_TIMEOUT": "900"}, "tags": ["store:4711", "env:prd"], "priority": 50 }
FieldNotes
projectRequired. Must be the key’s project (403 otherwise).
spiderRequired. A spider of the project’s version.
versionOptional. Defaults to the project’s latest version.
argsOptional. Spider arguments (scrapy -a); string values without control or shell characters.
settingsOptional. Scrapy settings (scrapy -s) from an allowlist; string values ("900", not 900).
tagsOptional. Up to 32 tags of 1–128 characters; use them to find runs again.
priorityOptional, -100..100, default 0. Higher runs first; 50 and above counts as on-demand (see Limits).

Unknown fields are rejected, so a typo never runs with defaults. The answer is 201 with {"status": "ok", "job": {…}} (the same run object as GET /jobs/{id}, status pending).

StatusWhen
201Run created and queued.
200Replay of an earlier request with the same Idempotency-Key and the same body: the existing run is returned (header Idempotent-Replayed: true).
400Invalid JSON, an unknown field, a bad tag, a setting outside the allowlist, or an invalid Idempotency-Key.
403The key has no run access, or project is not the key’s project.
404The project has no versions, or the version or spider is unknown.
409The Idempotency-Key expired while it was being read; retry (Retry-After: 1).
422The Idempotency-Key was already used with a different body.
429Too many pending runs, or the write rate limit; always has Retry-After (seconds).

Idempotency-Key (optional, recommended): 1–255 printable ASCII characters, remembered for 24 hours per project. Derive it from your own unit of work and retry network errors and 5xx with the same key: you get exactly one run, even if two retries race. If a start fails with 5xx, the key is released, so the retry creates the run.

Cancel a run

POST /api/v1/client/jobs/{id}/cancel Authorization: Bearer sp_your_key Content-Type: application/json {"force": false}
  • "force": false (the default) stops a running spider gracefully: Scrapy closes, writes its items and its final stats. "force": true kills it at once. A pending run is removed from the queue and becomes cancelled immediately.
  • The answer is 200 {"status": "ok", "jobid": "…", "prevstate": "pending" | "running"}. Cancelling a run that already ended is also 200, with prevstate set to its final status, so retries are safe.
  • A graceful cancel sets the status to cancelled at once while the spider is still shutting down; its stats arrive when it exits (stats_final turns true on the stats route). If it does not exit, cancel again with "force": true.
  • 404 for an unknown id or a run of another project.

Follow a run

Poll GET /api/v1/client/jobs/{id} for status: pending → running → finished, error or cancelled. Then read GET /api/v1/client/jobs/{id}/stats:

{ "status": "ok", "job_status": "finished", "stats_final": true, "stats": {"items_scraped": 231, "pages_crawled": 309, "error_count": 0, "runtime_seconds": 58.2, "finish_reason": "finished"}, "stats_json": {"item_scraped_count": "231", "downloader/response_count": "309", "finish_reason": "finished"} }
  • stats_json is Scrapy’s full stats dictionary, including counters your spider adds itself. Every value is a string ("231", not 231): decode it as a string map and parse the keys you need. Typed numbers are in stats.
  • A run that ended before Scrapy reported anything (cancelled while pending, failed to start) has stats_json: {}.
  • error with finish_reason platform_timeout means the run reached the maximum runtime.
  • To find runs again, list them by tag: GET /api/v1/client/jobs?tag=store:4711&tag=env:prd.

Limits

Per organization:

LimitValueWhen reached
Running runs8Runs below priority 50 wait in the queue (no error) until a slot frees.
Extra on-demand slots+3Runs at priority 50 or above may start while fewer than 11 runs are running.
Pending runs500Start answers 429 with Retry-After.
Write rate60 per minuteStarts and cancels share this budget with your other dashboard writes (schedule edits included); 429 with Retry-After.
Maximum runtime48 hoursThe run is stopped and ends error / platform_timeout.
  • Reading status, stats and lists is not rate-limited; polling every 10 seconds is fine.
  • Higher priority runs first, oldest first within a priority, so on-demand runs at 50 go ahead of scheduled runs at 0. Nothing already running is interrupted.
  • To end a run before the maximum runtime, pass Scrapy’s own close conditions in settings: CLOSESPIDER_TIMEOUT (seconds), CLOSESPIDER_ITEMCOUNT, CLOSESPIDER_PAGECOUNT, CLOSESPIDER_ERRORCOUNT, CLOSESPIDER_TIMEOUT_NO_ITEM and CLOSESPIDER_PAGECOUNT_NO_ITEM are allowed. The run then ends finished with finish_reason closespider_timeout (and so on).

Example

KEY=sp_your_key # created with run access for project "shop" API=https://<your-arachne-host> JOB=$(curl -fsS -X POST "$API/api/v1/client/jobs" -H "Authorization: Bearer $KEY" \ -H "Idempotency-Key: store-4711:$(date -u +%Y%m%dT%H%M)" -H 'Content-Type: application/json' \ -d '{"project":"shop","spider":"catalogue","args":{"store_id":"4711"},"settings":{"CLOSESPIDER_TIMEOUT":"900"},"tags":["store:4711"],"priority":50}' \ | jq -r .job.id) curl -fsS "$API/api/v1/client/jobs/$JOB" -H "Authorization: Bearer $KEY" | jq -r .job.status curl -fsS "$API/api/v1/client/jobs/$JOB/stats" -H "Authorization: Bearer $KEY" | jq .stats_json curl -fsS -X POST "$API/api/v1/client/jobs/$JOB/cancel" -H "Authorization: Bearer $KEY" -d '{"force":false}'

Build a metrics-export spider

Put the two together to export on a schedule of your own: a spider that reads its own project’s schedules + runs (the injected token cannot read other projects; for an org-wide export use an sp_ key that is not bound to a project, supplied as a project secret) and writes them wherever you want. A working end-to-end example ships in the reference project as metrics_export_demo — it logs the next 30 scheduled spiders and the last 20 runs with their metrics. The core of it:

import os, urllib.request, urllib.parse, json import scrapy class MetricsExportSpider(scrapy.Spider): name = "metrics_export" def __init__(self, *a, **k): super().__init__(*a, **k) self.base = os.environ["INSIGHT_METRICS_API_URL"].rstrip("/") self.token = os.environ["INSIGHT_METRICS_API_TOKEN"] def get(self, path, **params): url = self.base + path if params: url += "?" + urllib.parse.urlencode(params) req = urllib.request.Request(url, headers={"Authorization": f"Bearer {self.token}"}) return json.load(urllib.request.urlopen(req, timeout=30)) async def start(self): upcoming = self.get("/api/v1/client/schedules", sort="next_run_at", dir="asc", limit=30) for s in upcoming["schedules"]: self.logger.info("next: %s %s @ %s", s["spider"], s["cron_expression"], s["next_run_at"]) runs = self.get("/api/v1/client/jobs", limit=20) for r in runs["jobs"]: self.logger.info("run: %s %s items=%s errors=%s", r["spider"], r["status"], r["items_scraped"], r["error_count"]) # …ship `r` to your own warehouse / dashboard here. return yield # marks start() as an async generator

Because the token is injected automatically, the same spider works unchanged on any schedule — point it at your destination in settings.py (see Getting your data out).

Last updated on