Skip to main content

Firecrawl + OpenAI: Build an AI Research Assistant 2026

· 3 min read
Yassine El Haddad
Software Developer & Automation Specialist

I build production AI agents, web scrapers, and automation pipelines. Most of what I publish here comes from the actual problems they run into: proxies that get banned, anti-bot stacks that fingerprint your client, RAG that drifts when the underlying data moves. Stack: Python, TypeScript, Go, FastAPI, LangChain, Crawlee, Playwright, deployed on AWS, GCP, and Cloudflare.

Combine Firecrawl (web scrape) and OpenAI (GPT-4) to build a research assistant: scrape URLs, extract markdown, send to the model with a prompt, and return structured findings. Pipeline: user query → Firecrawl scrape → chunk if needed → GPT-4 with system + user messages → structured response.

Get Firecrawl →

Minimal Python Flow​

from firecrawl import Firecrawl
from openai import OpenAI

firecrawl = Firecrawl(api_key="fc-YOUR-API-KEY")
openai_client = OpenAI()

def research(query: str, urls: list[str]) -> str:
# 1. Scrape
contents = []
for url in urls:
doc = firecrawl.scrape(url, formats=["markdown"])
md = doc.get("markdown", "")
contents.append(f"--- Source: {url} ---\n{md[:8000]}") # Truncate per page

# 2. Build prompt
context = "\n\n".join(contents)
messages = [
{"role": "system", "content": "You are a research assistant. Summarize findings and cite sources by URL."},
{"role": "user", "content": f"Research question: {query}\n\nSources:\n{context}"}
]

# 3. Call GPT-4
resp = openai_client.chat.completions.create(
model="gpt-4o",
messages=messages,
temperature=0.3
)
return resp.choices[0].message.content

Example Usage​

result = research(
"What are the main features of Firecrawl?",
["https://docs.firecrawl.dev", "https://firecrawl.dev"]
)
print(result)

Structured Output​

Use a JSON schema for deterministic output:

from openai import OpenAI

resp = openai_client.beta.chat.completions.parse(
model="gpt-4o",
messages=messages,
response_format=ResearchOutput # Pydantic model
)

Cost and Limits​

  • Firecrawl: 1 credit per page
  • OpenAI: Per-token pricing. Truncate or chunk to control cost.
  • Keep source URLs and timestamps for citations and auditability.
Next step

Scale research with RAG: index many pages, retrieve only relevant chunks.

Frequently Asked Questions

Yes. Scrape with Firecrawl, pass markdown to GPT-4. Use chunking for long content.

Scrape URLs → extract markdown → send to LLM with a research prompt → return findings with citations.

A tool that gathers web content, analyzes it with an LLM, and returns structured research with source citations.

Chunk content per page. Summarize each, or use RAG to retrieve only relevant sections.

Common mistakes and fixes

Token limit exceeded with long pages

Chunk markdown or use onlyMainContent. Summarize sections before sending to GPT.

Research output lacks citations

Include source URLs in each chunk's metadata and instruct the model to cite them.

Advertise on this page