Tavily
The @mastra/tavily package wraps the Tavily API as Mastra-compatible tools. It exposes factory functions for search, extract, crawl, and map. Each function returns a tool created with createTool() that includes full Zod input/output schemas.
InstallationInstallation的直接链接
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/tavily @tavily/core zod
pnpm add @mastra/tavily @tavily/core zod
yarn add @mastra/tavily @tavily/core zod
bun add @mastra/tavily @tavily/core zod
Quick startQuick start的直接链接
Use createTavilyTools() to get all four tools with shared configuration:
import { createTavilyTools } from '@mastra/tavily'
const tools = createTavilyTools()
// Or pass an explicit API key:
// const tools = createTavilyTools({ apiKey: 'tvly-...' })
Each tool can also be created individually:
import { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily'
const searchTool = createTavilySearchTool()
const extractTool = createTavilyExtractTool({ apiKey: 'tvly-...' })
By default, all tools read TAVILY_API_KEY from the environment. You can pass { apiKey } explicitly to override.
ConfigurationConfiguration的直接链接
All factory functions accept TavilyClientOptions from @tavily/core:
apiKey?:
TAVILY_API_KEY environment variable.clientName?:
X-Client-Name header.apiBaseURL?:
proxies?:
projectId?:
createTavilyTools()createtavilytools的直接链接
Returns an object containing all four tools with a shared configuration.
import { createTavilyTools } from '@mastra/tavily'
const tools = createTavilyTools({ apiKey: 'tvly-...' })
// tools.tavilySearch, tools.tavilyExtract, tools.tavilyCrawl, tools.tavilyMap
Returns: { tavilySearch, tavilyExtract, tavilyCrawl, tavilyMap }
createTavilySearchTool()createtavilysearchtool的直接链接
Creates a tool that searches the web using Tavily. Returns relevant results with content snippets, optional AI-generated answers, and images.
Tool ID: tavily-search
import { createTavilySearchTool } from '@mastra/tavily'
const searchTool = createTavilySearchTool()
InputInput的直接链接
query:
searchDepth?:
maxResults?:
includeAnswer?:
includeImages?:
includeImageDescriptions?:
includeRawContent?:
includeDomains?:
excludeDomains?:
timeRange?:
OutputOutput的直接链接
query:
answer?:
images?:
results:
title:
url:
content:
score:
rawContent?:
responseTime:
createTavilyExtractTool()createtavilyextracttool的直接链接
Creates a tool that extracts content from one or more URLs. Returns raw page content in markdown or text format with up to 20 URLs per request.
Tool ID: tavily-extract
import { createTavilyExtractTool } from '@mastra/tavily'
const extractTool = createTavilyExtractTool()
InputInput的直接链接
urls:
extractDepth?:
query?:
includeImages?:
format?:
OutputOutput的直接链接
results:
url:
rawContent:
images?:
failedResults:
url:
error:
responseTime:
createTavilyCrawlTool()createtavilycrawltool的直接链接
Creates a tool that crawls a website starting from a URL. Extracts content from discovered pages with configurable depth, breadth, and domain constraints.
Tool ID: tavily-crawl
import { createTavilyCrawlTool } from '@mastra/tavily'
const crawlTool = createTavilyCrawlTool()
InputInput的直接链接
url:
maxDepth?:
maxBreadth?:
limit?:
instructions?:
selectPaths?:
selectDomains?:
excludePaths?:
excludeDomains?:
allowExternal?:
extractDepth?:
includeImages?:
format?:
OutputOutput的直接链接
baseUrl:
results:
url:
rawContent:
images?:
responseTime:
createTavilyMapTool()createtavilymaptool的直接链接
Creates a tool that maps a website's structure starting from a URL. Discovers and returns a list of URLs without extracting page content. Use this to understand site structure before targeted extraction.
Tool ID: tavily-map
import { createTavilyMapTool } from '@mastra/tavily'
const mapTool = createTavilyMapTool()
InputInput的直接链接
url:
maxDepth?:
maxBreadth?:
limit?:
instructions?:
selectPaths?:
selectDomains?:
excludePaths?:
excludeDomains?:
allowExternal?:
OutputOutput的直接链接
baseUrl:
results:
responseTime:
Agent exampleAgent example的直接链接
The following example demonstrates a research agent that combines search and extract:
import { Agent } from '@mastra/core/agent'
import { createTavilySearchTool, createTavilyExtractTool } from '@mastra/tavily'
const agent = new Agent({
id: 'web-search-agent',
name: 'Web Search Agent',
model: 'anthropic/claude-sonnet-4-6',
instructions:
'You are a web search assistant. Use search tool to find relevant pages, then use extract tool to get full content from the best results.',
tools: {
search: createTavilySearchTool(),
extract: createTavilyExtractTool(),
},
})
Environment variablesEnvironment variables的直接链接
| Variable | Description |
|---|---|
TAVILY_API_KEY | Your Tavily API key. Used as the default when apiKey isn't passed to a factory function. |