Firecrawl + OpenAI
Give OpenAI models live web search and scraping with Firecrawl.
Define Firecrawl as a function calling tool or add it to the OpenAI Agents SDK.
companies of all sizes
await firecrawl.scrape()
await firecrawl.scrape()
await firecrawl.scrape()
await firecrawl.scrape()
Key Features
Which web search API can I use as an OpenAI function calling tool?
Any web search API with an HTTP endpoint can be an OpenAI function calling tool. Firecrawl's search API fits because one call returns titles, URLs and descriptions, and can return full page Markdown too. Define a web_search function, run the Firecrawl search when the model calls it, and send the results back to the model.
Install the packages
Install the OpenAI and Firecrawl Python SDKs. Set FIRECRAWL_API_KEY from your Firecrawl dashboard and OPENAI_API_KEY.
pip install -U openai firecrawl-py
export FIRECRAWL_API_KEY="fc-YOUR-API-KEY"
export OPENAI_API_KEY="sk-YOUR-API-KEY"Define the web_search function
The model sees the name, description and JSON schema, and returns a function call with a query when it needs the web. Your code runs the call against the Firecrawl search API.
import json
from firecrawl import Firecrawl
from openai import OpenAI
client = OpenAI()
firecrawl = Firecrawl()
tools = [
{
"type": "function",
"name": "web_search",
"description": "Search the web with Firecrawl. Returns titles, URLs and descriptions.",
"parameters": {
"type": "object",
"properties": {"query": {"type": "string", "description": "The search query"}},
"required": ["query"],
"additionalProperties": False,
},
"strict": True,
}
]
def web_search(query: str) -> str:
results = firecrawl.search(query, limit=5)
return json.dumps(
[{"title": r.title, "url": r.url, "description": r.description} for r in (results.web or [])]
)Run the function calling loop
Send the question with the tool defined. While the model keeps asking for searches, run web_search for each function call and return the output with the matching call ID. When a response has no function calls, it holds the final answer.
input_list = [{"role": "user", "content": "What did OpenAI ship this week? Cite sources."}]
while True:
response = client.responses.create(model="gpt-6-luna", tools=tools, input=input_list)
calls = [item for item in response.output if item.type == "function_call"]
if not calls:
break
input_list += response.output
for call in calls:
query = json.loads(call.arguments)["query"]
input_list.append(
{"type": "function_call_output", "call_id": call.call_id, "output": web_search(query)}
)
print(response.output_text)How do I add a web search tool to the OpenAI Agents SDK?
To add web search to the OpenAI Agents SDK, decorate a function that calls Firecrawl search with function_tool and add it to the agent's tools. The SDK builds the tool schema from the type hints and docstring, runs the function when the model calls it, and loops until the agent answers.
Install the packages
Install the Agents SDK and the Firecrawl Python SDK, then set both API keys.
pip install -U openai-agents firecrawl-pyCreate the tool and the agent
function_tool turns firecrawl_search into a tool with query and limit arguments. Runner.run_sync runs the agent until it returns a final answer.
from agents import Agent, Runner, function_tool
from firecrawl import Firecrawl
firecrawl = Firecrawl()
@function_tool
def firecrawl_search(query: str, limit: int = 5) -> str:
"""Search the web with Firecrawl and return titles, URLs and descriptions.
Args:
query: The search query.
limit: Maximum number of results.
"""
results = firecrawl.search(query, limit=limit)
return "\n\n".join(f"{r.title}\n{r.url}\n{r.description}" for r in (results.web or []))
agent = Agent(
name="Research assistant",
instructions="Use firecrawl_search for anything current and cite the URLs you used.",
model="gpt-6-luna",
tools=[firecrawl_search],
)
result = Runner.run_sync(agent, "What changed in the latest OpenAI Agents SDK release?")
print(result.final_output)People love
building with Firecrawl











Firecrawl is an open-source framework that takes a URL, crawls it, and conver..."

Upload a CSV of emails and..."



Firecrawl is an open-source framework that takes a URL, crawls it, and conver..."

Upload a CSV of emails and..."
Tutorials & guides
How to Use OpenAI's o1 Reasoning Models in Your Applications
Learn how to harness OpenAI's latest o1 series models for complex reasoning tasks in your apps.
Read tutorial →Using OpenAI's Realtime API and Firecrawl to Talk with Any Website
Build a real-time conversational agent that interacts with any website using OpenAI's Realtime API and Firecrawl.
Read tutorial →OpenAI Swarm Tutorial: Create Marketing Campaigns for Any Website
A guide to building a multi-agent system using OpenAI Swarm and Firecrawl for AI-driven marketing strategies
Read tutorial →Frequently
asked questions
Flexible pricing
Free Plan
Hobby
StandardMost popular
Growth
Scale Plans
High-volume plans for teams that need more power and dedicated support. Get access to higher rate limits, more concurrent browsers, and priority support. Scale checks out instantly, no sales call needed.
Need more? Contact usAlso on AWS Marketplace and Google Cloud Marketplace.

















