Instantiating a client
To interact with Tavily in JavaScript, you must instatiate a client with your API key. Our client is asynchronous by default. Once you have instantiated a client, call one of our supported methods (detailed below) to access the API.Proxies
If you would like to specify a proxy to be used when making requests, you can do so by passing in a proxy parameter on client instantiation. Proxy configuration is available in both the synchronous and asynchronous clients.TAVILY_HTTP_PROXY and TAVILY_HTTPS_PROXY variables in your environment file.
Tavily Search
You can access Tavily Search in JavaScript through the client’ssearch function.
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
query (required) | string | The query to run a search on. | — |
auto_parameters | boolean | When auto_parameters is enabled, Tavily automatically configures search parameters based on your query’s content and intent. You can still set other parameters manually, and your explicit values will override the automatic ones. The parameters include_answer, include_raw_content, and max_results must always be set manually, as they directly affect response size. Note: search_depth may be automatically set to advanced when it’s likely to improve results. This uses 2 API credits per request. To avoid the extra cost, you can explicitly set search_depth to basic. | false |
searchDepth | string | The depth of the search. It can be "basic" or "advanced". "advanced" search is tailored to retrieve the most relevant sources and content snippets for your query, while "basic" search provides generic content snippets from each source. | "basic" |
topic | string | The category of the search. Determines which agent will be used. Supported values are "general" , "news" and "finance". | "general" |
timeRange | string | The time range back from the current date based on publish date or last updated date. Accepted values include "day", "week", "month", "year" or shorthand values "d", "w", "m", "y". | — |
startDate | string | Will return all results after the specified start date based on publish date or last updated date. Required to be written in the format YYYY-MM-DD | — |
endDate | string | Will return all results before the specified end date based on publish date or last updated date. Required to be written in the format YYYY-MM-DD. | — |
maxResults | number | The maximum number of search results to return. It must be between 0 and 20. | 5 |
chunksPerSource | number | Chunks are short content snippets (maximum 500 characters each) pulled directly from the source. Use chunksPerSource to define the maximum number of relevant chunks returned per source and to control the content length. Chunks will appear in the content field as: <chunk 1> [...] <chunk 2> [...] <chunk 3>. Available only when searchDepth is "advanced". | 3 |
includeImages | boolean | Include a list of query-related images in the response. | false |
includeImageDescriptions | boolean | Include a list of query-related images and their descriptions in the response. | false |
includeAnswer | boolean or string | Include an answer to the query generated by an LLM based on search results. A "basic" (or true) answer is quick but less detailed; an "advanced" answer is more detailed. | false |
includeRawContent | boolean or string | Include the cleaned and parsed HTML content of each search result. "markdown" or True returns search result content in markdown format. "text" returns the plain text from the results and may increase latency. | False |
includeDomains | string[] | A list of domains to specifically include in the search results. Maximum 300 domains. | [] |
excludeDomains | string[] | A list of domains to specifically exclude from the search results. Maximum 150 domains. | [] |
country | string | Boost search results from a specific country. This will prioritize content from the selected country in the search results. Available only if topic is general. | — |
timeout | number | A timeout to be used in requests to the Tavily API. | 60 |
includeFavicon | boolean | Whether to include the favicon URL for each result. | false |
includeUsage | boolean | Whether to include credit usage information in the response. | false |
Response format
The response object you receive will be in the following format:| Key | Type | Description |
|---|---|---|
results | Result[] | A list of sorted search results ranked by relevancy. |
query | string | Your search query. |
responseTime | number | Your search result response time. |
requestId | string | A unique request identifier you can share with customer support to help resolve issues with specific requests. |
answer (optional) | string | The answer to your search query, generated by an LLM based on Tavily’s search results. This is only available if includeAnswer is set to true. |
images (optional) | string[] or ImageResult[] | This is only available if includeImages is set to true. A list of query-related image URLs. If includeImageDescriptions is set to true, each entry will be an ImageResult. |
favicon (optional) | string | The favicon URL for the search result. |
Results
Each result in theresults list will be in the following Result format:
| Key | Type | Description |
|---|---|---|
title | string | The title of the search result. |
url | string | The URL of the search result. |
content | string | The most query-related content from the scraped URL. Tavily uses proprietary AI to extract the most relevant content based on context quality and size. |
score | float | The relevance score of the search result. |
rawContent (optional) | string | The parsed and cleaned HTML content of the site. This is only available if includeRawContent is set to true. |
publishedDate (optional) | string | The publication date of the source. This is only available if the search topic is set to news. |
favicon (optional) | string | ”The favicon URL for the result. |
Image Results
Each image in theimages list will be in the following ImageResult format:
| Key | Type | Description |
|---|---|---|
url | string | The URL of the image. |
description (optional) | string | This is only available if includeImageDescriptions is set to true. An LLM-generated description of the image. |
Example
Request
Request
Response
Response
Tavily Extract
You can access Tavily Extract in JavaScript through the client’sextract function.
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
urls (required) | string[] | The URLs you want to extract. The list must not contain more than 20 URLs. | — |
includeImages | boolean | Include a list of images extracted from the URLs in the response. | false |
extractDepth | string | The depth of the extraction process. You may experience higher latency with "advanced" extraction, but it offers a higher success rate and retrieves more data from the URL (e.g., tables, embedded content). "basic" extraction costs 1 API Credit per 5 successful URL extractions, while "advanced" extraction costs 2 API Credits per 5 successful URL extractions. | "basic" |
format | str | The format of the extracted web page content. "markdown" returns content in markdown format. "text" returns plain text and may increase latency. | "markdown" |
timeout | number | A timeout to be used in requests to the Tavily API. Maximum time in seconds to wait for the URL extraction before timing out. Must be between 1.0 and 60.0 seconds. If not specified, default timeouts are applied based on extract_depth: 10 seconds for basic extraction and 30 seconds for advanced extraction. | None |
includeFavicon | boolean | Whether to include the favicon URL for each result. | false |
includeUsage | boolean | Whether to include credit usage information in the response.NOTE:The value may be 0 if the total successful URL extractions has not yet reached 5 calls. See our Credits & Pricing documentation for details. | false |
query | string | User intent for reranking extracted content chunks. When provided, chunks are reranked based on relevance to this query. | — |
chunksPerSource | number | Chunks are short content snippets (maximum 500 characters each) pulled directly from the source. Use chunksPerSource to define the maximum number of relevant chunks returned per source and to control the rawContent length. Chunks will appear in the rawContent field as: <chunk 1> [...] <chunk 2> [...] <chunk 3>. Available only when query is provided. Must be between 1 and 5. | 3 |
Response format
The response object you receive will be in the following format:| Key | Type | Description |
|---|---|---|
results | SuccessfulResult[] | A list of extracted content. |
failed_results | FailedResult[] | A list of URLs that could not be processed. |
response_time | number | The search result response time. |
requestId | string | A unique request identifier you can share with customer support to help resolve issues with specific requests. |
Successful Results
Each successful result in theresults list will be in the following SuccessfulResult format:
| Key | Type | Description |
|---|---|---|
url | string | The URL of the webpage. |
raw_content | string | The raw content extracted. When query is provided, contains the top-ranked chunks joined by [...] separator. |
images (optional) | string[] | This is only available if includeImages is set to true. A list of extracted image URLs. |
favicon (optional) | string | The favicon URL for the result. |
Failed Results
Each failed result in theresults list will be in the following FailedResult format:
| Key | Type | Description |
|---|---|---|
url | string | The URL that failed. |
error | string | An error message describing why it could not be processed. |
Example
Request
Request
Response
Response
Tavily Crawl
You can access Tavily Crawl in JavaScript through the client’scrawl function.
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
url (required) | string | The root URL to begin the crawl. | — |
maxDepth | number | Max depth of the crawl. Defines how far from the base URL the crawler can explore. | 1 |
maxBreadth | number | Max number of links to follow per level of the tree (i.e., per page). | 20 |
limit | number | Total number of links the crawler will process before stopping. | 50 |
instructions | string | Natural language instructions for the crawler. | — |
selectPaths | string[] | Regex patterns to select only URLs with specific path patterns (e.g., "/docs/.*", "/api/v1.*"). | [] |
selectDomains | string[] | Regex patterns to select crawling to specific domains or subdomains (e.g., "^docs\.example\.com$"). | [] |
excludePaths | string[] | Regex patterns to exclude URLs with specific path patterns (e.g., "/admin/.*", "/private/.*"). | [] |
excludeDomains | string[] | Regex patterns to exclude specific domains or subdomains from crawling (e.g., "^admin\.example\.com$"). | [] |
allowExternal | boolean | Whether to return links from external domains in crawl output. | true |
includeImages | boolean | Whether to extract image URLs from the crawled pages. | false |
extractDepth | string | Advanced extraction retrieves more data, including tables and embedded content, with higher success but may increase latency. Options: "basic" or "advanced". | "basic" |
format | str | The format of the extracted web page content. "markdown" returns content in markdown format. "text" returns plain text and may increase latency. | "markdown" |
timeout | number | Maximum time in seconds to wait for the crawl operation before timing out. Must be between 10 and 150 seconds. | 150 |
includeFavicon | boolean | Whether to include the favicon URL for each result. | false |
includeUsage | boolean | Whether to include credit usage information in the response.NOTE:The value may be 0 if the total use of /extract and /map calls has not yet reached minimum needed. See our Credits & Pricing documentation for details. | false |
chunksPerSource | number | Chunks are short content snippets (maximum 500 characters each) pulled directly from the source. Use chunksPerSource to define the maximum number of relevant chunks returned per source and to control the rawContent length. Chunks will appear in the rawContent field as: <chunk 1> [...] <chunk 2> [...] <chunk 3>. Must be between 1 and 5. | 3 |
Response format
The response object you receive will be in the following format:| Key | Type | Description |
|---|---|---|
baseUrl | string | The URL you started the crawl from. |
results | Result[] | A list of crawled pages. |
responseTime | number | The crawl response time. |
requestId | string | A unique request identifier you can share with customer support to help resolve issues with specific requests. |
Results
Each successful result in theresults list will be in the following Result format:
| Key | Type | Description |
|---|---|---|
url | string | The URL of the webpage. |
rawContent | string | The raw content extracted. |
images | string[] | Image URLs extracted from the page. |
favicon (optional) | string | The favicon URL for the result. |
Example
Request
Request
Response
Response
Tavily Map
You can access Tavily Map in JavaScript through the client’smap function.
Parameters
| Parameter | Type | Description | Default |
|---|---|---|---|
url (required) | string | The root URL to begin the mapping. | — |
maxDepth | number | Max depth of the mapping. Defines how far from the base URL the crawler can explore. | 1 |
maxBreadth | number | Max number of links to follow per level of the tree (i.e., per page). | 20 |
limit | number | Total number of links the crawler will process before stopping. | 50 |
instructions | string | Natural language instructions for the mapper. | — |
selectPaths | string[] | Regex patterns to select only URLs with specific path patterns (e.g., "/docs/.*", "/api/v1.*"). | [] |
selectDomains | string[] | Regex patterns to select crawling to specific domains or subdomains (e.g., "^docs\.example\.com$"). | [] |
excludePaths | string[] | Regex patterns to exclude URLs with specific path patterns (e.g., "/admin/.*", "/private/.*"). | [] |
excludeDomains | string[] | Regex patterns to exclude specific domains or subdomains from mapping (e.g., "^admin\.example\.com$"). | [] |
allowExternal | boolean | Whether to return links from external domains in crawl output. | true |
timeout | number | Maximum time in seconds to wait for the map operation before timing out. Must be between 10 and 150 seconds. | 150 |
includeUsage | boolean | Whether to include credit usage information in the response.NOTE:The value may be 0 if the total successful pages mapped has not yet reached 10 calls. See our Credits & Pricing documentation for details. | false |
Response format
The response object you receive will be in the following format:| Key | Type | Description |
|---|---|---|
baseUrl | string | The URL you started the crawl from. |
results | string[] | A list of URLs that were discovered during the mapping. |
responseTime | number | The crawl response time. |
requestId | string | A unique request identifier you can share with customer support to help resolve issues with specific requests. |
Example
Request
Request
Response
Response