taviliy-elixir

Elixir SDK for the Tavily API, modeled after the official Python SDK.

Supported endpoints:

Compatibility helpers:

Installation

Add to mix.exs:

def deps do
  [
    {:taviliy_elixir, "~> 0.1.0"}
  ]
end

Configuration

You can pass an API key directly, or use environment variables.

Supported environment variables:

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)
end

Async 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:

Notes