Tavily API bindings: search built for LLM agents
(https://docs.tavily.com), plus clean page content from extract.
Setup: context variable tavily.api.key (tvly-...), or a
per-call api-key in the trailing opts Map of any API-calling
function (see ::tavily::api). Sent as Authorization: Bearer.
Quick start
out ::tavily/search("qdrant vs pinecone pricing", {include_answer: true, max_results: 5})
out.answer
map(out.results, (r) { `${r.title} - ${r.url}` })
pages ::tavily/extract(["https://example.com"], {format: "markdown"})
Options use Tavily's own names, and functions return Tavily's own
response. A failed call is an Err carrying ::tavily::http/HttpError.
Context Vars
tavily.api.key
Values
BASE_URL
BASE_URL: Str "https://api.tavily.com"
Functions
build-request
fn (path: Str, body: Map, api-key: Str): ::hot::http/HttpRequest
The outgoing HttpRequest for a key. Pure; exposed for testing.
Example
key ::hot::ctx/get("tavily.api.key")
req ::tavily/build-request("/search", {query: "hot language", topic: null}, key)
req.url
req.body
extract
fn (urls: Vec): Map
fn (urls: Vec, options: Map): Map
fn (urls: Vec, options: Map, opts: Map): Map
POST /extract - Fetch and clean page content for up to 20 URLs.
options: extract_depth ("basic"/"advanced"), format
("markdown"/"text"), query (rerank chunks by relevance),
include_images, timeout (seconds). Returns {results: [{url, raw_content}], failed_results: [{url, error}]}; check both.
Example
pages ::tavily/extract(["https://example.com"], {format: "markdown"})
map(pages.results, (r) { r.raw_content })
map(pages.failed_results, (f) { f.error })
tavily.api.key
post
fn (path: Str, body: Map): Any
fn (path: Str, body: Map, api-key: Str?): Any
fn (path: Str, body: Map, opts: Map): Any
POST body as JSON to a Tavily path, dropping null values, and return
the decoded response. The escape hatch for endpoints this package does
not wrap. The third argument is an api-key Str or an opts Map (see
::tavily::api). A failed call is an Err carrying
::tavily::http/HttpError.
Example
// An endpoint this package does not wrap
out ::tavily/post("/crawl", {url: "https://example.com", limit: 5})
map(out.results, (r) { r.url })
// With a per-call key
::tavily/post("/search", {query: "hot language"}, {api-key: ::hot::ctx/get("tenant.tavily.key")})
search
fn (query: Str): Map
fn (query: Str, options: Map): Map
fn (query: Str, options: Map, opts: Map): Map
POST /search - Tavily search. options: search_depth ("basic",
"advanced", "fast", "ultra-fast"), topic ("general", "news",
"finance"), max_results (0-20), time_range ("day", "week",
"month", "year"), start_date/end_date (YYYY-MM-DD),
include_domains/exclude_domains, include_answer (LLM-written
answer in .answer), include_raw_content ("markdown"/"text"),
country, include_usage. Null options are dropped. Returns
{query, answer?, results: [{title, url, content, score}], ...}.
Example
out ::tavily/search("qdrant vs pinecone pricing", {include_answer: true, max_results: 5})
out.answer
map(out.results, (r) { r.url })
tavily.api.key