How do I set up the Perplexity action to work well?

Hoping someone can help me here. I have a Pro Perplexity subscription - I generated an API key and connected it via the action in the action library…

When I search via perplexity on the desktop, I get a comprehensive and correct/factual answer, but when I ask my tool the same question, it comes back with ‘I can’t find the answer’… Am I missing something here?

I have a rule in my Pickaxe that if the knowledge base doesn’t provide an answer, then search with perplexity.

Thanks in advance.

@nathaniel check this out :eyes:

Further testing of this and it still doesn’t pull through anything useful form perplexity. I’ve switched the action back to Google and this works fine!

My preference would be to get Perplexity working as on the desktop, it givers a higher quality result.

Is anyone else getting an issue with the Perplexity Action?

Hi @ecaveo can you do a screen recording or take some screenshots of the issue with the Perplexity action? It will definitely help with diagnosing the issue.

Hi @Ned.Malki I have PM’d Screenshots.

1 Like

Hey @ecaveo thanks for sharing. I forwarded it to the Dev team for diagnosis.

Any update on this - its still not working for me.


This happens for me too. We are trying to use Perplexity for the most recent searches, the pickaxe tries, then fails, then uses Google Search (and doesn’t return the most recent search results)

Note: I am using Sonar Pro

   perplexity_api_key = os.environ["PERPLEXITY_SONAR_API_KEY"]


    url = "https://api.perplexity.ai/chat/completions"

    payload = {
        "model": "sonar-pro",
        "messages": [
            {
                "role": "system",
                "content": "Be precise and concise."

This code works:

import os
import requests
import json

def answer_with_perplexity_copy(query: str):
    """
    If a user prompt requires a search, to verify facts, or include references, use Perplexity to retrieve the information and reference URLs.

    Args:
        query (string): The query for perplexity. It can be in natural language.
    Envs:
        PERPLEXITY_SONAR_API_KEY (string): API key from Perplexity
    """

    # Insert your PYTHON code below. You can access environment variables using os.environ[].
    # Currently, only the requests library is supported, but more libraries will be available soon.
    # Use print statements or return values to display results to the user.
    # If you save a png, pdf, csv, jpg, webp, gif, or html file in the root directory, it will be automatically displayed to the user.
    # You do not have to call this function as the bot will automatically call and fill in the parameters.


    perplexity_api_key = os.environ["PERPLEXITY_SONAR_API_KEY"]
    if not perplexity_api_key:
        return "Error: API key is missing or empty. Please check your environment variables."
    
    url = "https://api.perplexity.ai/chat/completions"
    payload = {
        "model": "sonar-pro",
        "messages": [
            {
                "role": "system",
                "content": "Be precise and concise."
            },
            {
                "role": "user",
                "content": query
            }
        ],
        "temperature": 0.2,
        "top_p": 0.9,
        "search_domain_filter": [],  # Removed limitation to just perplexity.ai
        "search": True,  # Explicitly enable search
        "return_urls": True,  # Make sure to return URLs
        "return_images": False,
        "return_related_questions": False,
        "search_recency_filter": "month",
        "top_k": 0,
        "stream": False,
        "presence_penalty": 0,
        "frequency_penalty": 1
    }
    
    headers = {
        "Authorization": f"Bearer {perplexity_api_key}",
        "Content-Type": "application/json"
    }
    
    try:
        response = requests.post(url, json=payload, headers=headers)
        response.raise_for_status()  # Raise exception for 4XX/5XX responses
        
        data = response.json()
        
        # Format and return the result with sources
        if "choices" in data and data["choices"]:
            answer = data["choices"][0]["message"]["content"]
            
            # Extract and format sources if available
            sources = []
            if "urls" in data and data["urls"]:
                sources = [f"- {url}" for url in data["urls"]]
            
            result = answer
            if sources:
                result += "\n\nSources:\n" + "\n".join(sources)
            
            return result
        else:
            return "Error: Unexpected response format from Perplexity API."
            
    except requests.exceptions.RequestException as e:
        return f"Error connecting to Perplexity API: {str(e)}"
    except json.JSONDecodeError:
        return "Error: Could not parse the API response."
    except Exception as e:
        return f"Unexpected error: {str(e)}"
2 Likes

the existing perplexity action doest work. It doesnt return the latest info upon searching. When will this be fixed?

complicated for non-technical.Mind telling how to use?