> ## Documentation Index
> Fetch the complete documentation index at: https://firecrawl-claude-eager-dijkstra-gyth0o.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust Agent Quickstart

> Canonical Firecrawl Rust quickstart for external agents using search, scrape, and interact.

# Firecrawl Rust Agent Quickstart

This file is the canonical quickstart for external agents integrating with Firecrawl via the Rust SDK. It is generated from SDK source and the OpenAPI spec.

## Install

Add to your `Cargo.toml`:

```toml theme={null}
[dependencies]
firecrawl = "2"
tokio = { version = "1", features = ["full"] }
```

## Authenticate

```rust theme={null}
use firecrawl::Client;

// Cloud client with API key
let client = Client::new("fc-YOUR-API-KEY")?;

// Self-hosted client (API key optional)
let client = Client::new_selfhosted("https://your-instance.com", Some("fc-YOUR-API-KEY"))?;
```

| Constructor                                | Description                                                  |
| ------------------------------------------ | ------------------------------------------------------------ |
| `Client::new(api_key)`                     | Cloud client. API key required.                              |
| `Client::new_selfhosted(api_url, api_key)` | Self-hosted client. API key is optional (keyless free tier). |

## When To Use What

* **`search`**: Use when you start with a query and need to discover relevant pages across the web.
* **`scrape`**: Use when you already have a URL and want to extract page content (markdown, HTML, structured data, etc.).
* **`interact`**: Use when the page needs clicks, form fills, or post-scrape browser actions via code or natural language.

## Search

### Why use it

Search finds relevant web pages for a query. Optionally scrapes each result in the same call via `scrape_options`.

### Preferred SDK method

```
client.search(query, options).await
```

### Example

```rust theme={null}
use firecrawl::{Client, SearchOptions};

let client = Client::new("fc-YOUR-API-KEY")?;

let response = client.search("firecrawl web scraping", SearchOptions {
    limit: Some(5),
    ..Default::default()
}).await?;

if let Some(web_results) = response.data.web {
    for result in web_results {
        println!("{:?}", result);
    }
}
```

### Parameters

All fields on `SearchOptions` are `Option`, defaulting to `None`.

| Parameter             | Type                          | Description                                                     |
| --------------------- | ----------------------------- | --------------------------------------------------------------- |
| `query`               | `impl AsRef<str>`             | Required (first positional arg). The search query.              |
| `limit`               | `Option<u32>`                 | Max results (default 5, max 20).                                |
| `sources`             | `Option<Vec<SearchSource>>`   | Result verticals: `Web`, `News`, `Images`.                      |
| `categories`          | `Option<Vec<SearchCategory>>` | Narrow search: `Github`, `Research`, `Pdf`.                     |
| `include_domains`     | `Option<Vec<String>>`         | Only return results from these domains.                         |
| `exclude_domains`     | `Option<Vec<String>>`         | Exclude results from these domains.                             |
| `tbs`                 | `Option<String>`              | Time-based search filter (e.g. `"qdr:d"`).                      |
| `location`            | `Option<String>`              | Geo-location string.                                            |
| `country`             | `Option<String>`              | Country code for geo-targeting.                                 |
| `ignore_invalid_urls` | `Option<bool>`                | Skip invalid URLs.                                              |
| `timeout`             | `Option<u32>`                 | Timeout in milliseconds.                                        |
| `highlights`          | `Option<bool>`                | Include query-relevant highlights. Default: `true` server-side. |
| `scrape_options`      | `Option<ScrapeOptions>`       | Scrape each result with these options.                          |
| `integration`         | `Option<String>`              | Integration identifier.                                         |
| `origin`              | `Option<String>`              | Auto-set to `"rust-sdk@{version}"`.                             |

**Returns:** `SearchResponse { success, data: SearchData, warning }` where `SearchData` has `web`, `news`, `images` fields.

**Convenience:** `client.search_and_scrape(query, limit).await` searches and returns only scraped `Document` results.

## Scrape

### Why use it

