Skip to main content
9 toolsAPI key
tavily_example.py
Tavily is the web layer for AI agents: search when sources are unknown, extract when the URL is already selected, map and crawl when a whole site needs to be read, and research when the output should be a cited synthesis.

Authenticating

This pack takes an API key in Authorization, and configure() is optional when $TAVILY_API_KEY is set. There is no authorization server, no consent screen and no refresh — API keys is the whole story. The key is prefixed tvly-… and goes out as a bearer token.

The client

api_key_tool_factory is the whole client: a thin wrapper over httpx that attaches your key and these endpoint constants to each request. No vendor SDK enters your dependency tree.

Tools

Each is a Tool, called with ainvoke as in the snippet above.

What each tool is for

search is the starting point when sources are unknown or current web context is needed. Prefer search_depth="advanced" with chunks_per_source=3 for stronger evidence per source. extract reads one or more known URLs as markdown or text. Use it after search when the URL is already selected. map discovers URLs on a site without extracting content — useful before crawl to understand structure. crawl traverses a site graph and extracts page content. Use when many pages on a site need to be read. research_create starts an async research task that searches, analyzes sources, and generates a cited report. Poll with research_get until status is completed. SSE streaming is not exposed as a tool. usage, logs, and org_usage report credit consumption. logs requires a paid plan or pay-as-you-go; org_usage is enterprise-only and must authenticate with the organization owner’s personal API key.

Gotchas

Parameters, bodies and query strings are all snake_case. Tavily ignores parameters it does not recognise, so a misspelled filter silently drops rather than failing.
research_create returns a request_id. Poll with research_get — HTTP 202 means still running; HTTP 200 with status: completed carries the report.
Search costs 1 credit for basic/fast/ultra-fast and 2 for advanced. Extract bills per five successful URLs; crawl and map bill per ten pages.