Submit a request from your backend
Keep credentials in a server-side secret store. The key needs scrape:write to submit and requests:read to poll and read results. Generate a unique idempotency key for each new logical request and retain it with the exact body. The following example submits work; it does not immediately return the finished page.
curl --request POST "https://api.runharvester.com/api/v1/data/requests" \
--header "X-API-Key: YOUR_API_KEY" \
--header "Idempotency-Key: YOUR_UNIQUE_REQUEST_KEY" \
--header "Content-Type: application/json" \
--data '{"url":"https://example.com/catalog","mode":"auto"}'Poll the state, then retrieve the result
Save the returned id. Poll the status endpoint with backoff and jitter until status is completed, failed, or cancelled; pending, queued, waiting_for_page, running, and solving_captcha are not complete states.
The POST response returns the request id, status, and billing metadata. A raw result contains id, html, text, result_meta, and expires_at; an extraction result also contains data and extraction state. The runnable example prints the JSON returned for your request; values depend on the target page, so no fixed result is invented.
Set RUNHARVESTER_API_KEY and RUNHARVESTER_IDEMPOTENCY_KEY in your server environment. Keep the same key and exact body for an uncertain retry; use a new key for a new observation. API errors use the documented error, code, message, and requestId fields. A result requested before completion returns 409 RESULT_NOT_READY; an expired result returns 410 RESULT_EXPIRED.
import json
import os
import random
import time
from urllib.error import HTTPError
from urllib.request import Request, urlopen
API = "https://api.runharvester.com/api/v1/data"
API_KEY = os.environ["RUNHARVESTER_API_KEY"]
IDEMPOTENCY_KEY = os.environ["RUNHARVESTER_IDEMPOTENCY_KEY"]
HTTP_TIMEOUT_SECONDS = 30
CLIENT_WAIT_LIMIT_SECONDS = 240
INITIAL_POLL_DELAY_SECONDS = 1
MAX_POLL_DELAY_SECONDS = 10
POLL_JITTER_RATIO = 0.2
def call(method, path, payload=None):
body = None if payload is None else json.dumps(payload).encode()
headers = {"X-API-Key": API_KEY}
if payload is not None:
headers["Idempotency-Key"] = IDEMPOTENCY_KEY
headers["Content-Type"] = "application/json"
request = Request(
API + path,
data=body,
method=method,
headers=headers,
)
try:
with urlopen(request, timeout=HTTP_TIMEOUT_SECONDS) as response:
return response.status, json.load(response)
except HTTPError as error:
response_body = error.read().decode("utf-8")
raise RuntimeError(
"HTTP " + str(error.code) + " " + path + ": " + response_body
) from error
status_code, submission = call(
"POST", "/requests", {"url": "https://example.com/", "mode": "auto"}
)
if status_code != 202:
raise RuntimeError("Unexpected submission status: " + str(status_code))
request_id = submission["id"]
print("202 submission:", json.dumps(submission, indent=2))
deadline = time.monotonic() + CLIENT_WAIT_LIMIT_SECONDS
delay = INITIAL_POLL_DELAY_SECONDS
while time.monotonic() < deadline:
status_code, state = call("GET", "/requests/" + request_id)
if status_code != 200:
raise RuntimeError("Unexpected polling status: " + str(status_code))
print("200 status:", json.dumps(state, indent=2))
if state["status"] == "completed":
break
if state["status"] in {"failed", "cancelled"}:
raise RuntimeError("Request ended without a result: " + json.dumps(state))
time.sleep(delay + random.random() * delay * POLL_JITTER_RATIO)
delay = min(delay * 2, MAX_POLL_DELAY_SECONDS)
else:
raise TimeoutError("Request did not complete before the client deadline")
status_code, result = call("GET", "/requests/" + request_id + "/result")
if status_code != 200:
raise RuntimeError("Unexpected result status: " + str(status_code))
print("200 result:", json.dumps(result, indent=2))Choose acquisition and output independently
Select HTTP if the initial response holds the required data, switch to browser mode for JavaScript execution, or choose auto to let the system handle route selection. Residential modes indicate an egress requirement. Availability depends on account status and deployment details.
To produce typed output, include extraction.fields or reference an active recipe you own. Structured extraction is limited to individual requests; Data API batches process only raw scrape jobs.
Handle failures without hiding them
RESULT_NOT_READY means the result was requested before completion; continue polling instead of submitting duplicate work. Results are retained for seven days; RESULT_EXPIRED means that window has passed. The example surfaces the HTTP status and response body for API errors. Inspect public error fields and request events before deciding whether to retry.
Resubmit the interrupted request using its original idempotency key and payload. Each retry of a failed job generates a new request ID. For bounded retries, retrieve outcomes before expiration and apply the returned billing metadata for cost reconciliation.
Integrate in your existing runtime
Use the documented HTTP interface from your backend. Keep Data API credentials server-side. The existing MCP server provides a documented Streamable HTTP connection for agents, with Data API tools.