diff --git a/agent-quickstart/elixir.mdx b/agent-quickstart/elixir.mdx new file mode 100644 index 000000000..8ca4473ca --- /dev/null +++ b/agent-quickstart/elixir.mdx @@ -0,0 +1,194 @@ +--- +title: "Elixir Agent Quickstart" +description: "Canonical Firecrawl Elixir quickstart for external agents using search, scrape, and interact." +--- + +# Firecrawl Elixir Agent Quickstart + +Canonical quickstart for external agents. Generated from SDK source (`:firecrawl` **1.9.2**, `firecrawl/apps/elixir-sdk`) and the v2 OpenAPI spec. Function names and parameter keys are generated from the OpenAPI spec. + +## Install + +Add to `mix.exs`: + +```elixir +{:firecrawl, "~> 1.4"} +``` + +## Authenticate + +```elixir +# config/runtime.exs or config.exs +config :firecrawl, api_key: System.get_env("FIRECRAWL_API_KEY") + +# Or pass api_key per call: +{:ok, res} = Firecrawl.scrape_and_extract_from_url( + [url: "https://example.com"], + api_key: "fc-your-api-key" +) +``` + +There is no client struct. Configuration is resolved per-call from Application config or per-call opts. + +## When To Use What + +- `search`: use when you start with a query and need discovery. +- `scrape`: use when you already have a URL and want page content. +- `interact`: use when the page needs clicks, forms, or post-scrape browser actions. + +## Search + +### Why use it + +Discover relevant pages from a query, then pick URLs to scrape or interact with. Constrain results to a site with `site:`, e.g. `site:docs.firecrawl.dev crawl webhooks`. + +### Preferred SDK method + +`Firecrawl.search_and_scrape(params \\ [], opts \\ [])` + +### Example + +```elixir +{:ok, res} = Firecrawl.search_and_scrape( + query: "site:docs.firecrawl.dev webhook retries", + sources: [:web], + limit: 5, + scrape_options: [ + formats: ["markdown"], + only_main_content: true + ] +) +``` + +A bang variant `search_and_scrape!/2` is also available — it raises on error instead of returning `{:error, _}`. + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `query` | `string` | Search query (required). Use `site:example.com` to limit to a domain. | +| `sources` | `list` | Sources: `:web`, `:news`, `:images` (atoms or strings). | +| `categories` | `list` | Categories: `:github`, `:research`, `:pdf` (atoms or strings). | +| `include_domains` | `list(string)` | Restrict results to these domains. | +| `exclude_domains` | `list(string)` | Exclude these domains. | +| `limit` | `integer` | Max results. | +| `tbs` | `string` | Time-based filter (e.g. `qdr:d`, `qdr:w`). | +| `location` | `string` | Location for localized results. | +| `country` | `string` | ISO 3166-1 alpha-2 code (e.g. `"US"`). | +| `ignore_invalid_urls` | `boolean` | Drop invalid URLs. | +| `timeout` | `integer` | Timeout in milliseconds. | +| `highlights` | `boolean` | Generate query-relevant highlights. Default: `true`. | +| `enterprise` | `list(string)` | Enterprise options: `["zdr"]` for zero data retention, `["anon"]` for anonymized. | +| `scrape_options` | `keyword list` | Scrape each result (see Scrape parameters). | + +## Scrape + +### Why use it + +Use scrape when you already have a URL and want structured content in one or more formats. + +### Preferred SDK method + +`Firecrawl.scrape_and_extract_from_url(params \\ [], opts \\ [])` + +### Example + +```elixir +{:ok, res} = Firecrawl.scrape_and_extract_from_url( + url: "https://example.com/pricing", + formats: [ + "markdown", + "links", + %{type: "json", prompt: "Extract plan names and prices."} + ], + only_main_content: true, + wait_for: 1000 +) +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `url` | `string` | Target URL (required). | +| `formats` | `list` | Output formats. Strings: `"markdown"`, `"html"`, `"rawHtml"`, `"links"`, `"images"`, `"screenshot"`, `"summary"`, `"changeTracking"`, `"json"`, `"branding"`, `"audio"`, `"video"`. Maps: `%{type: "json", prompt: ...}`, `%{type: "screenshot", fullPage: true}`, etc. | +| `headers` | `map` | Custom HTTP headers. | +| `include_tags` | `list(string)` | Only include these HTML tags. | +| `exclude_tags` | `list(string)` | Exclude these HTML tags. | +| `only_main_content` | `boolean` | Strip nav, footer, and boilerplate. | +| `timeout` | `integer` | Timeout in milliseconds. Default: 60000. | +| `wait_for` | `integer` | Wait for page to render (milliseconds). | +| `mobile` | `boolean` | Mobile viewport. | +| `parsers` | `list` | Parser controls. E.g. `[%{type: "pdf", mode: "auto", maxPages: 5}]`. | +| `actions` | `list(map)` | Pre-scrape browser actions. Types: `wait`, `click`, `write`, `press`, `scroll`, `scrape`, `executeJavascript`, `screenshot`, `pdf`. | +| `location` | `keyword list` | Geo/language-aware scraping. E.g. `[country: "US", languages: ["en-US"]]`. | +| `skip_tls_verification` | `boolean` | Skip TLS verification. | +| `remove_base64_images` | `boolean` | Drop base64 images from markdown. | +| `block_ads` | `boolean` | Block ads and cookie popups. | +| `proxy` | `atom` | Proxy control: `:basic`, `:enhanced`, `:auto`. | +| `max_age` | `integer` | Cached data up to this age (milliseconds). | +| `min_age` | `integer` | Cached data only if at least this old (milliseconds). | +| `store_in_cache` | `boolean` | Cache the result. | +| `lockdown` | `boolean` | Only serve previously cached results. | +| `redact_pii` | `boolean` | Redact PII from output. | +| `profile` | `keyword list` | Persistent browser profile. E.g. `[name: "session", save_changes: true]`. | +| `zero_data_retention` | `boolean` | Enable zero data retention. | + +## Interact + +### Why use it + +Use interact when a page requires browser actions or code execution after a scrape starts. + +### Preferred SDK method + +`Firecrawl.interact_with_scrape_browser_session(job_id, params \\ [], opts \\ [])` + +### Example + +```elixir +{:ok, scrape_res} = Firecrawl.scrape_and_extract_from_url( + url: "https://example.com", + formats: ["markdown"] +) +job_id = get_in(scrape_res.body, ["data", "metadata", "scrapeId"]) + +{:ok, res} = Firecrawl.interact_with_scrape_browser_session( + job_id, + code: "console.log(await page.title());", + language: :node, + timeout: 60 +) +``` + +To end the session: + +```elixir +{:ok, _} = Firecrawl.stop_interactive_scrape_browser_session(job_id) +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `job_id` | `string` | Scrape job ID (first positional argument). | +| `code` | `string` | Code to run in the browser session (required). | +| `language` | `atom` | Runtime: `:python`, `:node`, `:bash`. | +| `timeout` | `integer` | Execution timeout in seconds. | + +The Elixir SDK exposes code-based interactions only — there is no `prompt` parameter (unlike JS/TS, Python, and Rust SDKs). + +## Notes + +- The Elixir SDK is auto-generated from the OpenAPI spec. Function names match the spec operations. +- Each function has a bang (`!`) variant that raises on error instead of returning `{:error, _}`. +- Parameters use `snake_case` in Elixir and are auto-converted to `camelCase` for the JSON body. +- OpenAPI enum values are represented as Elixir atoms (e.g. `proxy: :basic`, `language: :node`). +- No client struct — configuration via Application config or per-call opts. +- Uses the `Req` HTTP library. Extra opts are passed through to `Req`. + +## Source Of Truth + +- `firecrawl/apps/elixir-sdk/mix.exs` +- `firecrawl/apps/elixir-sdk/lib/firecrawl.ex` +- `firecrawl-docs/api-reference/v2-openapi.json` diff --git a/agent-quickstart/java.mdx b/agent-quickstart/java.mdx new file mode 100644 index 000000000..57e17ea85 --- /dev/null +++ b/agent-quickstart/java.mdx @@ -0,0 +1,221 @@ +--- +title: "Java Agent Quickstart" +description: "Canonical Firecrawl Java quickstart for external agents using search, scrape, and interact." +--- + +# Firecrawl Java Agent Quickstart + +Canonical quickstart for external agents. Generated from SDK source (`firecrawl-java` **1.15.0**, `firecrawl/apps/java-sdk`) and the v2 OpenAPI spec. + +## Install + +Maven: + +```xml + + com.firecrawl + firecrawl-java + 1.15.0 + +``` + +Gradle: + +```gradle +implementation("com.firecrawl:firecrawl-java:1.15.0") +``` + +Requires Java 11+. + +## Authenticate + +```java +import com.firecrawl.client.FirecrawlClient; + +FirecrawlClient client = FirecrawlClient.builder() + .apiKey(System.getenv("FIRECRAWL_API_KEY")) + .build(); + +// Or from environment (reads FIRECRAWL_API_KEY env var or firecrawl.apiKey system property): +// FirecrawlClient client = FirecrawlClient.fromEnv(); +``` + +## When To Use What + +- `search`: use when you start with a query and need discovery. +- `scrape`: use when you already have a URL and want page content. +- `interact`: use when the page needs clicks, forms, or post-scrape browser actions. + +## Search + +### Why use it + +Discover relevant pages from a query, then pick URLs to scrape or interact with. Constrain results to a site with `site:`, e.g. `site:docs.firecrawl.dev crawl webhooks`. + +### Preferred SDK method + +- `client.search(query)` → `SearchData` +- `client.search(query, options)` → `SearchData` + +### Example + +```java +import com.firecrawl.models.SearchOptions; +import com.firecrawl.models.ScrapeOptions; +import com.firecrawl.models.SearchData; +import java.util.List; +import java.util.Map; + +SearchOptions options = SearchOptions.builder() + .sources(List.of("web")) + .limit(5) + .scrapeOptions( + ScrapeOptions.builder() + .formats(List.of("markdown")) + .onlyMainContent(true) + .build() + ) + .build(); + +SearchData results = client.search("site:docs.firecrawl.dev webhook retries", options); +List> web = results.getWeb(); +``` + +Read result buckets with `getWeb()`, `getNews()`, `getImages()` (each is `List>` and may be null). Do not treat `SearchData` as a directly iterable list. + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `query` | `String` | Search query. Use `site:example.com` to limit to a domain. | +| `options.sources` | `List` | Sources: `"web"`, `"news"`, `"images"`. | +| `options.categories` | `List` | Categories: `"github"`, `"research"`, `"pdf"`. | +| `options.includeDomains` | `List` | Restrict results to these domains. | +| `options.excludeDomains` | `List` | Exclude these domains. | +| `options.limit` | `Integer` | Max results. | +| `options.tbs` | `String` | Time-based filter (e.g. `qdr:d`, `qdr:w`). | +| `options.location` | `String` | Location for localized results. | +| `options.ignoreInvalidURLs` | `Boolean` | Drop invalid URLs. | +| `options.timeout` | `Integer` | Timeout in milliseconds. | +| `options.highlights` | `Boolean` | Generate query-relevant highlights. Default: `true`. | +| `options.scrapeOptions` | `ScrapeOptions` | Scrape each result (see Scrape parameters). | + +## Scrape + +### Why use it + +Use scrape when you already have a URL and want structured content in one or more formats. + +### Preferred SDK method + +- `client.scrape(url)` → `Document` +- `client.scrape(url, options)` → `Document` + +### Example + +```java +import com.firecrawl.models.ScrapeOptions; +import com.firecrawl.models.JsonFormat; +import com.firecrawl.models.Document; + +ScrapeOptions options = ScrapeOptions.builder() + .formats(List.of( + "markdown", + "links", + JsonFormat.builder().prompt("Extract plan names and prices.").build() + )) + .onlyMainContent(true) + .waitFor(1000) + .build(); + +Document doc = client.scrape("https://example.com/pricing", options); +System.out.println(doc.getMarkdown()); +System.out.println(doc.getJson()); +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `url` | `String` | Target URL to scrape. | +| `options.formats` | `List` | Output formats. Strings: `"markdown"`, `"html"`, `"rawHtml"`, `"links"`, `"images"`, `"screenshot"`, `"summary"`, `"changeTracking"`, `"json"`, `"attributes"`, `"branding"`, `"audio"`, `"video"`. Objects: `JsonFormat`, `QuestionFormat`, `HighlightsFormat`, or maps for screenshot/changeTracking/attributes. | +| `options.headers` | `Map` | Custom HTTP headers. | +| `options.includeTags` | `List` | Only include these HTML tags. | +| `options.excludeTags` | `List` | Exclude these HTML tags. | +| `options.onlyMainContent` | `Boolean` | Strip nav, footer, and boilerplate. | +| `options.timeout` | `Integer` | Timeout in milliseconds. | +| `options.waitFor` | `Integer` | Wait for page to render (milliseconds). | +| `options.mobile` | `Boolean` | Mobile viewport. | +| `options.parsers` | `List` | Parser controls. E.g. `List.of(Map.of("type", "pdf", "maxPages", 5))`. | +| `options.actions` | `List>` | Pre-scrape browser actions. Types: `wait`, `click`, `write`, `press`, `scroll`, `scrape`, `executeJavascript`, `screenshot`, `pdf`. | +| `options.location` | `LocationConfig` | Geo/language-aware scraping. `.country(String)`, `.languages(List)`. | +| `options.skipTlsVerification` | `Boolean` | Skip TLS verification. | +| `options.removeBase64Images` | `Boolean` | Drop base64 images from markdown. | +| `options.blockAds` | `Boolean` | Block ads and cookie popups. | +| `options.proxy` | `String` | Proxy control: `"basic"`, `"stealth"`, `"enhanced"`, `"auto"`, or custom URL. | +| `options.maxAge` | `Long` | Cached data up to this age (milliseconds). | +| `options.storeInCache` | `Boolean` | Cache the result. | +| `options.lockdown` | `Boolean` | Only serve previously cached results. | +| `options.redactPII` | `Boolean` | Redact PII from output. | + +## Interact + +### Why use it + +Use interact when a page requires browser actions or code execution after a scrape starts. + +### Preferred SDK method + +- `client.interact(jobId, code)` — language defaults to `"node"` +- `client.interact(jobId, code, language, timeout)` — `timeout` is seconds (1-300) +- `client.interact(jobId, code, language, timeout, origin)` — optional origin for attribution + +### Example + +```java +import com.firecrawl.models.BrowserExecuteResponse; + +Document doc = client.scrape("https://example.com", + ScrapeOptions.builder().formats(List.of("markdown")).build()); +String jobId = (String) doc.getMetadata().get("scrapeId"); + +BrowserExecuteResponse result = client.interact( + jobId, + "console.log(await page.title());", + "node", + 60 +); + +System.out.println(result.getStdout()); +``` + +To end the session: `client.stopInteractiveBrowser(jobId);` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `jobId` | `String` | Scrape job ID from `doc.getMetadata().get("scrapeId")`. | +| `code` | `String` | Code to run in the browser session. | +| `language` | `String` | Runtime: `"python"`, `"node"`, `"bash"`. Default: `"node"`. | +| `timeout` | `Integer` | Execution timeout in seconds (1-300). Null uses API default (30). | + +The Java SDK exposes code-based interactions only — there is no `prompt` parameter (unlike JS/TS, Python, and Rust SDKs). + +## Notes + +- Deprecated aliases: `scrapeExecute` → `interact`, `deleteScrapeBrowser` → `stopInteractiveBrowser`. +- All option classes use the Builder pattern: `ScrapeOptions.builder()...build()`. +- `formats` is `List` to allow mixing strings and typed format objects. +- `SearchData` result maps are untyped (`List>`). +- Errors are unchecked exceptions: `AuthenticationException` (401), `RateLimitException` (429), `FirecrawlException` (other). +- Automatic retry with exponential backoff on 408, 409, 5xx, and IOException. + +## Source Of Truth + +- `firecrawl/apps/java-sdk/build.gradle.kts` +- `firecrawl/apps/java-sdk/src/main/java/com/firecrawl/client/FirecrawlClient.java` +- `firecrawl/apps/java-sdk/src/main/java/com/firecrawl/models/ScrapeOptions.java` +- `firecrawl/apps/java-sdk/src/main/java/com/firecrawl/models/SearchOptions.java` +- `firecrawl/apps/java-sdk/src/main/java/com/firecrawl/models/SearchData.java` +- `firecrawl-docs/api-reference/v2-openapi.json` diff --git a/agent-quickstart/node.mdx b/agent-quickstart/node.mdx new file mode 100644 index 000000000..73e3ad247 --- /dev/null +++ b/agent-quickstart/node.mdx @@ -0,0 +1,196 @@ +--- +title: "Node.js Agent Quickstart" +description: "Canonical Firecrawl Node.js quickstart for external agents using search, scrape, and interact." +--- + +# Firecrawl Node.js Agent Quickstart + +Canonical quickstart for external agents. Generated from SDK source (`firecrawl` **4.35.0**, `firecrawl/apps/js-sdk/firecrawl`) and the v2 OpenAPI spec. Method names, parameters, and types match the SDK public API. + +## Install + +```bash +npm install firecrawl +``` + +Requires Node.js >= 22. + +## Authenticate + +```ts +import { Firecrawl } from "firecrawl"; + +const client = new Firecrawl({ + apiKey: process.env.FIRECRAWL_API_KEY, + // apiUrl: "https://api.firecrawl.dev" // optional; falls back to FIRECRAWL_API_URL env or cloud default +}); +``` + +## When To Use What + +- `search`: use when you start with a query and need discovery. +- `scrape`: use when you already have a URL and want page content. +- `interact`: use when the page needs clicks, forms, or other browser actions after a scrape has created a session. + +## Search + +### Why use it + +Discover relevant pages from a query, then pick URLs to scrape or interact with. Constrain results to a site with `site:`, e.g. `site:docs.firecrawl.dev crawl webhooks`. + +### Preferred SDK method + +`client.search(query, options?)` → `Promise` + +### Example + +```ts +const results = await client.search("site:docs.firecrawl.dev webhook retries", { + sources: ["web"], + limit: 5, + scrapeOptions: { + formats: ["markdown"], + onlyMainContent: true, + }, +}); + +for (const item of results.web ?? []) { + console.log(item.url, item.title); +} +``` + +**Wrong turn to avoid:** `search()` does not return `{ data: [...] }`. Do not access `result.data`. Web results are in `result.web`, news in `result.news`, images in `result.images`. + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `query` | `string` | Search query. Use `site:example.com` to limit to a domain. | +| `options.sources` | `("web" \| "news" \| "images")[]` | Which result sources to include. | +| `options.categories` | `("github" \| "research" \| "pdf" \| "developer")[]` | Narrow results by category. | +| `options.includeDomains` | `string[]` | Restrict results to these domains. Mutually exclusive with `excludeDomains`. | +| `options.excludeDomains` | `string[]` | Exclude these domains. Mutually exclusive with `includeDomains`. | +| `options.limit` | `number` | Max results to return. | +| `options.tbs` | `string` | Time-based filter (e.g. `qdr:d` for past day, `qdr:w` for past week). | +| `options.location` | `string` | Location string for localized results. | +| `options.ignoreInvalidURLs` | `boolean` | Drop URLs that cannot be scraped. | +| `options.timeout` | `number` | Request timeout in milliseconds. | +| `options.highlights` | `boolean` | Generate query-relevant highlights. Default: `true`. | +| `options.scrapeOptions` | `ScrapeOptions` | Scrape each search result with these options (see Scrape parameters). | + +## Scrape + +### Why use it + +Use scrape when you already have a URL and want structured content in one or more formats. + +### Preferred SDK method + +`client.scrape(url, options?)` → `Promise` + +### Example + +```ts +const doc = await client.scrape("https://example.com/pricing", { + formats: [ + "markdown", + "links", + { type: "json", prompt: "Extract plan names and prices." }, + ], + onlyMainContent: true, + waitFor: 1000, +}); + +console.log(doc.markdown); +console.log(doc.json); +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `url` | `string` | Target URL to scrape. | +| `options.formats` | `FormatOption[]` | Output formats. Strings: `"markdown"`, `"html"`, `"rawHtml"`, `"links"`, `"images"`, `"screenshot"`, `"summary"`, `"changeTracking"`, `"attributes"`, `"branding"`, `"audio"`, `"video"`. Objects: `{ type: "json", prompt?, schema? }`, `{ type: "question", question }`, `{ type: "highlights", query }`, `{ type: "screenshot", fullPage?, quality?, viewport? }`, `{ type: "changeTracking", modes, schema?, prompt?, tag? }`, `{ type: "attributes", selectors: [{ selector, attribute }] }`. Note: plain string `"json"` is rejected — use an object. | +| `options.headers` | `Record` | Custom HTTP headers. | +| `options.includeTags` | `string[]` | Only include these HTML tags. | +| `options.excludeTags` | `string[]` | Exclude these HTML tags. | +| `options.onlyMainContent` | `boolean` | Strip nav, footer, and boilerplate. | +| `options.timeout` | `number` | Timeout in milliseconds. | +| `options.waitFor` | `number` | Wait for the page to render (milliseconds). | +| `options.mobile` | `boolean` | Use a mobile viewport. | +| `options.parsers` | `(string \| PDFParser)[]` | Parser controls. E.g. `["pdf"]` or `[{ type: "pdf", mode: "auto", maxPages: 5 }]`. | +| `options.actions` | `ActionOption[]` | Pre-scrape browser actions. Types: `wait`, `click`, `write`, `press`, `scroll`, `scrape`, `executeJavascript`, `screenshot`, `pdf`. | +| `options.location` | `{ country?: string; languages?: string[] }` | Geo/language-aware scraping. | +| `options.skipTlsVerification` | `boolean` | Skip TLS verification. | +| `options.removeBase64Images` | `boolean` | Drop base64 images from markdown. | +| `options.fastMode` | `boolean` | Faster scrapes with reduced fidelity. | +| `options.blockAds` | `boolean` | Block ads and cookie popups. | +| `options.proxy` | `"basic" \| "stealth" \| "enhanced" \| "auto" \| string` | Proxy control. | +| `options.maxAge` | `number` | Cached data up to this age (milliseconds). `0` bypasses cache. | +| `options.minAge` | `number` | Cached data only if at least this old (milliseconds). | +| `options.storeInCache` | `boolean` | Cache the result. | +| `options.lockdown` | `boolean` | Only serve previously cached results. | +| `options.profile` | `{ name: string; saveChanges?: boolean }` | Persistent browser profile shared across scrapes and interactions. | + +## Interact + +### Why use it + +Use `interact` for code or natural-language control of the browser session tied to a scrape job (via `metadata.scrapeId`). The SDK requires at least one of `code` or `prompt`. + +### Preferred SDK method + +`client.interact(jobId, args)` → `Promise` + +### Example + +```ts +const doc = await client.scrape("https://example.com", { formats: ["markdown"] }); +const jobId = doc.metadata?.scrapeId; +if (!jobId) throw new Error("Missing scrapeId from scrape response"); + +const result = await client.interact(jobId, { + prompt: "Click the pricing tab and summarize the plans.", +}); + +console.log(result.output); +``` + +To run code directly: + +```ts +const result = await client.interact(jobId, { + code: "console.log(await page.title());", + language: "node", + timeout: 60, +}); +``` + +To end the session: `await client.stopInteraction(jobId);` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `jobId` | `string` | Scrape job ID from `document.metadata.scrapeId`. | +| `args.code` | `string` | Code to run in the browser session (Playwright `page` is available in `node` runtime). | +| `args.prompt` | `string` | Natural-language instruction for the browser agent. | +| `args.language` | `"python" \| "node" \| "bash"` | Runtime language. Default: `"node"`. | +| `args.timeout` | `number` | Execution timeout in seconds. | + +At least one of `code` or `prompt` must be non-empty. + +## Notes + +- Deprecated aliases: `scrapeExecute` → `interact`; `stopInteractiveBrowser` and `deleteScrapeBrowser` → `stopInteraction`. +- The default `Firecrawl` export is the v2 client; v1 remains under `client.v1`. +- Zod schemas passed in `formats` (for `json` or `changeTracking`) are converted to JSON Schema by the SDK. +- The SDK adds 5000ms to user-specified `timeout` values for the HTTP transport layer. + +## Source Of Truth + +- `firecrawl/apps/js-sdk/firecrawl/package.json` +- `firecrawl/apps/js-sdk/firecrawl/src/index.ts` +- `firecrawl/apps/js-sdk/firecrawl/src/v2/client.ts` +- `firecrawl/apps/js-sdk/firecrawl/src/v2/types.ts` +- `firecrawl-docs/api-reference/v2-openapi.json` diff --git a/agent-quickstart/python.mdx b/agent-quickstart/python.mdx new file mode 100644 index 000000000..10b6bffab --- /dev/null +++ b/agent-quickstart/python.mdx @@ -0,0 +1,197 @@ +--- +title: "Python Agent Quickstart" +description: "Canonical Firecrawl Python quickstart for external agents using search, scrape, and interact." +--- + +# Firecrawl Python Agent Quickstart + +Canonical quickstart for external agents. Generated from SDK source (`firecrawl-py` **4.38.0**, `firecrawl/apps/python-sdk`) and the v2 OpenAPI spec. Method names, parameters, and return types match the v2 client in `firecrawl/v2/client.py`. + +## Install + +```bash +pip install firecrawl-py +``` + +Requires Python >= 3.8. + +## Authenticate + +```py +import os +from firecrawl import Firecrawl + +client = Firecrawl(api_key=os.environ.get("FIRECRAWL_API_KEY")) +# client = Firecrawl(api_key="fc-...", api_url="https://api.firecrawl.dev") +``` + +## When To Use What + +- `search`: use when you start with a query and need discovery. +- `scrape`: use when you already have a URL and want page content. +- `interact`: use when the page needs clicks, forms, or post-scrape browser actions. + +## Search + +### Why use it + +Discover relevant pages from a query, then pick URLs to scrape or interact with. Constrain results to a site with `site:`, e.g. `site:docs.firecrawl.dev crawl webhooks`. + +### Preferred SDK method + +`client.search(query, **options)` → `SearchData` + +### Example + +```py +results = client.search( + "site:docs.firecrawl.dev webhook retries", + sources=["web"], + limit=5, + scrape_options=ScrapeOptions( + formats=["markdown"], + only_main_content=True, + ), +) + +for item in results.web or []: + print(getattr(item, "url", None), getattr(item, "title", None)) +``` + +**Wrong turn to avoid:** `search()` does not return `{ data: [...] }`. Do not access `result.data`. Web results are in `result.web`, news in `result.news`, images in `result.images`. + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `query` | `str` | Search query. Use `site:example.com` to limit to a domain. | +| `sources` | `list` | Source types: `"web"`, `"news"`, `"images"`. | +| `categories` | `list` | Category filters: `"github"`, `"research"`, `"pdf"`, `"developer"`. | +| `include_domains` | `list[str]` | Restrict results to these domains. Mutually exclusive with `exclude_domains`. | +| `exclude_domains` | `list[str]` | Exclude these domains. Mutually exclusive with `include_domains`. | +| `limit` | `int` | Max results. Default: `5`. | +| `tbs` | `str` | Time-based filter (e.g. `qdr:d`, `qdr:w`). | +| `location` | `str` | Location string for localized results. | +| `ignore_invalid_urls` | `bool` | Drop invalid URLs. | +| `timeout` | `int` | Request timeout in milliseconds. Default: `300000`. | +| `highlights` | `bool` | Generate query-relevant highlights. Default: `True`. | +| `scrape_options` | `ScrapeOptions` | Scrape each result with these options (see Scrape parameters). | + +## Scrape + +### Why use it + +Use scrape when you already have a URL and want structured content in one or more formats. + +### Preferred SDK method + +`client.scrape(url, **options)` → `Document` + +### Example + +```py +doc = client.scrape( + "https://example.com/pricing", + formats=[ + "markdown", + "links", + {"type": "json", "prompt": "Extract plan names and prices."}, + ], + only_main_content=True, + wait_for=1000, +) + +print(doc.markdown) +print(doc.json) +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `url` | `str` | Target URL to scrape. | +| `formats` | `list` | Output formats. Strings: `"markdown"`, `"html"`, `"rawHtml"` (or `"raw_html"`), `"links"`, `"images"`, `"screenshot"`, `"summary"`, `"changeTracking"` (or `"change_tracking"`), `"attributes"`, `"branding"`, `"audio"`, `"video"`. Objects: `{"type": "json", "prompt": ..., "schema": ...}`, `{"type": "question", "question": ...}`, `{"type": "highlights", "query": ...}`. Note: plain string `"json"` should not be used — use an object. | +| `headers` | `dict[str, str]` | Custom HTTP headers. | +| `include_tags` | `list[str]` | Only include these HTML tags. | +| `exclude_tags` | `list[str]` | Exclude these HTML tags. | +| `only_main_content` | `bool` | Strip nav, footer, and boilerplate. | +| `timeout` | `int` | Timeout in milliseconds. | +| `wait_for` | `int` | Wait for page to render (milliseconds). | +| `mobile` | `bool` | Mobile viewport. | +| `parsers` | `list` | Parser controls. E.g. `["pdf"]` or `[{"type": "pdf", "mode": "auto", "max_pages": 5}]`. | +| `actions` | `list[dict]` | Pre-scrape browser actions. Types: `wait`, `click`, `write`, `press`, `scroll`, `scrape`, `executeJavascript`, `screenshot`, `pdf`. | +| `location` | `dict` | Geo/language-aware scraping. `{"country": "US", "languages": ["en-US"]}`. | +| `skip_tls_verification` | `bool` | Skip TLS verification. | +| `remove_base64_images` | `bool` | Drop base64 images from markdown. | +| `fast_mode` | `bool` | Faster scrapes with reduced fidelity. | +| `block_ads` | `bool` | Block ads and cookie popups. | +| `proxy` | `str` | Proxy control: `"basic"`, `"stealth"`, `"enhanced"`, `"auto"`. | +| `max_age` | `int` | Cached data up to this age (milliseconds). | +| `min_age` | `int` | Cached data only if at least this old (milliseconds). | +| `store_in_cache` | `bool` | Cache the result. | +| `lockdown` | `bool` | Only serve previously cached results. | +| `profile` | `dict` | Persistent browser profile. `{"name": "session", "save_changes": True}`. | + +## Interact + +### Why use it + +Use `interact` for code or natural-language control of the browser session tied to a scrape job. The SDK requires at least one of `code` or `prompt`. + +### Preferred SDK method + +`client.interact(job_id, code=None, *, prompt=None, language="node", timeout=None)` + +`prompt` is keyword-only. + +### Example + +```py +doc = client.scrape("https://example.com", formats=["markdown"]) +job_id = doc.metadata.scrape_id if doc.metadata else None +if not job_id: + raise RuntimeError("Missing scrape_id from scrape response") + +result = client.interact(job_id, prompt="Click the pricing tab and summarize the plans.") +print(result.output) +``` + +To run code directly: + +```py +result = client.interact( + job_id, + code="print(await page.title())", + language="python", + timeout=60, +) +``` + +To end the session: `client.stop_interaction(job_id)` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `job_id` | `str` | Scrape job ID from `document.metadata.scrape_id`. | +| `code` | `str` | Code to run in the browser session (optional if `prompt` is set). | +| `prompt` | `str` | Natural-language instruction (keyword-only, optional if `code` is set). | +| `language` | `str` | Runtime: `"python"`, `"node"`, `"bash"`. Default: `"node"`. | +| `timeout` | `int` | Execution timeout in seconds. | + +At least one of `code` or `prompt` must be non-empty. + +## Notes + +- Deprecated aliases: `scrape_execute` → `interact`; `stop_interactive_browser` and `delete_scrape_browser` → `stop_interaction`. `FirecrawlApp` → `Firecrawl`. +- The top-level `Firecrawl` client exposes v2 methods directly; v1 remains under `client.v1`. +- Both `snake_case` and `camelCase` parameter names are accepted by the SDK's Pydantic models (`populate_by_name=True`). +- `search` location is a plain `str`; `scrape` location is a `dict` with `country` and `languages`. They are not interchangeable. + +## Source Of Truth + +- `firecrawl/apps/python-sdk/pyproject.toml` +- `firecrawl/apps/python-sdk/firecrawl/client.py` +- `firecrawl/apps/python-sdk/firecrawl/v2/client.py` +- `firecrawl/apps/python-sdk/firecrawl/v2/types.py` +- `firecrawl-docs/api-reference/v2-openapi.json` diff --git a/agent-quickstart/rust.mdx b/agent-quickstart/rust.mdx new file mode 100644 index 000000000..29a584da4 --- /dev/null +++ b/agent-quickstart/rust.mdx @@ -0,0 +1,235 @@ +--- +title: "Rust Agent Quickstart" +description: "Canonical Firecrawl Rust quickstart for external agents using search, scrape, and interact." +--- + +# Firecrawl Rust Agent Quickstart + +Canonical quickstart for external agents. Generated from SDK source (`firecrawl` crate **2.16.0**, `firecrawl/apps/rust-sdk`) and the v2 OpenAPI spec. + +## Install + +```toml +[dependencies] +firecrawl = "2.16.0" +``` + +All types are re-exported at the crate root: `use firecrawl::Client;`, `use firecrawl::ScrapeOptions;`, etc. + +## Authenticate + +```rust +use firecrawl::Client; + +let client = Client::new("fc-your-api-key")?; +// Self-hosted: +// let client = Client::new_selfhosted("http://localhost:3002", Some("fc-your-api-key"))?; +``` + +## When To Use What + +- `search`: use when you start with a query and need discovery. +- `scrape`: use when you already have a URL and want page content. +- `interact`: use when the page needs clicks, forms, or post-scrape browser actions. + +## Search + +### Why use it + +Discover relevant pages from a query, then pick URLs to scrape or interact with. Constrain results to a site with `site:`, e.g. `site:docs.firecrawl.dev crawl webhooks`. + +### Preferred SDK method + +`client.search(query, options)` → `Result` + +### Example + +```rust +use firecrawl::{Client, SearchOptions, ScrapeOptions, Format}; + +let results = client + .search("site:docs.firecrawl.dev webhook retries", SearchOptions { + sources: Some(vec![SearchSource::Web]), + limit: Some(5), + scrape_options: Some(ScrapeOptions { + formats: Some(vec![Format::Markdown]), + only_main_content: Some(true), + ..Default::default() + }), + ..Default::default() + }) + .await?; + +if let Some(web) = results.data.web { + for item in web { + // item is SearchResultOrDocument::WebResult or ::Document + } +} +``` + +Results are in `result.data.web`, `result.data.news`, `result.data.images`. + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `query` | `impl AsRef` | Search query. Use `site:example.com` to limit to a domain. | +| `options.sources` | `Vec` | Sources: `Web`, `News`, `Images`. | +| `options.categories` | `Vec` | Categories: `Github`, `Research`, `Pdf`. | +| `options.include_domains` | `Vec` | Restrict results to these domains. | +| `options.exclude_domains` | `Vec` | Exclude these domains. | +| `options.limit` | `u32` | Max results. | +| `options.tbs` | `String` | Time-based filter (e.g. `qdr:d`, `qdr:w`). | +| `options.location` | `String` | Location for localized results. | +| `options.ignore_invalid_urls` | `bool` | Drop invalid URLs. | +| `options.timeout` | `u32` | Request timeout in milliseconds. | +| `options.highlights` | `bool` | Generate query-relevant highlights. Default: `true`. | +| `options.scrape_options` | `ScrapeOptions` | Scrape each result (see Scrape parameters). | + +### Convenience method + +`client.search_and_scrape(query, limit)` → `Result, FirecrawlError>` — searches with default scrape options and returns only `Document` entries from `data.web`. + +## Scrape + +### Why use it + +Use scrape when you already have a URL and want structured content in one or more formats. + +### Preferred SDK method + +`client.scrape(url, options)` → `Result` + +### Example + +```rust +use firecrawl::{Client, ScrapeOptions, Format, JsonOptions}; + +let doc = client + .scrape("https://example.com/pricing", ScrapeOptions { + formats: Some(vec![Format::Markdown, Format::Links, Format::Json]), + json_options: Some(JsonOptions { + prompt: Some("Extract plan names and prices.".to_string()), + ..Default::default() + }), + only_main_content: Some(true), + wait_for: Some(1000), + ..Default::default() + }) + .await?; +``` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `url` | `impl AsRef` | Target URL to scrape. | +| `options.formats` | `Vec` | Output formats: `Markdown`, `Html`, `RawHtml`, `Links`, `Images`, `Screenshot`, `Summary`, `ChangeTracking`, `Json`, `Attributes`, `Branding`, `Product`, `Menu`, `Audio`, `Video`, `Question(QuestionFormat)`, `Highlights(HighlightsFormat)`. | +| `options.headers` | `HashMap` | Custom HTTP headers. | +| `options.include_tags` | `Vec` | Only include these HTML tags. | +| `options.exclude_tags` | `Vec` | Exclude these HTML tags. | +| `options.only_main_content` | `bool` | Strip nav, footer, and boilerplate. | +| `options.timeout` | `u32` | Timeout in milliseconds. | +| `options.wait_for` | `u32` | Wait for page to render (milliseconds). | +| `options.mobile` | `bool` | Mobile viewport. | +| `options.parsers` | `Vec` | Parser controls. E.g. `ParserConfig::Pdf { parser_type: "pdf", max_pages: Some(5) }`. | +| `options.actions` | `Vec` | Pre-scrape browser actions: `Wait`, `Click`, `Write`, `Press`, `Scroll`, `Scrape`, `ExecuteJavascript`, `Screenshot`, `Pdf`. | +| `options.location` | `LocationConfig` | Geo/language-aware scraping. Fields: `country`, `languages`. | +| `options.skip_tls_verification` | `bool` | Skip TLS verification. | +| `options.remove_base64_images` | `bool` | Drop base64 images from markdown. | +| `options.fast_mode` | `bool` | Faster scrapes with reduced fidelity. | +| `options.block_ads` | `bool` | Block ads and cookie popups. | +| `options.proxy` | `ProxyType` | Proxy control: `Basic`, `Stealth`, `Enhanced`, `Auto`. | +| `options.max_age` | `u32` | Cached data up to this age (milliseconds). | +| `options.min_age` | `u32` | Cached data only if at least this old (milliseconds). | +| `options.store_in_cache` | `bool` | Cache the result. | +| `options.lockdown` | `bool` | Only serve previously cached results. | +| `options.redact_pii` | `bool` | Redact PII from output. | +| `options.profile` | `ProfileConfig` | Persistent browser profile. Fields: `name`, `save_changes`. | +| `options.json_options` | `JsonOptions` | JSON extraction options. Fields: `schema`, `system_prompt`, `prompt`. | +| `options.screenshot_options` | `ScreenshotOptions` | Screenshot config. Fields: `full_page`, `quality`, `viewport`. | +| `options.change_tracking_options` | `ChangeTrackingOptions` | Change tracking. Fields: `modes` (`GitDiff`, `Json`), `schema`, `prompt`, `tag`. | +| `options.attribute_selectors` | `Vec` | Attribute extraction. Fields: `selector`, `attribute`. | + +### Convenience method + +`client.scrape_with_schema(url, schema, prompt)` → `Result` — sets `formats: [Json]` and returns the extracted JSON directly. + +## Interact + +### Why use it + +Use `interact` for code or natural-language control of the browser session tied to a scrape job. At least one of `code` or `prompt` must be provided. + +### Preferred SDK method + +`client.interact(job_id, options)` → `Result` + +### Example + +```rust +use firecrawl::{Client, ScrapeOptions, Format, ScrapeExecuteOptions}; + +let doc = client + .scrape("https://example.com", ScrapeOptions { + formats: Some(vec![Format::Markdown]), + ..Default::default() + }) + .await?; + +let job_id = doc.metadata + .as_ref() + .and_then(|m| m.scrape_id.as_deref()) + .expect("Missing scrapeId"); + +let result = client + .interact(job_id, ScrapeExecuteOptions { + prompt: Some("Click the pricing tab and summarize the plans.".to_string()), + ..Default::default() + }) + .await?; +``` + +To run code: + +```rust +let result = client + .interact(job_id, ScrapeExecuteOptions { + code: Some("console.log(await page.title());".to_string()), + language: Some(ScrapeExecuteLanguage::Node), + timeout: Some(60), + ..Default::default() + }) + .await?; +``` + +To end the session: `client.stop_interaction(job_id).await?;` + +### Parameters + +| Parameter | Type | Description | +|---|---|---| +| `job_id` | `impl AsRef` | Scrape job ID. | +| `options.code` | `Option` | Code to run in the browser session (optional if `prompt` is set). | +| `options.prompt` | `Option` | Natural-language instruction (optional if `code` is set). | +| `options.language` | `ScrapeExecuteLanguage` | Runtime: `Python`, `Node`, `Bash`. Default: `Node`. | +| `options.timeout` | `u32` | Execution timeout in seconds. | + +At least one of `code` or `prompt` must be non-empty; otherwise `FirecrawlError::Misuse` is returned. + +## Notes + +- Deprecated aliases: `scrape_execute` → `interact`; `stop_interactive_browser` and `delete_scrape_browser` → `stop_interaction`. +- All option structs derive `Default`, enabling the `..Default::default()` pattern. +- `impl Into>` on `scrape`/`search` means you can pass `None`, `Some(options)`, or the options struct directly. +- All methods are `async` and require a Tokio runtime. +- `#[serde(rename_all = "camelCase")]` is used for JSON serialization; `redact_pii` is explicitly renamed to `"redactPII"`. + +## Source Of Truth + +- `firecrawl/apps/rust-sdk/Cargo.toml` +- `firecrawl/apps/rust-sdk/src/lib.rs` +- `firecrawl/apps/rust-sdk/src/client.rs` +- `firecrawl/apps/rust-sdk/src/scrape.rs` +- `firecrawl/apps/rust-sdk/src/search.rs` +- `firecrawl-docs/api-reference/v2-openapi.json`