Complete Tavily Tutorial: AI Search API for RAG and AI Agents

# Tutorial Lengkap Tavily: AI Search API untuk RAG dan AI Agents Tavily adalah search API yang dirancang khusus untuk aplikasi AI, Large Language Models (LLM), dan Retrieval-Augmented Generation (RAG...

By Ruby Abdullah · · tutorial
TavilyRAGAI SearchLangChainAI Agents

Complete Tavily Tutorial: AI Search API for RAG and AI Agents

Tavily is a search API designed specifically for AI applications, Large Language Models (LLMs), and Retrieval-Augmented Generation (RAG). Unlike traditional search APIs like Google Custom Search or Bing API that return lists of URLs, Tavily optimizes search results for direct AI consumption — providing extracted, summarized content ready to be used as LLM context.

In this tutorial, we will learn how to use Tavily from installation, basic usage, integration with LangChain and LlamaIndex, to building powerful RAG applications using Tavily as a real-time knowledge source.

Why Tavily?

When building AI applications that require up-to-date information from the internet, developers face several challenges:

  • Traditional search APIs only return URLs and short snippets, requiring additional scraping
  • Web scraping requires high maintenance as website structures frequently change
  • Irrelevant context — general search results often contain ads, navigation, and irrelevant content
  • Token waste — sending too much irrelevant content to LLMs wastes tokens and increases costs
  • Tavily solves all these problems by providing:

    • Pre-extracted and cleaned search results
    • Content optimized for LLM consumption
    • Support for different search depths (basic and advanced)
    • Native integration with popular AI frameworks
    • Affordable pricing for production usage

    Installation

    Python SDK

    pip install tavily-python
    

    Node.js SDK

    npm install @tavily/core
    

    Getting Your API Key

  • Visit tavily.com and create an account
  • In the dashboard, copy your API key
  • Set it as an environment variable:
  • export TAVILYAPIKEY="tvly-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
    

    Or save it in a .env file:

    TAVILYAPIKEY=tvly-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    

    Tavily offers a free tier with 1,000 API calls per month, sufficient for development and prototyping.

    Basic Usage

    from tavily import TavilyClient
    
    

    client = TavilyClient(apikey="tvly-YOURAPIKEY")

    response = client.search("What is Retrieval Augmented Generation?")

    for result in response["results"]:

    print(f"Title: {result['title']}")

    print(f"URL: {result['url']}")

    print(f"Content: {result['content'][:200]}...")

    print("---")

    Response Structure

    {
    

    "query": "What is Retrieval Augmented Generation?",

    "followupquestions": None,

    "answer": None,

    "images": [],

    "results": [

    {

    "title": "What is RAG? - Retrieval-Augmented Generation Explained",

    "url": "https://example.com/rag-explained",

    "content": "Retrieval-Augmented Generation (RAG) is...",

    "score": 0.98,

    "rawcontent": None

    }

    ],

    "responsetime": 1.23

    }

    const { tavily } = require("@tavily/core");
    
    

    const client = tavily({ apiKey: "tvly-YOURAPIKEY" });

    async function search() {

    const response = await client.search("Latest developments in AI agents 2026");

    response.results.forEach(result => {

    console.log(Title: ${result.title});

    console.log(URL: ${result.url});

    console.log(Score: ${result.score});

    console.log("---");

    });

    }

    search();

    Search with Advanced Parameters

    from tavily import TavilyClient
    
    

    client = TavilyClient(apikey="tvly-YOURAPIKEY")

    response = client.search(

    query="machine learning model deployment best practices",

    searchdepth="advanced", # "basic" or "advanced"

    topic="general", # "general" or "news"

    maxresults=10, # number of results (default: 5)

    includedomains=["arxiv.org", "huggingface.co"], # domain filter

    excludedomains=["pinterest.com"], # exclude domain

    Related Articles

    LangChain Tutorial: The Most Popular Framework for Building LLM Applications

    Tutorial LangChain: Framework Paling Populer untuk Membangun Aplikasi LLM LangChain adalah framework open-source yang di...

    Composio Tutorial: Tool Integration Platform for AI Agents

    Tutorial Composio: Platform Integrasi Tool untuk AI Agents Composio adalah platform open-source yang memungkinkan AI age...

    Complete LangGraph Tutorial: Building Complex AI Agents

    Tutorial Lengkap LangGraph: Membangun AI Agents yang Kompleks LangGraph adalah library dari LangChain untuk membangun st...

    Marker Tutorial: Converting PDFs and Documents to Markdown for RAG Pipelines

    Tutorial Marker: Mengubah PDF dan Dokumen Menjadi Markdown untuk Pipeline RAG Dalam dunia AI dan data engineering, kemam...