Crawler
Crawl a site within a page budget, review what came back, and publish the approved pages to Knowledge.
The Crawler collects pages from a website (or from web search results), cleans them into text, and holds them for review. Pages you approve are then published into Knowledge for search.
Crawled content comes from the open web, so it is untrusted until a person has looked at it. That is why the flow has a gate in the middle:
create ─▶ start ─▶ crawling ─▶ ready ─▶ approve pages ─▶ publish ─▶ published
(free) (quota) (a person) (to Knowledge)pip install aice-crawlerCreate a client
import os
from aice_crawler import CrawlerClient
client = CrawlerClient(
base_url=os.environ["AICE_CRAWLER_URL"], # http://localhost:6200/crawl
api_key=os.environ["AICE_API_KEY"],
user_id=current_user.id,
user_role=current_user.role, # admin/owner needed to change the policy
)| Argument (Python / TypeScript) | Default | Meaning |
|---|---|---|
base_url / baseUrl | the service host and its /crawl path | |
api_key / apiKey | the project key. Needs Crawler enabled on the project | |
user_id / userId | sent as X-User-Id. Required by the service | |
user_role / userRole | none | sent as X-User-Role. admin, owner or service_role is needed to narrow the policy |
timeout | 30.0 s / 30000 ms | per-request timeout |
max_retries / maxRetries | 3 | retries on network errors, 5xx and 429 |
Python also has AsyncCrawlerClient with the same resources (await every call, close with await client.aclose()).
A crawl, start to finish
Create the job
Creating a job costs nothing and starts nothing, so you can show "up to 200 pages" before anyone commits to a crawl.
job = client.jobs.create(
start_urls=["https://docs.example.com"], # sent as seed_urls
page_budget=200, # sent as max_pages
max_depth=2,
scope="host",
name="Docs site",
)
print(job["id"], job["status"]) # "pending"The client's names map to the service's fields: start_urls / startUrls is seed_urls and page_budget / pageBudget is max_pages. The other fields have their own arguments (search_query / searchQuery, max_depth / maxDepth, scope, mode, llm_instruction / llmInstruction, review_mode / reviewMode, name), and anything else can go in config, which is sent as-is. A job needs seed URLs or a search query; with neither, the client raises ValueError (Python) or rejects with an Error (TypeScript) before sending anything.
| Service field | Default | Meaning |
|---|---|---|
seed_urls | pages to start from. This or search_query is required | |
search_query | start from web search results instead | |
max_search_results | 5 | results to take from the search (1–25) |
max_pages | 200 | the page budget. The deployment caps it (5,000 by default) |
max_depth | 2 | how many links deep to follow (0–6) |
scope | host | host stays on the seed's host, domain includes its subdomains, any follows links anywhere (limited to depth 1) |
mode | raw | raw keeps the cleaned page text; llm rewrites each page with your instruction, costing a model call per page |
llm_instruction | required when mode is llm | |
review_mode | manual | manual holds pages for approval; auto approves them as they arrive |
name | a label for the job |
URLs that can't be crawled are rejected when you create the job (ValidationError), not when it runs: it must be http or https, and the crawler refuses targets that resolve to private or internal addresses.
A job's status moves through pending → queued → crawling → ready → publishing → published, or failed. It also carries counters: pages_discovered, pages_fetched, pages_failed, pages_skipped and pages_published.
Start it
client.jobs.start(job["id"])Starting checks your quota, then queues the crawl; it returns {"ok": true, "queued": true, "job_id": ...} and the crawl runs in the background. Poll jobs.get(id) until status is ready (or failed, in which case error_message says why).
A start can be refused with 429 (a RateLimitError) naming the limit you hit, or 409 if the job isn't pending or failed. A failed job can be started again.
Read the pages
result = client.jobs.list_pages(job["id"], params={"status": "fetched", "limit": 100})
for page in result["pages"]:
print(page["id"], page["url"], page["title"])
page = client.pages.get(result["pages"][0]["id"])
print(page["content_markdown"])list_pages returns {"pages": [...], "count": n} without the page bodies (limit up to 500). pages.get returns one page with its markdown, for a review screen.
A page's status is pending, fetching, fetched, failed or skipped. Skipped is not a failure: the crawler behaved correctly and chose not to fetch the URL (blocked by robots.txt, out of scope, or a disallowed target). The row is kept so you can explain why a link was seen but not fetched. Only fetched pages can be approved.
Approve pages
Approval is per page, from 1 to 500 page IDs a call:
fetched = client.jobs.list_pages(job["id"], params={"status": "fetched"})["pages"]
client.jobs.approve(job["id"], [p["id"] for p in fetched])
client.jobs.approve(job["id"], ["pg_9"], approved=False) # un-approveThe answer is {"ok": true, "updated": 2, "requested": 2}. updated can be lower than requested: only fetched pages can be approved. An empty list, or more than 500 IDs, is refused before anything is sent; split a larger job into several calls. With review_mode: "auto" you don't need this step at all.
Publish
client.jobs.publish(job["id"])Only approved pages are published. Each goes to Knowledge as a document whose source_uri is the page's URL, so a citation reads as the web address. Publishing needs the job to be ready (or already published; a second publish pushes pages you approved since). It returns {"ok": true, "queued": true, ...} and finishes in the background; jobs.get shows pages_published rising and the status becoming published.
A page whose content Knowledge already holds comes back as a duplicate, and that counts as success, so re-crawling an unchanged site is cheap.
Listing jobs
for j in client.jobs.list(params={"status": "ready", "limit": 20})["jobs"]:
print(j["id"], j["name"], j["pages_fetched"], "/", j["max_pages"])jobs.list returns {"jobs": [...], "count": n}; filters are status, limit (1–200) and offset.
Re-crawling on a schedule
client.jobs.schedule(job["id"], {"interval_seconds": 86400})
client.jobs.schedule(job["id"], {"interval_seconds": None}) # cancel
for run in client.jobs.list_runs(job["id"])["runs"]:
print(run["id"], run["status"])The schedule lives on the job you attach it to. Each run is a new child job, with its own pages and review, so earlier approvals and the record of what was published are never rewritten. Unchanged pages come back as duplicates when published.
interval_secondshas a minimum (one hour by default), so a schedule can't hammer a site. A smaller value is aValidationError.first_run_at(an ISO 8601 time) sets when the first run happens.- Every run goes through the same quota check as a manual start.
jobs.reclean(id) re-processes pages offline from the raw HTML the crawler archived, without fetching the site again. Use it after the text cleaning improves. It only touches pages that haven't become Knowledge documents yet, and answers 409 when the deployment doesn't archive raw HTML (pages crawled before archiving was turned on can't be re-cleaned).
Organization policy
policy.get() returns {"policy": {...}, "usage": {...}}: the project's crawl limits, the domains agents may crawl, and what has been used. The top-level fields are what applies; policy.ceiling is what your organization and AICE allow, and policy.yours is this project's own narrowing (null where it follows the ceiling).
The ceiling is set in the console: an organization admin chooses the allowed sites under Settings › Organization, and AICE sets the quotas. policy.update(...) can only make the policy tighter: domains must be a subset of what the organization allows and each quota at or below the ceiling, otherwise it is a 403 (raised as AiceForbiddenError) naming the field. It also needs the admin, owner or service_role role. Send a field as null to go back to the ceiling.
client.policy.update({
"max_concurrent_jobs": 3,
"max_pages_per_day": 20000,
"agent_allowed_domains": ["docs.example.com", "example.org"],
})| Field | Range |
|---|---|
max_concurrent_jobs | 1–50 |
max_jobs_per_day | 1–10,000 |
max_pages_per_day | 1–1,000,000 |
agent_allowed_domains | up to 200 domains agents may crawl, all within the organization's list |
Send only the fields you want to change. Quotas are checked when a job starts, never mid-crawl, so a quota that fills up can't strand a half-finished job. max_jobs_per_day counts jobs started, not created, and max_pages_per_day counts pages already created, so one job admitted just under the cap can overshoot by up to its own page budget. The usage block reports active_jobs, jobs_today and pages_today.
Use it from an agent
An Agent Platform agent can crawl through three tools, added with Crawler in Agent Studio (tool_bindings: ["crawler"] in code): crawl_url, list_crawl_jobs and get_crawl_job.
An agent can start a crawl, but it can never read what came back:
- No tool returns page text.
crawl_urlreturns a job ID andget_crawl_jobreturns counters. Crawled text reaches a model only after a person approves it and it is published into Knowledge. A web page written to manipulate an agent has no path into that agent's context. - Agents can only crawl allowed domains. When your organization lists allowed sites, an agent's crawl can't start outside them and doesn't follow links off them. With no list, any site is allowed. Domains match on their registrable form, so
evil-example.orgdoes not matchexample.org. - Agent jobs are clamped: always
manualreview,rawmode, depth 1 and 25 pages, whatever the agent asks for.
Errors
| Error | When |
|---|---|
ValidationError | an uncrawlable URL (no seeds and no query is caught by the client first), llm mode without an instruction, scope: "any" deeper than depth 1, a schedule below the minimum, an empty policy update |
NotFoundError | the job or page doesn't exist in your project |
RateLimitError (429) | starting a job would exceed your policy. The message names the limit |
AiceError (409) | starting a job that isn't pending/failed, publishing before ready, or reclean with archival off |
AiceForbiddenError | changing the policy without an admin role |
jobs.create is sent once and never retried: the service doesn't yet deduplicate it, and a retry could start a second crawl. A transient failure reaches you immediately. See Errors and retries. The other writes (start, approve, publish, schedule, reclean) retry with an automatic Idempotency-Key.
Reference
| Python | TypeScript | Endpoint |
|---|---|---|
jobs.create | jobs.create | POST /jobs (not retried) |
jobs.list / get | jobs.list / get | GET /jobs, GET /jobs/{id} |
jobs.start | jobs.start | POST /jobs/{id}/start |
jobs.list_pages | jobs.listPages | GET /jobs/{id}/pages |
pages.get | pages.get | GET /pages/{id} |
jobs.approve | jobs.approve | POST /jobs/{id}/approve |
jobs.publish | jobs.publish | POST /jobs/{id}/publish |
jobs.schedule | jobs.schedule | PUT /jobs/{id}/schedule |
jobs.list_runs | jobs.listRuns | GET /jobs/{id}/runs |
jobs.reclean | jobs.reclean | POST /jobs/{id}/reclean |
policy.get / update | policy.get / update | GET, PUT /policy |