These Go bindings implements the Tavily REST API for the Tavily SaaS service. Tavily offers APIs to search the web and retreive results in a simpe and clean way. It is first intended for LLM Agents but can be used for other purposes as well.
All current endpoints are supported:
- Search
- Extract
The client will automatically handle Tavily rate limiting for you.
Every fields of tavily API responses that can be convert to high level Golang types will be converted for ease of use within your code base.
For example: time.Duration
, *url.URL
But they will be reverted to their original type and value if they are marshal again to JSON.
The client will return a typed error with body content if the API returns a known API error status code.
The client will track current session API credits usage thru its stats method/object.
go get -v github.com/hekmon/tavily/v2
package main
import (
"context"
"github.com/hekmon/tavily"
)
func main() {
client := tavily.NewClient("<your-tavily-API-key>", tavily.APIKeyTypeDev, nil)
answer, err := client.Search(context.TODO(), tavily.SearchQuery{
Query: "What is Tavily ?",
SearchDepth: tavily.SearchDepthAdvanced, // optional
Topic: tavily.SearchQueryTopicGeneral, // optional
MaxResults: 3, // optional
IncludeImages: true, // optional
IncludeImageDescriptions: true, // optional
IncludeAnswer: true, // optional but recommended for LLMs agents
// ... others optional params exist
})
if err != nil {
panic(err)
}
// Do something with the answer
// ...
}
An optional package can help you to integrate this Tavily client as a tool with the OpenAI official API bindings.