Expand description
§Tavily Rust SDK
The Tavily Rust SDK simplifies interaction with the Tavily Search API, offering three main functions:
Import the library and create a new instance of Tavily
with your API key.
ⓘ
use tavily::Tavily;
let tavily = Tavily::builder("tvly-your-api-key").build()?;
or
ⓘ
let api_key = std::env::var("TAVILY_API_KEY").expect("TAVILY_API_KEY must be set");
let tavily = Tavily::builder(&api_key)
.timeout(Duration::from_secs(60))
.max_retries(5)
.build()?;
The Tavily
instance provides the following functions:
search
: Quick search with a query string.
ⓘ
let response = tavily.search("your search query").await?;
answer
: Advanced search with query and answer.
ⓘ
let response = tavily.answer("your search query").await?;
extract
: Extract content from a URL.
ⓘ
let response = tavily.extract(vec!["https://example.com", "..."]).await?;
call
: Custom search with various options usingSearchRequest
.
ⓘ
use tavily::SearchRequest;
let request = SearchRequest::new(&api_key, "your search query")
.search_depth("advanced")
.include_images(true)
.exclude_domains(vec!["example.org"]);
let response = tavily.call(&request).await?;
§Learn more
For examples, error codes and licensing, refer to the repository.
Structs§
- Search
Request - Request object for the search API more info
- Search
Response - The response from the API when a search is made. more info
- Search
Result - The result type contained in the response. more info
- Tavily