Tutorials

Free, Unlimited Perplexity AI API

This tutorial shows you how to leverage Puter.js to access Perplexity AI's specialized language models without any API keys or usage limits. Puter.js is completely free and open-source, allowing you to harness Perplexity AI's research-oriented capabilities directly in your applications. Using Puter.js, you can access Perplexity's Sonar models and reasoning engines straight from your frontend code with zero server setup.

Puter is the pioneer of the "User Pays" model, which allows developers to integrate AI capabilities into their applications while each user covers their own resource consumption. This model removes the burden of API key management and billing from developers, making sophisticated AI tools practically free for apps and websites.

Getting Started

Puter.js works without any API keys or account setup. To start using Puter.js, add the following script tag to your HTML file, in either the <head> or <body> section:

<script src="https://js.puter.com/v2/"></script>

Nothing more is needed to access Perplexity AI models through Puter.js. No API keys, no registration, no configuration.

Example 1Research with Perplexity Sonar

To perform research using Perplexity's Sonar model, use the puter.ai.chat() function:

puter.ai.chat("What are the latest developments in quantum computing research?", { model: "perplexity/sonar" })
    .then(response => {
        puter.print(response);
    });

Full example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat("What are the latest developments in quantum computing research?", { model: "perplexity/sonar" })
            .then(response => {
                puter.print(response);
            });
    </script>
</body>
</html>

Example 2Deep Research with Sonar Deep Research

Perplexity's deep research model provides comprehensive analysis for complex topics:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Analyze the environmental impact of electric vehicle adoption over the next decade", 
            { model: "perplexity/sonar-deep-research" }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

This example demonstrates Perplexity's ability to conduct thorough research and provide detailed analysis on complex topics with multiple facets.

Example 3Professional Research with Sonar Pro

For professional-grade research capabilities, use Sonar Pro:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "Provide a comprehensive market analysis for renewable energy investments in emerging markets", 
            { model: "perplexity/sonar-pro" }
        ).then(response => {
            puter.print(response);
        });
    </script>
</body>
</html>

This showcases Perplexity's professional research capabilities, ideal for business analysis and strategic planning.

Example 4Different Perplexity Models

You can access various Perplexity models using the model parameter:


// Using R1-1776 model
puter.ai.chat(
    "Explain the historical significance of the year 1776 and its modern implications",
    { model: "perplexity/r1-1776" }
).then(response => {
    puter.print(response);
});

// Using Sonar Reasoning model
puter.ai.chat(
    "What logical steps would you take to solve climate change?",
    { model: "perplexity/sonar-reasoning" }
).then(response => {
    puter.print(response);
});

// Using Sonar Reasoning Pro model
puter.ai.chat(
    "Develop a logical framework for evaluating artificial intelligence safety measures",
    { model: "perplexity/sonar-reasoning-pro" }
).then(response => {
    puter.print(response);
});

Complete example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        // Using R1-1776 model
        puter.ai.chat(
            "Explain the historical significance of the year 1776 and its modern implications",
            { model: "perplexity/r1-1776" }
        ).then(response => {
            puter.print("<h2>Using R1-1776 model</h2>");
            puter.print(response);
        });

        // Using Sonar Reasoning model
        puter.ai.chat(
            "What logical steps would you take to solve climate change?",
            { model: "perplexity/sonar-reasoning" }
        ).then(response => {
            puter.print("<h2>Using Sonar Reasoning model</h2>");
            puter.print(response);
        });

        // Using Sonar Reasoning Pro model
        puter.ai.chat(
            "Develop a logical framework for evaluating artificial intelligence safety measures",
            { model: "perplexity/sonar-reasoning-pro" }
        ).then(response => {
            puter.print("<h2>Using Sonar Reasoning Pro model</h2>");
            puter.print(response);
        });
    </script>
</body>
</html>

Example 5Streaming Research Results

For comprehensive research queries, use streaming to see results as they're generated:

async function streamResearch() {
    const response = await puter.ai.chat(
        "Conduct a thorough analysis of the global semiconductor supply chain and its vulnerabilities", 
        {
            stream: true,
            model: "perplexity/sonar-deep-research"
        }
    );
    
    for await (const part of response) {
        puter.print(part?.text);
    }
}

streamResearch();

Full example:

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        async function streamResearch() {
            const response = await puter.ai.chat(
                "Conduct a thorough analysis of the global semiconductor supply chain and its vulnerabilities", 
                {
                    stream: true,
                    model: "perplexity/sonar-deep-research"
                }
            );
            
            for await (const part of response) {
                puter.print(part?.text);
            }
        }

        streamResearch();
    </script>
</body>
</html>

Example 6Image Analysis

To analyze images, simply provide an image URL to puter.ai.chat():

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        puter.ai.chat(
            "What do you see in this image?",
            "https://assets.puter.site/doge.jpeg",
            { model: 'perplexity/sonar' }
        ).then(response => {
            document.write(response);
        });
    </script>
</body>
</html>

Available Perplexity Models

The following Perplexity AI models are accessible through Puter.js:

perplexity/r1-1776
perplexity/sonar
perplexity/sonar-deep-research
perplexity/sonar-pro
perplexity/sonar-reasoning
perplexity/sonar-reasoning-pro



Perfect! You now have unlimited access to Perplexity AI's research-focused language models through Puter.js. This enables you to build applications with powerful research and reasoning capabilities without managing API keys or backend infrastructure. From market analysis to scientific research, Perplexity's models excel at providing well-researched, factual responses directly in your frontend applications!

Related

Free, Serverless AI and Cloud

Start creating powerful web applications with Puter.js in seconds!

Get Started Now

Read the Docs Try the Playground