PerplexitySearchTool

PerplexitySearchTool(
    model: str = 'sonar',
    api_key: str | None = None,
    max_tokens: int = 1000,
    search_domain_filter: list[str] | None = None
)

Tool for interacting with the Perplexity AI search API.
This tool uses the Perplexity API to perform web search, news search, and conversational search, returning concise and precise responses.
Attributes:
url (str): API endpoint URL.
model (str): Name of the model to be used.
api_key (str): API key for authenticating with the Perplexity API.
max_tokens (int): Maximum tokens allowed for the API response.
search_domain_filters (Optional[list[str]]): Optional list of domain filters for the search.
Initializes a new instance of the PerplexitySearchTool.

Parameters:
NameDescription
modelType: str

Default: ‘sonar’
api_keyType: str | None

Default: None
max_tokensType: int

Default: 1000
search_domain_filterType: list[str] | None

Default: None

Instance Methods

search(self, query: str) -> SearchResponse

Perform a search query using the Perplexity AI API.
Constructs the payload, executes the query, and parses the response to return a concise search result along with any provided citations.

Parameters:
NameDescription
queryThe search query.

Type: str
Returns:
TypeDescription
SearchResponseSearchResponse: A model containing the search result content and citations.