Switch from Tavily to ContextFetch in Python with one line
You do not need to rewrite anything. ContextFetch serves a Tavily-compatible API under /tavily, so tavily-python keeps working once you pass api_base_url and a ContextFetch key. Results keep Tavily's shape: title, url, content, raw_content and score, and each search costs one credit, basic or advanced. The one real difference is that include_answer returns a passage quoted from the sources, not text written by a model.
1. Get an API key
Claim a free key with one POST request. It needs no signup and comes with 2,500 credits, and one free key is issued per network. Export it so the code below can read it.
You can also try the API with no key at all: requests without an Authorization header get 25 free calls per IP address per UTC day.
curl -X POST https://api.contextfetch.dev/v1/keys/free# {"apiKey": "cf_live_...", "credits": 2500}export CONTEXTFETCH_API_KEY="cf_live_..."2. Change the client
Create the client with your ContextFetch key and api_base_url. Every method you already call now goes to ContextFetch, and nothing else in your code has to change.
tavily-python sends the key as a bearer token, which ContextFetch reads. Raw HTTP requests can also send it as api_key in the JSON body, the way Tavily's own API takes it.
import osfrom tavily import TavilyClient # before# client = TavilyClient(api_key="tvly-...") # afterclient = TavilyClient( api_key=os.environ["CONTEXTFETCH_API_KEY"], api_base_url="https://api.contextfetch.dev/tavily",)3. What stays the same
search()takesquery,search_depth,max_results,include_domains,exclude_domains,include_raw_contentandinclude_answer.- Each result has
title,url,content,raw_contentandscore, andraw_contentis the page as clean Markdown when you ask for it. - Errors use Tavily's shape,
{"detail": {"error": ...}}, and running out of credits is HTTP 432 as on Tavily, so tavily-python raises its usual error. - Crawl and map are served at
/tavily/crawland/tavily/mapunder the same base URL.
4. What is different
search_depth accepts basic and advanced, and both cost one credit. include_answer adds an answer quoted from the most relevant passages, or null when none is relevant enough. ContextFetch runs no generative model, so the answer is never a paraphrase, which also means it never states something the sources do not say.
If your code relied on a fluent written summary, pass the results to your own LLM and have it write one from the quoted material.
5. Check it worked
Run the program below. It makes one search through tavily-python and prints the quoted answer and the top URLs. Every billable response also carries an X-Credits-Remaining header, and GET /v1/balance with your key returns the same number, so you can watch the credit count drop by one per search.
The complete code
Python, runnable as is with CONTEXTFETCH_API_KEY set. Install first: tavily-python. We ran it against the live API; the output below is what it printed.
import os from tavily import TavilyClient client = TavilyClient( api_key=os.environ["CONTEXTFETCH_API_KEY"], api_base_url="https://api.contextfetch.dev/tavily",) res = client.search( "how does HNSW indexing work", max_results=3, include_answer=True,) print("answer:", (res.get("answer") or "no passage was relevant enough")[:300])for r in res["results"]: print(f"{r['score']:.2f} {r['title']}\n {r['url']}")print("response_time:", res["response_time"]) answer: ## How does HNSW work?# HNSW uses proximity graphs (graphs connecting nodes based on distance between them) to approximate nearest-neighbor search. To understand HNSW, we can break it down into 2 parts: - **Hierarchical (H):** The algorithm operates over multiple layers - **Navigable Small W…
1.00 HNSW indexes | Supabase Docs
https://supabase.com/docs/guides/ai/vector-indexes/hnsw-indexes
1.00 HNSW Explained: How Vector Database Indexes Work
https://ai-tldr.dev/learn/embeddings-vector-databases/similarity-search-indexing/hnsw-explained
1.00 HNSW Indexing Fundamentals - Qdrant
https://qdrant.tech/course/essentials/day-2/what-is-hnsw
response_time: 0.002The 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/tavily/search \ -H "Content-Type: application/json" \ -d '{"api_key": "'"$CONTEXTFETCH_API_KEY"'", "query": "how does HNSW indexing work", "max_results": 3, "include_answer": true}'{
"query": "how does HNSW indexing work",
"images": [],
"results": [
{
"title": "HNSW indexes | Supabase Docs",
"url": "https://supabase.com/docs/guides/ai/vector-indexes/hnsw-indexes",
"content": "## How does HNSW work?#\n\nHNSW uses proximity graphs (graphs connecting nodes based on distance between them) to approximate nearest-neighbor search. To understand HNSW, we can break it down into 2 parts:\n\n- **Hierarchical (H):** The algorithm operates over multiple layers\n- **Nav…",
"raw_content": null,
"score": 0.9998405225057632
},
{
"title": "HNSW Explained: How Vector Database Indexes Work",
"url": "https://ai-tldr.dev/learn/embeddings-vector-databases/similarity-search-indexing/hnsw-explained",
"content": "You zoom out, pick the right continent, then the right country, then the right region, and only then do you zoom in and compare the handful of candidates nearby. That multi-scale drill-down is exactly the idea behind\nHNSW — Hierarchical Navigable Small World\ngraphs.\nHNSW\n— datasc…",
"raw_content": null,
"score": 0.9998355138433457
},
{
"title": "HNSW Indexing Fundamentals - Qdrant",
"url": "https://qdrant.tech/course/essentials/day-2/what-is-hnsw",
"content": "## Configuring HNSW\n\nWe can fine-tune how our HNSW graph is built to balance search speed, accuracy, memory usage, and indexing time, depending on our use case needs. Qdrant allows you to control how the HNSW index behaves with three key parameters: `m`, `hnsw_ef`, and `ef_constr…",
"raw_content": null,
"score": 0.9994862244941404
}
],
"answer": "## How does HNSW work?# HNSW uses proximity graphs (graphs connecting nodes based on distance between them) to approximate nearest-neighbor search. To understand HNSW, we can break it down into 2 parts: - **Hierarchical (H):** The algorithm operates over multiple layers - **Navig…",
"response_time": 0.001,
"request_id": "1953bcd391874172ab45261fc9a95a81"
}