Skip to content

Web search for CrewAI agents with ContextFetch

CrewAI already ships the tools you need. Create crewai-tools' ExaSearchTool with your ContextFetch key and base_url set to https://api.contextfetch.dev, hand it to an agent, and every search the agent runs goes to ContextFetch at $1 per 1,000 searches. TavilySearchTool works too once you swap in a TavilyClient with the /tavily base URL. No new package, no wrapper class: one constructor argument changes.

Verified PythonCrewAI/search/tavily/search

1. Get a key

One POST returns a free key with $2.50 of balance, enough for 2,500 default searches. There is no signup form, and one free key is issued per network. Export it as CONTEXTFETCH_API_KEY; the code below reads it from there.

curl -X POST https://api.contextfetch.dev/v1/keys/free# {"apiKey": "cf_live_...", "balance_usd": 2.5, "searches": 2500}export CONTEXTFETCH_API_KEY="cf_live_..."

2. Install crewai-tools and exa-py

ExaSearchTool lives in crewai-tools and calls the official exa-py client underneath. Install both into the environment your crew runs in.

pip install crewai-tools exa-py

3. Point ExaSearchTool at ContextFetch

ExaSearchTool has a base_url field (or the EXA_BASE_URL environment variable) that it passes to the Exa client. Set it to https://api.contextfetch.dev and pass your ContextFetch key as api_key. ContextFetch serves Exa's /search route, so the tool's default type="auto" and highlights come back in the shape the tool already parses.

If you prefer environment variables, export EXA_API_KEY with your ContextFetch key and EXA_BASE_URL=https://api.contextfetch.dev, then construct ExaSearchTool() with no arguments.

import osfrom crewai_tools import ExaSearchTool search = ExaSearchTool(    api_key=os.environ["CONTEXTFETCH_API_KEY"],    base_url="https://api.contextfetch.dev",)

4. Or keep TavilySearchTool

TavilySearchTool builds its own TavilyClient and has no base URL field, so replace its client after construction. tavily-python's TavilyClient takes api_base_url.

This tool always sends days (default 7). As on Tavily, ContextFetch applies days only when topic is news, so general searches are not limited to the past week.

import osfrom crewai_tools import TavilySearchToolfrom tavily import TavilyClient key = os.environ["CONTEXTFETCH_API_KEY"]search = TavilySearchTool(api_key=key, max_results=5)search.client = TavilyClient(api_key=key, api_base_url="https://api.contextfetch.dev/tavily")

5. Give the tool to an agent

Pass the tool in an agent's tools list as you would any CrewAI tool. The agent's LLM decides when to search and with what query; CrewAI then calls tool.run(...), which is exactly what the program below does by hand, so you can check the results without an LLM key.

from crewai import Agent, Crew, Task researcher = Agent(    role="Researcher",    goal="Answer with sources from the live web",    backstory="You check facts before you state them.",    tools=[search],)task = Task(    description="How do vector databases use HNSW? Cite URLs.",    expected_output="A short answer with source URLs",    agent=researcher,)print(Crew(agents=[researcher], tasks=[task]).kickoff())

6. Cost and limits

