Skip to main content

Introduction

This guide shows you how to integrate Tavily with OpenAI to create more powerful and informed AI applications. By combining OpenAI’s language models with Tavily’s real-time web search capabilities, you can build AI systems and agentic AI applications that access current information and provide up-to-date responses.

Prerequisites

Before you begin, make sure you have:

Installation

Install the required packages:

Setup

Set up your API keys:

Using Tavily with OpenAI agents SDK

Note: You can enhance the function by adding more parameters like topic="news", include_domains=["example.com"], time_range="week", etc. to customize your search results.
You can set auto_parameters=True to have Tavily automatically configure search parameters based on the content and intent of your query. You can still set other parameters manually, and any explicit values you provide will override the automatic ones.

Using Tavily with OpenAI Chat Completions API function calling

Function definition

Define a function that OpenAI can call to perform searches:
Scroll to the bottom to find the full json schema for search, extract, map and crawl

Using Tavily with OpenAI Responses API function calling

Function definition

Define a function that OpenAI can call to perform searches:
Scroll to the bottom to find the full json schema for search, extract, map and crawl

Tavily endpoints schema for OpenAI Responses API tool definition

Note: When using these schemas, you can customize which parameters are exposed to the model based on your specific use case. For example, if you are building a finance application, you might set topic: "finance" for all queries without exposing the topic parameter. This way, the LLM can focus on deciding other parameters, such as time_range, country, and so on, based on the user’s request. Feel free to modify these schemas as needed and only pass the parameters that are relevant to your application.
API Format: The schemas below are for OpenAI Responses API. For Chat Completions API, wrap the parameters in a "function" object: {"type": "function", "function": {"name": "...", "parameters": {...}}}.
For more information about Tavily’s capabilities, check out our API documentation and best practices.