Tavily JavaScript SDK
Tavily's JavaScript SDK allows for easy interaction with the Tavily API, offering the full range of our search and extract functionalities directly from your JavaScript and TypeScript programs. Easily integrate smart search and content extraction capabilities into your applications, harnessing the powerful Tavily Search and Tavily Extract APIs.
Installing
npm i @tavily/core
Tavily Search
Connect your LLM to the web using the Tavily Search API. Tavily Search is a powerful search engine tailored for use by LLMs in agentic applications.
Usage
Below is a simple code snippet that shows you how to use Tavily Search. The different steps and components of this code are explained in more detail on the JavaScript API Reference page.
const { tavily } = require("@tavily/core");
const tvly = tavily({ apiKey: "tvly-YOUR_API_KEY" });
const response = await tvly.search("Who is Leo Messi?");
console.log(response);
To learn more about the different parameters, head to our JavaScript API Reference.
The Tavily Extract API allows you to effortlessly retrieve raw content from a list of websites, making it ideal for data collection, content analysis, and research. You can also combine Tavily Extract with our Search method: first, obtain a list of relevant documents, then perform further processing on selected links to gather additional information and use it as context for your research tasks.
Usage
Below is a simple code snippet demonstrating how to use Tavily Extract. The different steps and components of this code are explained in more detail on the JavaScript API Reference page.
const { tavily } = require("@tavily/core");
const tvly = tavily({ apiKey: "tvly-YOUR_API_KEY" });
const urls = [
"https://en.wikipedia.org/wiki/Artificial_intelligence",
"https://en.wikipedia.org/wiki/Machine_learning",
"https://en.wikipedia.org/wiki/Data_science",
"https://en.wikipedia.org/wiki/Quantum_computing",
"https://en.wikipedia.org/wiki/Climate_change",
];
response = await tvly.extract(urls);
for (let result of response.results) {
console.log(`URL: ${result.url}`);
console.log(`Raw Content: ${result.rawContent}\n`);
}
To learn more about the different parameters, head to our JavaScript API Reference.
Tavily Crawl (Open-Access Beta)
Tavily Crawl is an agent‐first site explorer that leverages breadth‐first crawling to navigate websites. It uses natural-language goals to intelligently uncover deeply buried “needle-in-a-haystack” information or perform high-volume data retrieval across an entire site.
Usage
Below is a simple code snippet demonstrating how to use Tavily Crawl. The different steps and components of this code are explained in more detail on the JavaScript API Reference page.
const { tavily } = require("@tavily/core");
const tvly = tavily({ apiKey: "tvly-YOUR_API_KEY" });
const start_url = "https://wikipedia.org/wiki/Lemon"
response = await tvly.crawl(start_url, {
max_depth: 3,
limit: 50,
instructions: "Find all pages on citrus fruits"
});
for (let result of response.results) {
console.log(`URL: ${result.url}`);
console.log(`Raw Content: ${result.rawContent.substring(0, 200)}...`);
}
Tavily Map (Open-Access Beta)
Map lets you discover and visualize the structure of a website starting from a base URL.
Usage
Below are some code snippets that demonstrate how to interact with our Map API. Each step and component of this code is explained in greater detail in the API Methods section below.
Mapping a website with instructions
const { tavily } = require("@tavily/core");
const tvly = tavily({ apiKey: "tvly-YOUR_API_KEY" });
const start_url = "https://wikipedia.org/wiki/Lemon"
response = await tvly.map(start_url, {
max_depth: 3,
limit: 50,
instructions: "Find all pages on citrus fruits"
});
for (let url of response.results) {
console.log(`URl: ${url}`);
}
To learn more about the different parameters, head to our JavaScript API Reference.
Additional Information
Proxies
If you want to use either client with specified HTTP or HTTPS proxies, you can do so by passing the proxies parameter as a dictionary in the format { http?: string, https?: string }
, where each key is optional, or by setting the TAVILY_HTTP_PROXY
or TAVILY_HTTPS_PROXY
environment variables.
Cost
Head to the API Credits Overview in our documentation to learn more about how many API Credits each request costs.
License
This project is licensed under the terms of the MIT license.
Contact
If you are encountering issues while using Tavily, please email us at support@tavily.com. We'll be happy to help you.
If you want to stay updated on the latest Tavily news and releases, head to our Developer Community to learn more!