Each tool call is one search. type="auto" (the tool's default) and Tavily's basic depth are the default search at $1 per 1,000, and the page text comes in that price. Exa's deep types and Tavily's advanced depth run the deep tier at $3 per 1,000. A free key allows 100 requests a minute and a paid key 300. Every billable response carries X-Cost-USD and X-Balance-USD headers, so you can watch spend from your own logs.

The complete code

Python, runnable as is with CONTEXTFETCH_API_KEY set. Install first: crewai-tools, exa-py. We ran it against the live API; the output below is what it printed.

import os from crewai_tools import ExaSearchTool search = ExaSearchTool(    api_key=os.environ["CONTEXTFETCH_API_KEY"],    base_url="https://api.contextfetch.dev",) # Call the tool directly, the same way a CrewAI agent calls it mid-task.res = search.run(search_query="how do vector databases use HNSW")for r in res.results[:3]:    print(r.title)    print("  ", r.url)    if r.highlights:        print("  ", r.highlights[0][:160].replace("\n", " ")) 
OutputRecorded
Vector Database Basics: HNSW | Tiger Data
   https://www.tigerdata.com/blog/vector-database-basics-hnsw
   Among these, HNSW stands out for its use of a multi-layered graph structure that efficiently tackles the "curse of dimensionality"—an issue that impacts high-di
What is a Hierarchical Navigable Small World - MongoDB
   https://www.mongodb.com/resources/basics/hierarchical-navigable-small-world
   Vector databases and vector search solutions often use HNSW algorithms. For example, MongoDB Atlas Vector Search uses the hierarchical navigable small worlds al
Understand HNSW for Vector Search - Milvus Blog
   https://milvus.io/blog/understand-hierarchical-navigable-small-worlds-hnsw-for-vector-search.md
   The search procedure works much like the inner graph construction step. Starting from the top layer, we greedily navigate to the node or nodes closest to the qu

The same call with curl

The raw HTTP request, and the response it returned (long text fields and lists shortened).

curl -s https://api.contextfetch.dev/search \  -H "x-api-key: $CONTEXTFETCH_API_KEY" \  -H "Content-Type: application/json" \  -d '{"query": "how do vector databases use HNSW", "type": "auto", "numResults": 3, "contents": {"highlights": true}}'
ResponseRecorded
{
  "requestId": "da805cc8d96c4208ab651e001a8318cb",
  "results": [
    {
      "id": "da448ee3-6bf9-5d06-8884-9f47aa89b925",
      "url": "https://www.tigerdata.com/blog/vector-database-basics-hnsw",
      "title": "Vector Database Basics: HNSW | Tiger Data",
      "score": 0.9999999997954188,
      "publishedDate": "2024-08-13T11:10:35.000-04:00",
      "text": null,
      "highlights": [
        "Among these, HNSW stands out for its use of a multi-layered graph structure that efficiently tackles the \"curse of dimensionality\"—an issue that impacts high-dimensional data spaces by making traditional search methodologies inefficient and often infeasible.\n\nHNSW's layered graph…",
        "Here, `m` controls the maximum number of connections for each element in the index, `ef_construction` adjusts the size of the dynamic list used during index construction for better accuracy, and `ef_search` influences the search time precision.\n\n## Overcoming HNSW Limitations\n\nWh…",
        "With Timescale Cloud, developers can access [pgvector, pgvectorscale, and pgai](https://blog-cms.tigerdata.com/blog/making-postgresql-a-better-ai-database/)—extensions that turn PostgreSQL into an easy-to-use and high-performance vector database, plus a fully managed cloud databa…"
      ],
      "highlightScores": [
        0.9995938719798151,
        0.9992213747517059,
        0.9991101557546864
      ],
      "prunedContext": "---\ntitle: \"Vector Database Basics: HNSW\"\npublished: 2024-08-13T11:10:35.000-04:00\nupdated: 2026-02-24T11:33:07.000-05:00\nexcerpt: \"Learn more about hierarchical navigable small world indexes, their pros and cons, and how to use them with PostgreSQL via pgvector.\"\ntags: AI\nauthor…",
      "textSource": "page",
      "language": "en"
    },
    {
      "id": "8d894830-b9ff-55d6-8a56-b8f98ebe5e7c",
      "url": "https://www.mongodb.com/resources/basics/hierarchical-navigable-small-world",
      "title": "What is a Hierarchical Navigable Small World - MongoDB",
      "score": 0.9999999963476038,
      "publishedDate": "2016-01-01",
      "text": null,
      "highlights": [
        "Vector databases and vector search solutions often use HNSW algorithms. For example, MongoDB Atlas Vector Search uses the hierarchical navigable small worlds algorithm to perform the semantic search. You can use Atlas Vector Search support for ANN queries to search for results si…",
        "Another technique, prefiltering, can also improve search efficiency by narrowing the search space. In prefiltering, an initial candidate list is generated through a filtering step before the HNSW search begins, helping to streamline the process and reduce unnecessary computations…",
        "Hierarchical navigable small world (HNSW) is a powerful algorithm used in computer science and information retrieval systems to efficiently search large datasets. It addresses the challenge of finding the nearest neighbors of a given data point in a high-dimensional space by orga…"
      ],
      "highlightScores": [
        0.9995818617386723,
        0.9982503913028425,
        0.997563274277347
      ],
      "prunedContext": "Hierarchical navigable small world (HNSW) is a powerful algorithm used in computer science and information retrieval systems to efficiently search large datasets. It addresses the challenge of finding the nearest neighbors of a given data point in a high-dimensional space by orga…",
      "textSource": "page",
      "language": "en"
    },
    {
      "id": "29ff54bd-7b01-51b8-b2f1-05a70fba3211",
      "url": "https://milvus.io/blog/understand-hierarchical-navigable-small-worlds-hnsw-for-vector-search.md",
      "title": "Understand HNSW for Vector Search - Milvus Blog",
      "score": 0.9999999925301191,
      "publishedDate": "2025-05-21T00:00:00.000Z",
      "text": null,
      "highlights": [
        "The search procedure works much like the inner graph construction step. Starting from the top layer, we greedily navigate to the node or nodes closest to the query. Then we follow that node(s) down to the next layer and repeat the process. Our answer is obtained by the list of\nR\n…",
        "search\n, which involves finding the nearest neighbors in the database to a query vector, for example, by Euclidean distance. A naive method would calculate the distance from the query vector to every vector stored in the database and take the top-K closest. However, this clearly …",
        "Then, we follow an edge from the local minimum in the _L_th layer to the corresponding vector in the _(L-1)_th layer and use it as the entry point to greedily search the _(L-1)_th layer.\n\nThis process is repeated until we reach the _l_th layer. We then begin to create nodes for t…"
      ],
      "highlightScores": [
        0.9985946605552138,
        0.9972061269355634,
        0.9949557610493148
      ],
      "prunedContext": "🚀 Zilliz Cloud: fully managed Milvus — 10x faster. Zero hassle. Built for AI.\nTry Free Now →\nWhy Milvus\nWhat is Milvus\nUse Cases\nSolutions\nCompare databases\nDocs\nTutorials\nBootcamp\nDemos\nVideo\nTools\nAttu\nMilvus CLI\nSizing Tool\nMilvus Backup\nVTS\nDeep Searcher\nClaude Context\nBlog\n…",
      "textSource": "page",
      "language": "en"
    }
  ],
  "costDollars": {
    "total": 0.001
  },
  "searchTimeMs": 2,
  "searchTime": 2,
  "contextfetch": {
    "tokens": {
      "raw": 12744,
      "pruned": 3036,
      "savedPct": 76.17702448210923
    },
    "sources": {
      "local": 3,
      "bing": 8,
      "google": 10
    },
    "cache": "hit",
    "timingsMs": {
      "recall": 0,
      "fetch": 0,
      "rerank": 0,
      "total": 2
    }
  }
}

Questions

How does the cost compare with Exa and Tavily?

At list prices, Exa's auto search is $7 per 1,000 requests and Tavily's basic search is 1 credit at $0.008, so $8 per 1,000 on pay-as-you-go. The same tool calls through ContextFetch cost $1 per 1,000, with page Markdown included. [The Exa comparison](/compare/exa-alternative) cites the sources.

Do I need a CrewAI-specific package?

No. ExaSearchTool and TavilySearchTool are the stock crewai-tools classes. Only the base URL and the key change, so upgrading crewai-tools keeps working the same way.

Can my crew search without a key?

The Exa and Tavily clients expect a key, so use the free one: $2.50 of balance, one per network. Raw HTTP calls sent with no key at all get 25 requests per IP address per day, which is handy for trying the curl call below.

Does include_answer return a model-written answer?

No. If you set include_answer on TavilySearchTool, ContextFetch returns a passage quoted from the most relevant source, or null when nothing is relevant enough. Your agent's own LLM writes the final answer from the results.

Run it with your own key

A free key has 2,500 searches and needs no signup. Agents can claim one themselves with the POST below.

curl -X POST https://api.contextfetch.dev/v1/keys/free
Get a free key