Skip to main content

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.
Alternatively, you can specify which proxies to use by setting the TAVILY_HTTP_PROXY and TAVILY_HTTPS_PROXY variables in your environment file.

Project Tracking

You can attach a Project ID to your client to organize and track API usage by project. This is useful when a single API key is used across multiple projects.
Alternatively, you can set the TAVILY_PROJECT environment variable:
All requests made with this client will include the Project ID, allowing you to filter by project in the /logs endpoint and platform usage dashboard.

Session Tracking

You can attach session and user identifiers to your client for attribution and analytics across multi-step interactions and agent workflows. Each ID is sent as an HTTP header (X-Session-Id, X-Human-Id) on every request the client makes — across search, extract, crawl, and map.
You can also override either value on a per-call basis:
For security, Tavily hashes human IDs before processing or storing them. See Session Tracking in the API reference for the underlying header contract.
NEW! Try our interactive API Playground to see each parameter in action, and generate ready-to-use JavaScript snippets.
You can access Tavily Search in JavaScript through the client’s search function.

Parameters

Response format

The response object you receive will be in the following format:

Results

Each result in the results list will be in the following Result format:

Image Results

Each image in the images list will be in the following ImageResult format:

Example

Exact Match Example

Use exactMatch with quoted phrases in your query to find results containing a specific name or phrase verbatim:

Tavily Extract

You can access Tavily Extract in JavaScript through the client’s extract function.

Parameters

Response format

The response object you receive will be in the following format:

Successful Results

Each successful result in the results list will be in the following SuccessfulResult format:

Failed Results

Each failed result in the results list will be in the following FailedResult format:

Example

Tavily Crawl

You can access Tavily Crawl in JavaScript through the client’s crawl function.

Parameters

Response format

The response object you receive will be in the following format:

Results

Each successful result in the results list will be in the following Result format:

Example

Tavily Map

You can access Tavily Map in JavaScript through the client’s map function.

Parameters

Response format

The response object you receive will be in the following format:

Example