Scrape extracts content from a single URL in any format: markdown, HTML, structured JSON, screenshots, and more.

### Preferred SDK method

```
client.scrape(url, options).await
```

### Example

```rust theme={null}
use firecrawl::{Client, ScrapeOptions, Format};

let client = Client::new("fc-YOUR-API-KEY")?;

let doc = client.scrape("https://example.com", ScrapeOptions {
    formats: Some(vec![Format::Markdown, Format::Links]),
    ..Default::default()
}).await?;

println!("{}", doc.markdown.unwrap_or_default());
```

### Parameters

All fields on `ScrapeOptions` are `Option`, defaulting to `None`.

| Parameter                 | Type                              | Description                                                                                                                                                                                                             |
| ------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`                     | `impl AsRef<str>`                 | Required (first positional arg). The URL to scrape.                                                                                                                                                                     |
| `formats`                 | `Option<Vec<Format>>`             | Output formats: `Markdown`, `Html`, `RawHtml`, `Links`, `Images`, `Screenshot`, `Summary`, `ChangeTracking`, `Json`, `Attributes`, `Branding`, `Product`, `Menu`, `Audio`, `Video`, `Question(...)`, `Highlights(...)`. |
| `headers`                 | `Option<HashMap<String, String>>` | Custom HTTP headers.                                                                                                                                                                                                    |
| `include_tags`            | `Option<Vec<String>>`             | CSS selectors to include.                                                                                                                                                                                               |
| `exclude_tags`            | `Option<Vec<String>>`             | CSS selectors to exclude.                                                                                                                                                                                               |
| `only_main_content`       | `Option<bool>`                    | Strip navbars, footers, etc.                                                                                                                                                                                            |
| `timeout`                 | `Option<u32>`                     | Timeout in milliseconds.                                                                                                                                                                                                |
| `wait_for`                | `Option<u32>`                     | Wait after page load in milliseconds.                                                                                                                                                                                   |
| `mobile`                  | `Option<bool>`                    | Emulate mobile device.                                                                                                                                                                                                  |
| `parsers`                 | `Option<Vec<ParserConfig>>`       | Document parsers (e.g. PDF config).                                                                                                                                                                                     |
| `actions`                 | `Option<Vec<Action>>`             | Browser actions: `Wait`, `Screenshot`, `Click`, `Write`, `Press`, `Scroll`, `Scrape`, `ExecuteJavascript`, `Pdf`.                                                                                                       |
| `location`                | `Option<LocationConfig>`          | Geo-location with `country` and `languages`.                                                                                                                                                                            |
| `skip_tls_verification`   | `Option<bool>`                    | Skip TLS checks.                                                                                                                                                                                                        |
| `remove_base64_images`    | `Option<bool>`                    | Strip base64 images.                                                                                                                                                                                                    |
| `fast_mode`               | `Option<bool>`                    | Fast scraping (no JS rendering).                                                                                                                                                                                        |
| `block_ads`               | `Option<bool>`                    | Block ads.                                                                                                                                                                                                              |
| `proxy`                   | `Option<ProxyType>`               | Proxy: `Basic`, `Stealth`, `Enhanced`, `Auto`.                                                                                                                                                                          |
| `max_age`                 | `Option<u32>`                     | Cache max age in seconds.                                                                                                                                                                                               |
| `min_age`                 | `Option<u32>`                     | Cache min age in seconds.                                                                                                                                                                                               |
| `store_in_cache`          | `Option<bool>`                    | Store result in cache.                                                                                                                                                                                                  |
| `lockdown`                | `Option<bool>`                    | Cache-only mode.                                                                                                                                                                                                        |
| `redact_pii`              | `Option<bool>`                    | Redact PII from output.                                                                                                                                                                                                 |
| `audit_metadata`          | `Option<AuditMetadata>`           | Audit metadata.                                                                                                                                                                                                         |
| `profile`                 | `Option<ProfileConfig>`           | Browser profile (`name`, `save_changes`).                                                                                                                                                                               |
| `integration`             | `Option<String>`                  | Integration identifier.                                                                                                                                                                                                 |
| `json_options`            | `Option<JsonOptions>`             | JSON extraction config (`schema`, `system_prompt`, `prompt`).                                                                                                                                                           |
| `screenshot_options`      | `Option<ScreenshotOptions>`       | Screenshot config (`full_page`, `quality`, `viewport`).                                                                                                                                                                 |
| `change_tracking_options` | `Option<ChangeTrackingOptions>`   | Change tracking config.                                                                                                                                                                                                 |
| `attribute_selectors`     | `Option<Vec<AttributeSelector>>`  | Attribute extraction selectors.                                                                                                                                                                                         |
| `origin`                  | `Option<String>`                  | Auto-set to `"rust-sdk@{version}"`.                                                                                                                                                                                     |

**Returns:** `Document` with `markdown`, `html`, `raw_html`, `json`, `summary`, `metadata`, `links`, `images`, `screenshot`, `audio`, `video`, `actions`, `warning`, `change_tracking`, `branding`, `product`, `menu`, `pages`, `blocks`.

**Convenience:** `client.scrape_with_schema(url, schema, prompt).await` scrapes with JSON extraction and returns the extracted value.

## Interact

### Why use it

Interact lets you execute code or natural-language instructions in a browser session that was started by a scrape. Use it for post-scrape actions like clicking buttons, filling forms, or extracting dynamic content.

### Preferred SDK method

```
client.interact(job_id, options).await
```

### Example

```rust theme={null}
use firecrawl::{Client, ScrapeExecuteOptions, ScrapeExecuteLanguage};

