Tavily Dart Client

tests tavily_dart MIT

Dart Client for the Tavily API (a search engine optimized for LLMs and RAG).

Features

  • Fully type-safe, documented and tested
  • All platforms supported
  • Custom base URL, headers and query params support (e.g. HTTP proxies)
  • Custom HTTP client support (e.g. SOCKS5 proxies or advanced use cases)

Supported endpoints:

  • Search

Table of contents

Usage

Refer to the documentation for more information about the API.

Authentication

The Tavily API uses API keys for authentication. Visit the Tavily console to retrieve the API key you'll use in your requests.

Remember that your API key is a secret!
Do not share it with others or expose it in any client-side code (browsers, apps). Production requests must be routed through your own backend server where your API key can be securely loaded from an environment variable or key management service.

final apiKey = Platform.environment['TAVILY_API_KEY'];
final client = TavilyClient();

Search for data based on a query.

Basic search:

final res = await client.search(
  request: SearchRequest(
    apiKey: apiKey,
    query: 'Should I invest in Apple right now?',
  ),
);
print(res);

Advanced search:

final res = await client.search(
  request: SearchRequest(
    apiKey: apiKey,
    query: 'Should I invest in Apple right now?',
    searchDepth: SearchRequestSearchDepth.advanced,
  ),
);
print(res);

See the API documentation for more information on all supported search parameters.

Advance Usage

Custom HTTP client

You can always provide your own implementation of http.Client for further customization:

final client = TavilyClient(
  client: MyHttpClient(),
);

Using a proxy

HTTP proxy

You can use your own HTTP proxy by overriding the baseUrl and providing your required headers:

final client = TavilyClient(
  baseUrl: 'https://my-proxy.com',
  headers: {
      'x-my-proxy-header': 'value',
  },
);

If you need further customization, you can always provide your own http.Client.

SOCKS5 proxy

To use a SOCKS5 proxy, you can use the socks5_proxy package:

final baseHttpClient = HttpClient();
SocksTCPClient.assignToHttpClient(baseHttpClient, [
  ProxySettings(InternetAddress.loopbackIPv4, 1080),
]);
final httpClient = IOClient(baseClient);

final client = TavilyClient(
  client: httpClient,
);

Acknowledgements

The generation of this client was made possible by the openapi_spec package.

License

Tavily Dart Client is licensed under the MIT License.

Libraries

tavily_dart
Dart Client for the Tavily API (a search engine optimized for LLMs and RAG).