taviliy-elixir
Elixir SDK for the Tavily API, modeled after the official Python SDK.
Supported endpoints:
- Search
- Extract
- Crawl
- Map
- Research
-
Get research result by
request_id
Compatibility helpers:
get_search_context/3qna_search/3get_company_info/3
Installation
Add to mix.exs:
def deps do
[
{:taviliy_elixir, "~> 0.1.0"}
]
endConfiguration
You can pass an API key directly, or use environment variables.
Supported environment variables:
TAVILY_API_KEYTAVILY_PROJECT
Quick start
client = Tavily.new!(api_key: "tvly-YOUR_API_KEY")
response = Tavily.Client.search(client, "Who is Leo Messi?")
IO.inspect(response)Search
response =
Tavily.Client.search(client, "What is Tavily?",
search_depth: "advanced",
topic: "news",
max_results: 5,
include_answer: "advanced",
include_raw_content: true,
include_images: true
)Extract
response =
Tavily.Client.extract(client, [
"https://en.wikipedia.org/wiki/Artificial_intelligence",
"https://en.wikipedia.org/wiki/Machine_learning"
])
IO.inspect(response["results"])Crawl
response =
Tavily.Client.crawl(client, "https://wikipedia.org/wiki/Lemon",
max_depth: 3,
limit: 50,
instructions: "Find all pages on citrus fruits"
)Map
response =
Tavily.Client.map(client, "https://wikipedia.org/wiki/Lemon",
max_depth: 2,
limit: 30,
instructions: "Find pages on citrus fruits"
)Research
queued =
Tavily.Client.research(client, "Research the latest developments in AI",
model: "pro",
citation_format: "apa"
)
result = Tavily.Client.get_research(client, queued["request_id"])
IO.inspect(result)Stream mode returns an enumerable of chunks:
stream = Tavily.Client.research(client, "Research the latest developments in AI", stream: true)
for chunk <- stream do
IO.write(chunk)
endAsync client
Tavily.AsyncClient mirrors Tavily.Client, but each API call returns a Task.
async_client = Tavily.AsyncClient.new!(api_key: "tvly-YOUR_API_KEY")
task = Tavily.AsyncClient.search(async_client, "What is Tavily?")
response = Tavily.AsyncClient.await(task)Error handling
The SDK raises typed exceptions for common API responses:
Tavily.Errors.BadRequestError(400)Tavily.Errors.InvalidAPIKeyError(401)Tavily.Errors.ForbiddenError(403,432,433)Tavily.Errors.UsageLimitExceededError(429)Tavily.Errors.TimeoutError(transport timeout)
Notes
get_search_context/3andqna_search/3are included for parity with the Python SDK, where they are deprecated.close/1is a no-op compatibility method.