let client = Client::new("fc-YOUR-API-KEY")?;

let result = client.interact("job-id-from-scrape", ScrapeExecuteOptions {
    code: Some("console.log(await page.url())".to_string()),
    language: Some(ScrapeExecuteLanguage::Node),
    timeout: Some(60),
    ..Default::default()
}).await?;

println!("{:?}", result.stdout);

// Stop the session when done
client.stop_interaction("job-id-from-scrape").await?;
```

### Parameters

| Parameter  | Type                            | Description                                                                     |
| ---------- | ------------------------------- | ------------------------------------------------------------------------------- |
| `job_id`   | `impl AsRef<str>`               | Required. The scrape job ID.                                                    |
| `code`     | `Option<String>`                | Code to execute in the browser sandbox. Provide `code` or `prompt`.             |
| `prompt`   | `Option<String>`                | Natural-language instruction for the browser agent. Provide `code` or `prompt`. |
| `language` | `Option<ScrapeExecuteLanguage>` | Runtime: `Python`, `Node`, `Bash`. Default: `Node`.                             |
| `timeout`  | `Option<u32>`                   | Execution timeout in seconds.                                                   |
| `origin`   | `Option<String>`                | Auto-set to `"rust-sdk@{version}"`.                                             |

**Returns:** `ScrapeExecuteResponse` with `success`, `output`, `stdout`, `result`, `stderr`, `exit_code`, `killed`, `error`, `live_view_url`, `interactive_live_view_url`.

**Related:** `client.stop_interaction(job_id).await` ends the browser session and returns `session_duration_ms` and `credits_billed`.

## Notes

* All struct fields use **snake\_case** (e.g. `only_main_content`, `skip_tls_verification`). The SDK handles serde serialization to camelCase for the API.
* All option structs derive `Default`, so use `..Default::default()` for omitted fields.
* **Deprecated aliases** (use the preferred names instead):
  * `scrape_execute()` → `interact()`
  * `stop_interactive_browser()` → `stop_interaction()`
  * `delete_scrape_browser()` → `stop_interaction()`
* The SDK is fully async (requires `tokio` runtime).
* `origin` is auto-injected as `"rust-sdk@{version}"` on every request.

## Source Of Truth

* `firecrawl/apps/rust-sdk/src/scrape.rs`
* `firecrawl/apps/rust-sdk/src/search.rs`
* `firecrawl/apps/rust-sdk/src/client.rs`
* `firecrawl-docs/api-reference/v2-openapi.json`
