Low-level Firecrawl HTTP client plus the pure helpers behind the job functions: body building, next-page following, and job status checks. Most code wants the functions in ::firecrawl instead.

Per-call credentials. Every API-calling function in this package takes an optional trailing opts Map, resolved by resolve: opts first, then the firecrawl.api.key context variable, then the defaults. Nothing from opts is written to ctx, so one run can act for many tenants and parallel flows don't share credentials. Credentials in opts are masked in call records. An api-key present but blank or null is an error, never a fallback to context.

  • api-key: the API key for this call
  • base-url: another API root, such as a self-hosted Firecrawl. It needs an api-key in the same opts: firecrawl.api.key is never sent to a per-call URL.

Context Vars

Optional
  • firecrawl.api.key

Values

MAX_PAGES

MAX_PAGES: Int 1000

Functions

body-with

fn (required: Map, options: Map): Map

Merge caller options with the required fields (required fields win) and drop null values, so unset options are omitted rather than sent as JSON null. Exposed for testing.

Example

::firecrawl::api/body-with({url: "https://example.com"}, {limit: 5, url: "ignored", webhook: null})
// {url: "https://example.com", limit: 5}

build-request

fn (method: Str, path: Str, body: Any, resolved: Map): ::hot::http/HttpRequest

The outgoing HttpRequest from resolved settings (see resolve). A "" body sends no Content-Type. Pure; exposed for testing.

Example

req ::firecrawl::api/build-request("POST", "/scrape", {url: "https://example.com"}, {
  api-key: "tenant-key",
  base-url: "https://api.firecrawl.dev/v2"
})
req.url  // "https://api.firecrawl.dev/v2/scrape"
req.body  // "{\"url\":\"https://example.com\"}"

collect-pages

fn (page: Map, fetch: Fn): Map
fn (page: Map, fetch: Fn, base-url: Str): Map

Follow next from a crawl or batch-scrape status page, calling fetch(path) for each further page, and return the latest page's status fields with data holding every page's documents. Stops on the last page, on a running job's repeated empty cursor (keeping next so you can resume), or on an Err from fetch (returned). base-url (default the v2 base URL) is the only root it follows. Exposed for testing.

Example

pages {"/crawl/abc?skip=1": {status: "completed", data: [{n: 2}]}}
page-one {status: "scraping", data: [{n: 1}], next: "https://api.firecrawl.dev/v2/crawl/abc?skip=1"}
out ::firecrawl::api/collect-pages(page-one, (path) { get(pages, path) })
out.status  // "completed"
out.data  // [{n: 1}, {n: 2}]

error-message

fn (status: Int, body: Any): Str

Readable text for a failed response: Firecrawl's error (or message) field when present, prefixed with the HTTP status. Exposed for testing.

Example

::firecrawl::api/error-message(402, {success: false, error: "Insufficient credits"})  // "Firecrawl API error 402: Insufficient credits"
::firecrawl::api/error-message(500, null)  // "Firecrawl API error 500"

get-all-pages

fn (path: Str, opts: Map): Map

GET a status path and follow next across the pages, with the credentials and API root from opts.

Example

::api ::firecrawl::api

job ::api/get-all-pages(::api/job-path("crawl", "0b5e6c1a-3d2f-4a7e-9c11-2f8a6d4b7e90"), {})
length(job.data)

is-terminal

fn (status: Any): Bool

True for a job status that will not change again: "completed", "failed", or "cancelled". Exposed for testing.

Example

::firecrawl::api/is-terminal("completed")  // true
::firecrawl::api/is-terminal("scraping")  // false

job-path

fn (kind: Str, id: Str): Str
fn (kind: Str, id: Str, suffix: Str): Str

/<kind>/<id> with the id URL-encoded, plus an optional suffix (e.g. "/errors"). Exposed for testing.

Example

::firecrawl::api/job-path("crawl", "abc")  // "/crawl/abc"
::firecrawl::api/job-path("batch/scrape", "abc", "/errors")  // "/batch/scrape/abc/errors"

next-path

fn (next: Any): Any
fn (next: Any, base-url: Str): Any

The path to request for a status response's next URL, relative to base-url (default the v2 base URL), or null when there is no next page. A next that points anywhere other than that API root is never followed, so the API key is only ever sent there. Exposed for testing.

Example

::firecrawl::api/next-path("https://api.firecrawl.dev/v2/crawl/abc?skip=10")  // "/crawl/abc?skip=10"
::firecrawl::api/next-path("https://other.example/crawl/abc")  // null

request

fn (method: Str, path: Str, body: Any): Any
fn (method: Str, path: Str, body: Any, api-key: Str?): Any
fn (method: Str, path: Str, body: Any, opts: Map): Any

Make an authenticated Firecrawl request. path is relative to the v2 base URL; pass "" as body for requests without one. Returns the decoded JSON body on 2xx, an Err carrying HttpError otherwise, or the transport Err.

Example

body ::firecrawl::api/request("POST", "/scrape", {url: "https://example.com", formats: ["markdown"]})
body.data.markdown

// Act for another tenant, with its key from context
::firecrawl::api/request("GET", "/crawl/active", "", {api-key: ::hot::ctx/get("tenant.firecrawl.key")})

resolve

fn (opts: Map): Map

Credentials and settings for one call (see resolve-from). An api-key from opts is masked in this run's records and never written to ctx.

Example

::firecrawl::api/resolve({api-key: "fc-tenant-b"}).base-url  // "https://api.firecrawl.dev/v2"
Context Vars: firecrawl.api.key

resolve-from

fn (opts: Map, ctx-values: Map): Map

The one resolver, pure: {api-key, base-url} for a call from opts first, then ctx-values (a Map of context variables), then defaults. An Err when no API key is set, when api-key is in opts but blank or null (that never falls back to context), or when opts has base-url without api-key. Exposed for testing; resolve feeds it the context.

Example

::api ::firecrawl::api

::api/resolve-from({}, {"firecrawl.api.key": "ctx-key"}).api-key  // "ctx-key"
::api/resolve-from({api-key: "tenant-key"}, {}).base-url  // "https://api.firecrawl.dev/v2"

Types

HttpError

HttpError type {
    status: Int,
    message: Str,
    headers: Map,
    body: Any
}

A non-2xx Firecrawl response. message is readable text built from Firecrawl's {success: false, error, code?} body; the raw body is kept in body.