快速开始(2/3)
doc = firecrawl.scrape('https://example.com', formats=['markdown'], location={ 'country': 'US', 'languages': ['en'] } )
print(doc)
```js
import { Firecrawl } from 'firecrawl';
const firecrawl = new Firecrawl({
// No API key needed to get started — add one for higher rate limits:
// apiKey: "fc-YOUR-API-KEY",
});
const doc = await firecrawl.scrape('https://example.com', {
formats: ['markdown'],
location: { country: 'US', languages: ['en'] },
});
console.log(doc.metadata);
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
curl -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"formats": ["markdown"],
"location": { "country": "US", "languages": ["en"] }
}'
For more details about supported locations, refer to the Proxies documentation.
Caching and maxAge
To make requests faster, Firecrawl serves results from cache by default when a recent copy is available.
- Default freshness window:
maxAge = 172800000ms (2 days). If a cached page is newer than this, it’s returned instantly; otherwise, the page is scraped and then cached. - Performance: This can speed up scrapes by up to 5x when data doesn’t need to be ultra-fresh.
- Always fetch fresh: Set
maxAgeto0. Note that this bypasses the cache entirely, so every request goes through the full scraping pipeline, meaning that the request will take longer to complete and is more likely to fail. Use a non-zeromaxAgeif freshness on every request is not critical. - Avoid storing: Set
storeInCachetofalseif you don’t want Firecrawl to cache/store results for this request. - Cache-only lookup: Set
minAgeto perform a cache-only lookup without triggering a fresh scrape. The value is in milliseconds and specifies the minimum age the cached data must be. If no cached data is found, a404with error codeSCRAPE_NO_CACHED_DATAis returned. SetminAgeto1to accept any cached data regardless of age. - Change tracking: Requests that include
changeTrackingbypass the cache, somaxAgeis ignored. - Credits: Cached results still cost 1 credit per page. Caching improves speed, not credit usage.
Example (force fresh content):
from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key='fc-YOUR_API_KEY')
doc = firecrawl.scrape(url='https://example.com', max_age=0, formats=['markdown'])
print(doc)
import { Firecrawl } from 'firecrawl';
const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });
const doc = await firecrawl.scrape('https://example.com', { maxAge: 0, formats: ['markdown'] });
console.log(doc);
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"maxAge": 0,
"formats": ["markdown"]
}'
Example (use a 10-minute cache window):
from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key='fc-YOUR_API_KEY')
doc = firecrawl.scrape(url='https://example.com', max_age=600000, formats=['markdown', 'html'])
print(doc)
const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });
const doc = await firecrawl.scrape('https://example.com', { maxAge: 600000, formats: ['markdown', 'html'] });
console.log(doc);
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"maxAge": 600000,
"formats": ["markdown", "html"]
}'
Freshness and item status
maxAge controls whether Firecrawl may return a cached copy; it does not tell you whether the state represented by a page is current. When freshness matters, use maxAge: 0 to skip the cache, then inspect the returned content and any redirect or source-specific status signals. A successful response alone is not proof of current state.
See Verifying Freshness and Liveness for a checklist and examples.
Alexandria data tools
Scrape can also run a data tool from Alexandria, the Firecrawl catalogue of third-party data providers. Send an alexandria object with provider, capability, and options instead of a url. Get these values from Search or Find Tools.
result = firecrawl.scrape(
alexandria={
"provider": "particle",
"capability": "podcasts/episodes/search",
"options": {"semantic_search": "AI agents", "limit": 2},
},
)
print(result.alexandria[0].data)
const result = await firecrawl.scrape({
alexandria: {
provider: "particle",
capability: "podcasts/episodes/search",
options: { semantic_search: "AI agents", limit: 2 },
},
});
console.log(result.alexandria[0].data);
curl -X POST https://api.firecrawl.dev/v2/scrape \
-H "Content-Type: application/json" \
-H "Authorization: Bearer fc-YOUR_API_KEY" \
-d '{
"alexandria": {
"provider": "particle",
"capability": "podcasts/episodes/search",
"options": { "semantic_search": "AI agents", "limit": 2 }
}
}'
- The response has one item for each call in
data.alexandria. Each item hasdataor anerror. Examine each item, because one call can fail when the request succeeds. - Send an array of up to 10 calls to run them in one request. You cannot use
alexandriatogether withurlor other scrape options. - Each call costs the price listed on its tool.
data.creditsCostshows the total. - To retry, send the same
x-request-idheader with the same body. A completed request replays its result and does not run again. Without this header, a retry is a new charge. - Some providers need an org admin to accept their terms first. Then the request fails with
THIRD_PARTY_DATA_TERMS_REQUIRED.
To find tools for the page that you scrape, add domainTools: true to an ordinary URL scrape. Matching tools come back in data.tools. See Alexandria for pricing and access.
Batch scraping multiple URLs
You can now batch scrape multiple URLs at the same time. It takes the starting URLs and optional parameters as arguments. The params argument allows you to specify additional options for the batch scrape job, such as the output formats.
How it works
It is very similar to how the /crawl endpoint works. It submits a batch scrape job and returns a job ID to check the status of the batch scrape.
The sdk provides 2 methods, synchronous and asynchronous. The synchronous method will return the results of the batch scrape job, while the asynchronous method will return a job ID that you can use to check the status of the batch scrape.
Usage
from firecrawl import Firecrawl
firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")
job = firecrawl.batch_scrape([
"https://firecrawl.dev",
"https://docs.firecrawl.dev",
], formats=["markdown"], poll_interval=2, wait_timeout=120)
print(job)
import { Firecrawl } from 'firecrawl';
const firecrawl = new Firecrawl({ apiKey: "fc-YOUR-API-KEY" });
const job = await firecrawl.batchScrape([
'https://firecrawl.dev',
'https://docs.firecrawl.dev',
], { options: { formats: ['markdown'] }, pollInterval: 2, timeout: 120 });
console.log(job);
curl -s -X POST "https://api.firecrawl.dev/v2/batch/scrape" \
-H "Authorization: Bearer $FIRECRAWL_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"urls": ["https://firecrawl.dev", "https://docs.firecrawl.dev"],
"formats": ["markdown"]
}'
Response
If you’re using the sync methods from the SDKs, it will return the results of the batch scrape job. Otherwise, it will return a job ID that you can use to check the status of the batch scrape.
Synchronous
{
"status": "completed",
"total": 36,
"completed": 36,
"creditsUsed": 36,
"expiresAt": "2024-00-00T00:00:00.000Z",
"next": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789?skip=26",
"data": [
{
"markdown": "[Firecrawl Docs home page!...",
"html": "<!DOCTYPE html><html lang=\"en\" class=\"js-focus-visible lg:[--scroll-mt:9.5rem]\" data-js-focus-visible=\"\">...",
"metadata": {
"title": "Build a 'Chat with website' using Groq Llama 3 | Firecrawl",
"language": "en",
"sourceURL": "https://docs.firecrawl.dev/learn/rag-llama3",
"description": "Learn how to use Firecrawl, Groq Llama 3, and Langchain to build a 'Chat with your website' bot.",
"ogLocaleAlternate": [],
"statusCode": 200
}
},
...
]
}
Asynchronous
You can then use the job ID to check the status of the batch scrape by calling the /batch/scrape/{id} endpoint. This endpoint is meant to be used while the job is still running or right after it has completed as batch scrape jobs expire after 24 hours.
{
"success": true,
"id": "123-456-789",
"url": "https://api.firecrawl.dev/v2/batch/scrape/123-456-789"
}
Enhanced Mode
For complex websites, Firecrawl offers enhanced mode that provides better success rates while maintaining privacy.
Learn more about Enhanced Mode.
Zero Data Retention (ZDR)
Firecrawl supports Zero Data Retention (ZDR) for teams with strict data handling requirements. When enabled, Firecrawl will not persist any page content or extracted data beyond the lifetime of the request.
To enable ZDR, set zeroDataRetention: true in your request:
curl -X POST https://api.firecrawl.dev/v2/scrape \
-H "Content-Type: application/json" \
-H "Authorization: Bearer fc-YOUR_API_KEY" \
-d '{
"url": "https://example.com",
"formats": ["markdown"],
"zeroDataRetention": true
}'
ZDR is available on Enterprise plans and must be enabled for your team. Visit firecrawl.dev/enterprise to get started.
ZDR adds 1 additional credit per page on top of the base scrape cost.
Screenshots are not available in ZDR mode. Because screenshots require uploading to persistent storage, they are incompatible with the ZDR guarantee. Requests that include both zeroDataRetention: true and a screenshot format will return an error.
Are you an AI agent that needs a Firecrawl API key? See firecrawl.dev/agent-onboarding/SKILL.md for automated onboarding instructions.
The web data API for AI agents. Search the web, scrape any page, and interact with it through one API.
Firecrawl is the web data API for AI agents. Search, scrape, and interact with the live web to get clean Markdown or structured data.
Get started
Connect over Streamable HTTP. The keyless server URL (Search, Scrape, and Parse; no credential required) is https://mcp.firecrawl.dev/v2/mcp.
- Codex CLI:
codex mcp add firecrawl --url https://mcp.firecrawl.dev/v2/mcp - Claude Code:
claude mcp add --transport http firecrawl https://mcp.firecrawl.dev/v2/mcp - Cursor or any JSON-config client:
{"mcpServers": {"firecrawl": {"url": "https://mcp.firecrawl.dev/v2/mcp"}}} - OpenCode (
opencode.json):{"mcp": {"firecrawl": {"type": "remote", "url": "https://mcp.firecrawl.dev/v2/mcp", "enabled": true}}} - ChatGPT or Claude.ai: use the native Firecrawl connector — ChatGPT or Claude.
Both setup paths and API-key setup: MCP Get Started, For Agents, and For Humans.
Build directly with the API
Scrape your first page now. No account or API key is required for this request.
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://firecrawl.dev",
"formats": ["markdown", "html"]
}'
Add an API key when you need higher limits. See the Python SDK, Node SDK, or API reference to build it into your application.
Other ways to get started
Install the Firecrawl CLI
One command installs the Firecrawl CLI, authenticates in your browser, and adds skills to every detected coding agent.
npx -y firecrawl-cli@latest init --all --browser
Restart your coding agent after setup so it can discover the new skills. See CLI for the full setup.
Set up with an agent
Provide your agent with this Firecrawl setup prompt, or see all MCP setup options.
For AI agents: Use llms.txt for an index of the documentation, or llms-full.txt for the full text.
Build and test directly
Create a free account for direct API access and higher limits
Test Firecrawl in the browser without writing code
What can Firecrawl do?
Search the web and get full page content from results
Extract content from any URL as markdown, HTML, or structured JSON
Continue working with any scraped page: click, fill forms, extract dynamic
content
Why Firecrawl?
- LLM-ready output: Clean markdown, structured JSON, screenshots, and more.
- Handles the hard stuff: Proxies, anti-bot, JavaScript rendering, and dynamic content.
- Reliable: Built for production with high uptime and consistent results.
- Fast: Results in seconds, optimized for high throughput.
- MCP Server: Connect Firecrawl to any AI tool via the Model Context Protocol.
To qualify, complete a high-signal interview (thoughtful, concrete use cases, etc) with our Firecrawl Feedback Assistant. Only takes a few minutes, can be stopped at any time, and is both human/agent-friendly (just paste the link into your agentic harness!). Haven't used Alexandria yet? Your take still counts.
[https://www.firecrawl.dev/survey/uilpn?src=docs-alexandria]( Start the interview )Include your email to be eligible. Interviews are reviewed for quality at the end of each week.
Search
Search the web and get full page content from results in one call. See the Search feature docs for all options.
from firecrawl import Firecrawl
firecrawl = Firecrawl(
# No API key needed to get started — add one for higher rate limits:
# api_key="fc-YOUR-API-KEY",
)
results = firecrawl.search(
query="firecrawl",
limit=3,
)
print(results)
import { Firecrawl } from 'firecrawl';
const firecrawl = new Firecrawl({
// No API key needed to get started — add one for higher rate limits:
// apiKey: "fc-YOUR-API-KEY",
});
const results = await firecrawl.search('firecrawl', {
limit: 3,
scrapeOptions: { formats: ['markdown'] }
});
console.log(results);
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
curl -s -X POST "https://api.firecrawl.dev/v2/search" \
-H "Content-Type: application/json" \
-d '{
"query": "firecrawl",
"limit": 3
}'
# Search the web
firecrawl search "firecrawl web scraping" --limit 5 --pretty
SDKs will return the data object directly. cURL will return the complete payload.
{
"success": true,
"data": {
"web": [
{
"url": "https://www.firecrawl.dev/",
"title": "Firecrawl - The Web Data API for AI",
"description": "The web crawling, scraping, and search API for AI. Built for scale. Firecrawl delivers the entire internet to AI agents and builders.",
"position": 1
},
{
"url": "https://github.com/firecrawl/firecrawl",
"title": "mendableai/firecrawl: Turn entire websites into LLM-ready ... - GitHub",
"description": "Firecrawl is an API service that takes a URL, crawls it, and converts it into clean markdown or structured data.",
"position": 2
},
...
],
"images": [
{
"title": "Quickstart | Firecrawl",
"imageUrl": "https://mintlify.s3.us-west-1.amazonaws.com/firecrawl/logo/logo.png",
"imageWidth": 5814,
"imageHeight": 1200,
"url": "https://docs.firecrawl.dev/",
"position": 1
},
...
],
"news": [
{
"title": "Y Combinator startup Firecrawl is ready to pay $1M to hire three AI agents as employees",
"url": "https://techcrunch.com/2025/05/17/y-combinator-startup-firecrawl-is-ready-to-pay-1m-to-hire-three-ai-agents-as-employees/",
"snippet": "It's now placed three new ads on YC's job board for “AI agents only” and has set aside a $1 million budget total to make it happen.",
"date": "3 months ago",
"position": 1
},
...
]
}
}
Scrape
Scrape any URL and get its content in markdown, HTML, or other formats. See the Scrape feature docs for all options.
from firecrawl import Firecrawl
firecrawl = Firecrawl(
# No API key needed to get started — add one for higher rate limits:
# api_key="fc-YOUR-API-KEY",
)
# Scrape a website:
doc = firecrawl.scrape("https://firecrawl.dev", formats=["markdown", "html"])
print(doc)
import { Firecrawl } from 'firecrawl';
const firecrawl = new Firecrawl({
// No API key needed to get started — add one for higher rate limits:
// apiKey: "fc-YOUR-API-KEY",
});
// Scrape a website:
const doc = await firecrawl.scrape('https://firecrawl.dev', { formats: ['markdown', 'html'] });
console.log(doc);
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Content-Type: application/json" \
-d '{
"url": "https://firecrawl.dev",
"formats": ["markdown", "html"]
}'
# Scrape a URL and get markdown
firecrawl https://firecrawl.dev
# With multiple formats (returns JSON)
firecrawl https://firecrawl.dev --format markdown,html,links --pretty
SDKs will return the data object directly. cURL will return the payload exactly as shown below.
{
"success": true,
"data" : {
"markdown": "Launch Week I is here! [See our Day 2 Release 🚀](https://www.firecrawl.dev/blog/launch-week-i-day-2-doubled-rate-limits)[💥 Get 2 months free...",
"html": "<!DOCTYPE html><html lang=\"en\" class=\"light\" style=\"color-scheme: light;\"><body class=\"__variable_36bd41 __variable_d7dc5d font-inter ...",
"metadata": {
"title": "Home - Firecrawl",
"description": "Firecrawl crawls and converts any website into clean markdown.",
"language": "en",
"keywords": "Firecrawl,Markdown,Data,Mendable,Langchain",
"robots": "follow, index",
"ogTitle": "Firecrawl",
"ogDescription": "Turn any website into LLM-ready data.",
"ogUrl": "https://www.firecrawl.dev/",
"ogImage": "https://www.firecrawl.dev/og.png?123",
"ogLocaleAlternate": [],
"ogSiteName": "Firecrawl",
"sourceURL": "https://firecrawl.dev",
"statusCode": 200,
"contentType": "text/html"
}
}
}
Interact
Scrape a page, then keep working with it: click buttons, fill forms, extract dynamic content, or navigate deeper. Describe what you want in plain English or write code for full control. See the Interact feature docs for all options.
from firecrawl import Firecrawl
app = Firecrawl(
# No API key needed to get started — add one for higher rate limits:
# api_key="fc-YOUR-API-KEY",
)
# 1. Scrape Amazon's homepage
result = app.scrape("https://www.amazon.com", formats=["markdown"])
scrape_id = result.metadata.scrape_id
# 2. Interact — search for a product and get its price
app.interact(scrape_id, prompt="Search for iPhone 16 Pro Max")
response = app.interact(scrape_id, prompt="Click on the first result and tell me the price")
print(response.output)
# 3. Stop the session
app.stop_interaction(scrape_id)
import { Firecrawl } from 'firecrawl';
const app = new Firecrawl({
// No API key needed to get started — add one for higher rate limits:
// apiKey: 'fc-YOUR-API-KEY',
});
// 1. Scrape Amazon's homepage
const result = await app.scrape('https://www.amazon.com', { formats: ['markdown'] });
const scrapeId = result.metadata?.scrapeId;
// 2. Interact — search for a product and get its price
await app.interact(scrapeId, { prompt: 'Search for iPhone 16 Pro Max' });
const response = await app.interact(scrapeId, { prompt: 'Click on the first result and tell me the price' });
console.log(response.output);
// 3. Stop the session
await app.stopInteraction(scrapeId);
# 1. Scrape Amazon's homepage
# No API key needed to get started — add -H "Authorization: Bearer $FIRECRAWL_API_KEY" for higher rate limits:
RESPONSE=$(curl -s -X POST "https://api.firecrawl.dev/v2/scrape" \
-H "Content-Type: application/json" \
-d '{"url": "https://www.amazon.com", "formats": ["markdown"]}')
SCRAPE_ID=$(echo $RESPONSE | jq -r '.data.metadata.scrapeId')
# 2. Interact — search for a product and get its price
curl -s -X POST "https://api.firecrawl.dev/v2/scrape/$SCRAPE_ID/interact" \
-H "Content-Type: application/json" \
-d '{"prompt": "Search for iPhone 16 Pro Max"}'
curl -s -X POST "https://api.firecrawl.dev/v2/scrape/$SCRAPE_ID/interact" \
-H "Content-Type: application/json" \
-d '{"prompt": "Click on the first result and tell me the price"}'
# 3. Stop the session
curl -s -X DELETE "https://api.firecrawl.dev/v2/scrape/$SCRAPE_ID/interact"
# 1. Scrape Amazon's homepage (scrape ID is saved automatically)
firecrawl scrape https://www.amazon.com
# 2. Interact — search for a product and get its price
firecrawl interact "Search for iPhone 16 Pro Max"
firecrawl interact "Click on the first result and tell me the price"
# 3. Stop the session
firecrawl interact stop
{
"success": true,
"cdpUrl": "wss://browser.firecrawl.dev/...",
"liveViewUrl": "https://liveview.firecrawl.dev/...",
"interactiveLiveViewUrl": "https://liveview.firecrawl.dev/...",
"output": "The iPhone 16 Pro Max (256GB) is priced at $1,199.00.",
"exitCode": 0,
"killed": false
}
More capabilities
Autonomous web data gathering powered by AI
Click, fill forms, extract dynamic content
Async event delivery
Managed browser sessions for interactive workflows
Turn local PDFs, DOCX, XLSX, HTML, and more into Markdown or structured JSON
Discover all URLs on a website
Recursively gather content from entire sites
Resources
Complete API documentation with interactive examples
Python, Node.js, CLI, and community SDKs
Self-host Firecrawl or contribute to the project
LangChain, LlamaIndex, OpenAI, and more
Get started with Firecrawl in Go. Scrape, search, and interact with web data using the REST API.
Prerequisites
- Go 1.21+
- A Firecrawl API key — get one free
Search the web
Firecrawl works with Go through the REST API. Use net/http to make requests directly.
package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
)
func main() {
apiKey := os.Getenv("FIRECRAWL_API_KEY")
body, _ := json.Marshal(map[string]interface{}{
"query": "firecrawl web scraping",
"limit": 5,
})
req, _ := http.NewRequest("POST", "https://api.firecrawl.dev/v2/search", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "request failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}
{
"success": true,
"data": {
"web": [
{
"url": "https://docs.firecrawl.dev",
"title": "Firecrawl Documentation",
"markdown": "# Firecrawl\n\nFirecrawl is a web scraping API..."
}
]
}
}
Scrape a page
body, _ := json.Marshal(map[string]string{
"url": "https://example.com",
})
req, _ := http.NewRequest("POST", "https://api.firecrawl.dev/v2/scrape", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "request failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
{
"success": true,
"data": {
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
"metadata": {
"title": "Example Domain",
"sourceURL": "https://example.com"
}
}
}
Interact with a page
Start a browser session, interact with the page using natural-language prompts, then close the session.
Step 1 — Scrape to start a session
body, _ := json.Marshal(map[string]interface{}{
"url": "https://www.amazon.com",
"formats": []string{"markdown"},
})
req, _ := http.NewRequest("POST", "https://api.firecrawl.dev/v2/scrape", bytes.NewReader(body))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "request failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
var scrapeResult map[string]interface{}
json.NewDecoder(resp.Body).Decode(&scrapeResult)
data := scrapeResult["data"].(map[string]interface{})
metadata := data["metadata"].(map[string]interface{})
scrapeId := metadata["scrapeId"].(string)
fmt.Println("scrapeId:", scrapeId)
Step 2 — Send interactions
// Search for a product
interactBody, _ := json.Marshal(map[string]string{
"prompt": "Search for iPhone 16 Pro Max",
})
interactURL := fmt.Sprintf("https://api.firecrawl.dev/v2/scrape/%s/interact", scrapeId)
req, _ = http.NewRequest("POST", interactURL, bytes.NewReader(interactBody))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err = http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "interact failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
// Click on the first result
interactBody, _ = json.Marshal(map[string]string{
"prompt": "Click on the first result and tell me the price",
})
req, _ = http.NewRequest("POST", interactURL, bytes.NewReader(interactBody))
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
resp, err = http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "interact failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
result, _ = io.ReadAll(resp.Body)
fmt.Println(string(result))
Step 3 — Stop the session
req, _ = http.NewRequest("DELETE", interactURL, nil)
req.Header.Set("Authorization", "Bearer "+apiKey)
resp, err = http.DefaultClient.Do(req)
if err != nil {
fmt.Fprintf(os.Stderr, "delete failed: %v\n", err)
os.Exit(1)
}
defer resp.Body.Close()
fmt.Println("Session stopped")
Reusable helper
For repeated use, wrap the API in a small helper:
type FirecrawlClient struct {
APIKey string
BaseURL string
Client *http.Client
}
func NewFirecrawlClient(apiKey string) *FirecrawlClient {
return &FirecrawlClient{
APIKey: apiKey,
BaseURL: "https://api.firecrawl.dev/v2",
Client: &http.Client{},
}
}
func (fc *FirecrawlClient) post(endpoint string, payload interface{}) ([]byte, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
req, err := http.NewRequest("POST", fc.BaseURL+endpoint, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Authorization", "Bearer "+fc.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := fc.Client.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
return io.ReadAll(resp.Body)
}
func (fc *FirecrawlClient) Scrape(url string) ([]byte, error) {
return fc.post("/scrape", map[string]string{"url": url})
}
func (fc *FirecrawlClient) Search(query string, limit int) ([]byte, error) {
return fc.post("/search", map[string]interface{}{"query": query, "limit": limit})
}
A community Go SDK is available for the v1 API. See the Go SDK docs for details.
Next steps
Search the web and get full page content
All scrape options including formats, actions, and proxies
Click, fill forms, and extract dynamic content
Complete REST API documentation
Get started with Firecrawl in PHP. Scrape, search, and interact with web data using the REST API.
Prerequisites
- PHP 8.0+ with cURL extension
- A Firecrawl API key — get one free
Search the web
Firecrawl works with PHP through the REST API using cURL.
<?php
$apiKey = getenv('FIRECRAWL_API_KEY');
$ch = curl_init('https://api.firecrawl.dev/v2/search');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'query' => 'firecrawl web scraping',
'limit' => 5,
]),
]);
$response = curl_exec($ch);
curl_close($ch);
$results = json_decode($response, true);
foreach ($results['data']['web'] as $result) {
echo $result['title'] . ' - ' . $result['url'] . "\n";
}
{
"success": true,
"data": {
"web": [
{
"url": "https://docs.firecrawl.dev",
"title": "Firecrawl Documentation",
"markdown": "# Firecrawl\n\nFirecrawl is a web scraping API..."
}
]
}
}
Scrape a page
<?php
$ch = curl_init('https://api.firecrawl.dev/v2/scrape');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://example.com',
]),
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
echo $data['data']['markdown'];
{
"success": true,
"data": {
"markdown": "# Example Domain\n\nThis domain is for use in illustrative examples...",
"metadata": {
"title": "Example Domain",
"sourceURL": "https://example.com"
}
}
}
Interact with a page
Start a browser session, interact with the page using natural-language prompts, then close the session.
Step 1 — Scrape to start a session
<?php
$ch = curl_init('https://api.firecrawl.dev/v2/scrape');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'url' => 'https://www.amazon.com',
'formats' => ['markdown'],
]),
]);
$response = curl_exec($ch);
curl_close($ch);
$scrapeResult = json_decode($response, true);
$scrapeId = $scrapeResult['data']['metadata']['scrapeId'];
echo "scrapeId: $scrapeId\n";
Step 2 — Send interactions
<?php
$interactUrl = "https://api.firecrawl.dev/v2/scrape/$scrapeId/interact";
$headers = [
'Authorization: Bearer ' . $apiKey,
'Content-Type: application/json',
];
// Search for a product
$ch = curl_init($interactUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'Search for iPhone 16 Pro Max',
]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response . "\n";
// Click on the first result
$ch = curl_init($interactUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_POSTFIELDS => json_encode([
'prompt' => 'Click on the first result and tell me the price',
]),
]);
$response = curl_exec($ch);
curl_close($ch);
echo $response . "\n";
Step 3 — Stop the session
<?php
$ch = curl_init($interactUrl);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => 'DELETE',
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $apiKey,
],
]);
curl_exec($ch);
curl_close($ch);
echo "Session stopped\n";
Reusable helper class
For repeated use, wrap the API in a class:
<?php
class Firecrawl
{
private string $apiKey;
private string $baseUrl = 'https://api.firecrawl.dev/v2';
public function __construct(string $apiKey)
{
$this->apiKey = $apiKey;
}
private function post(string $endpoint, array $payload): array
{
$ch = curl_init($this->baseUrl . $endpoint);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer ' . $this->apiKey,
'Content-Type: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode >= 400) {
throw new \RuntimeException("Firecrawl API error: HTTP $httpCode");
}
return json_decode($response, true);
}
public function scrape(string $url, array $options = []): array
{
return $this->post('/scrape', array_merge(['url' => $url], $options));
}
public function search(string $query, int $limit = 5): array
{
return $this->post('/search', ['query' => $query, 'limit' => $limit]);
}
}
// Usage
$app = new Firecrawl(getenv('FIRECRAWL_API_KEY'));
$result = $app->scrape('https://example.com');
echo $result['data']['markdown'];
Next steps
Search the web and get full page content
All scrape options including formats, actions, and proxies
Click, fill forms, and extract dynamic content
Complete REST API documentation
