https://github.com/hekmon/tavily
Tavily Go bindings (unofficial)
https://github.com/hekmon/tavily
aitools bindings golang golang-library llm openai-api tavily tools websearch
Last synced: 9 months ago
JSON representation
Tavily Go bindings (unofficial)
- Host: GitHub
- URL: https://github.com/hekmon/tavily
- Owner: hekmon
- License: mit
- Created: 2024-12-07T10:18:31.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-20T09:39:40.000Z (over 1 year ago)
- Last Synced: 2025-02-20T10:33:23.835Z (over 1 year ago)
- Topics: aitools, bindings, golang, golang-library, llm, openai-api, tavily, tools, websearch
- Language: Go
- Homepage: https://tavily.com
- Size: 54.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tavily Go bindings
[](https://pkg.go.dev/github.com/hekmon/tavily/v2) [](https://goreportcard.com/report/github.com/hekmon/tavily)
These Go bindings implements the [Tavily REST API](https://docs.tavily.com/docs/rest-api/api-reference) for the [Tavily](https://tavily.com/) 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.
## Features
### Endpoints
All current endpoints are supported:
- [x] Search
- [x] Extract
### Rate Limiting
The client will automatically handle Tavily [rate limiting](https://docs.tavily.com/docs/rest-api/api-reference#rate-limiting) for you.
### Golang types
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.
### Error Handling
The client will return a typed error with body content if the API returns a [known API error](https://docs.tavily.com/docs/rest-api/api-reference#error-codes) status code.
### API Credits
The client will track current session API credits usage thru its stats method/object.
## Usage
### Installation
```bash
go get -v github.com/hekmon/tavily/v2
```
### Example
```go
package main
import (
"context"
"github.com/hekmon/tavily"
)
func main() {
client := tavily.NewClient("", 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
// ...
}
```
## OpenAI Tool helper
An [optional package](https://github.com/hekmon/tavily/tree/main/tools) can help you to integrate this Tavily client as a tool with the [OpenAI official API bindings](https://github.com/openai/openai-go).