Installation#
The official PHP SDK is maintained in the Firecrawl monorepo at apps/php-sdk.
To install the Firecrawl PHP SDK, add the dependency via Composer:
Laravel Integration#
The SDK includes first-class Laravel support with auto-discovery. After installing the package, publish the configuration file:
Then add your API key to your .env file:
The following environment variables are supported:
| Variable | Default | Description |
|---|---|---|
FIRECRAWL_API_KEY | — | Your Firecrawl API key (required) |
FIRECRAWL_API_URL | https://api.firecrawl.dev | API base URL |
FIRECRAWL_TIMEOUT | 300 | HTTP request timeout in seconds |
FIRECRAWL_MAX_RETRIES | 3 | Automatic retries for transient failures |
FIRECRAWL_BACKOFF_FACTOR | 0.5 | Exponential backoff factor in seconds |
Usage#
- Get an API key from firecrawl.dev
- Set the API key as an environment variable named
FIRECRAWL_API_KEY, or pass it withFirecrawlClient::create(apiKey: ...)
Here is a quick example using the current SDK API surface:
Using the Laravel Facade#
In a Laravel application you can use the Firecrawl facade or dependency injection:
Scraping a URL#
To scrape a single URL, use the scrape method.
JSON Extraction#
Extract structured JSON with JsonFormat via the scrape endpoint:
Crawling a Website#
To crawl a website and wait for completion, use crawl.
Start a Crawl#
Start a job without waiting using startCrawl.
Checking Crawl Status#
Check crawl progress with getCrawlStatus.
Cancelling a Crawl#
Cancel a running crawl with cancelCrawl.
Crawl Errors#
Fetch crawl-level errors (if any) with getCrawlErrors.
Mapping a Website#
Discover links on a site using map.
Searching the Web#
Search with optional search settings using search.
Batch Scraping#
Scrape multiple URLs in parallel using batchScrape.
For manual async control, use startBatchScrape, getBatchScrapeStatus, and cancelBatchScrape:
Agent#
Run an AI-powered agent with agent.
With a JSON schema for structured output:
For manual async control, use startAgent, getAgentStatus, and cancelAgent:
Usage & Metrics#
Check concurrency and remaining credits:
Laravel AI SDK Tools#
The SDK ships native tool classes for the Laravel AI SDK (laravel/ai), so agents can scrape, search, map, and crawl the web without an MCP server or manual HTTP calls.
firecrawl/firecrawl-sdk 1.9.0 or later, plus laravel/ai 0.9 or later (PHP 8.3+, Laravel 12+). The tool classes only load when laravel/ai is installed.The tools resolve the FirecrawlClient from the container, so your existing config/firecrawl.php and FIRECRAWL_API_KEY setup is reused as is:
Available Tools#
| Class | Tool name | What it does |
|---|---|---|
FirecrawlScrape | firecrawl_scrape | Scrape one URL and return clean markdown |
FirecrawlSearch | firecrawl_search | Search the web, returns JSON results |
FirecrawlMap | firecrawl_map | Discover the URLs on a website |
FirecrawlCrawl | firecrawl_crawl | Crawl multiple pages into markdown |
The tool names match the Firecrawl MCP server, so agents see the same vocabulary across surfaces. Register all four at once with the spread helper:
Every tool also accepts an explicit client, for one off credentials or use outside the container. FirecrawlTools::all() passes one to all four tools:
Tool Parameters#
Each tool exposes a small, model-facing schema. These are the parameters the agent can pass:
| Tool | Parameter | Description |
|---|---|---|
firecrawl_scrape | url (required) | Absolute URL of the page to scrape, including the scheme |
firecrawl_search | query (required) | The search query |
limit | Maximum results to return, 1–20. Defaults to 5 | |
firecrawl_map | url (required) | Base URL of the website to map |
search | Optional term to filter discovered URLs by relevance | |
limit | Maximum URLs to return, 1–500. Defaults to 100 | |
firecrawl_crawl | url (required) | URL to start crawling from |
limit | Maximum pages to crawl, 1–25. Defaults to 5 |
Out-of-range limit values are clamped to the nearest bound rather than rejected, so a model that asks for 99 search results gets 20 instead of an error.
Tool Behavior#
Tool failures such as rate limits, timeouts, and invalid URLs are returned to the model as readable error strings rather than thrown, so agent runs degrade gracefully. Outputs are capped to stay within model context: scrape results truncate at 80,000 characters, crawl pages at 15,000 characters each under a 100,000 character whole result budget, and search and map results drop tail items with an explicit omitted marker.
firecrawl_search and firecrawl_map return JSON arrays of results. firecrawl_scrape returns the page as markdown.
Crawl Results#
firecrawl_crawl waits up to 55 seconds for the crawl to finish, then returns a JSON object that makes the outcome explicit. Failed, cancelled, or partial crawls stay visible to the model through the status field rather than being silently truncated:
Two optional fields appear when results don't fit: omittedPages counts pages dropped to stay inside the output budget, and note tells the model that more pages exist on the server and that it should use a smaller limit or scrape specific pages with firecrawl_scrape. The tool reports pagination instead of following it, so agents that need every page of a large crawl should use FirecrawlClient directly.
If the crawl is still running when the wait expires, the tool says so and reminds the model the crawl may still complete server-side. Crawl starts carry a UUID idempotency key, so an HTTP-level retry never creates a duplicate crawl.
If your agent runs inside a queued job, keep the crawl limit small or raise the worker's job timeout. The wait, poll cadence, and per-page cap are protected properties, so extend the class to tune them:
Browser#
The PHP SDK includes Browser Sandbox helpers.
Create a Session#
Execute Code#
Scrape-Bound Interactive Session#
Use a scrape job ID to run follow-up browser code in the same replayed context:
interact(...)runs code in the scrape-bound browser session (and initializes it on first use).stopInteractiveBrowser(...)explicitly stops the interactive session when you are done.
List & Close Sessions#
Configuration#
FirecrawlClient::create() supports the following options:
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | FIRECRAWL_API_KEY env var | Your Firecrawl API key |
apiUrl | string | https://api.firecrawl.dev (or FIRECRAWL_API_URL) | API base URL |
timeoutSeconds | float | 300 | HTTP request timeout in seconds |
maxRetries | int | 3 | Automatic retries for transient failures |
backoffFactor | float | 0.5 | Exponential backoff factor in seconds |
httpClient | GuzzleHttp\ClientInterface | Built from timeout | Custom Guzzle-compatible HTTP client |
Custom HTTP Client#
You can pass a pre-configured GuzzleHttp\ClientInterface implementation to control connection pooling, middleware, proxy settings, and other HTTP features. When provided, the timeoutSeconds setting is ignored in favor of the client's own configuration.
Error Handling#
The SDK throws runtime exceptions under Firecrawl\Exceptions.
Are you an AI agent that needs a Firecrawl API key? See firecrawl.dev/agent-onboarding/SKILL.md for automated onboarding instructions.

