Perplexity API

ai-ml perplexity

Perplexity API

Online LLM API with real-time web search and cited answers.

Quick Facts

FieldValue
ProviderPerplexity
CategoryAI & Machine Learning APIs
Websitehttps://perplexity.ai
AuthenticationAPI Key
Pricing Modelusage-based
Free TierLimited free credits for new users
Rate Limit60 req/min (varies by model)

Overview

Perplexity API is a ai & machine learning apis provided by Perplexity. Online LLM API with real-time web search and cited answers. This API is designed to help developers integrate ai-ml capabilities into their applications with minimal setup and maximum reliability.

The API supports API Key authentication, ensuring secure access to all endpoints. With a usage-based pricing model, Perplexity offers flexible options for projects of any size, from prototypes to enterprise deployments.

Perplexity maintains comprehensive documentation, SDKs for popular programming languages, and active community support. The API is built on REST principles, returning JSON responses with standard HTTP status codes, making it straightforward to integrate into existing workflows.

Authentication

This API uses API Key authentication. Send your API key in the request header or as a query parameter. The exact method depends on the API specification.

Always store your credentials securely using environment variables or a secrets manager. Never commit API keys to version control or expose them in client-side code.

Code Samples

Python

import requests
import os

API_KEY = os.environ.get("API_KEY", "YOUR_API_KEY")
BASE_URL = "https://api.perplexity.ai"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

response = requests.get(f"{BASE_URL}/v1/resources", headers=headers)
print(response.status_code)
print(response.json())

JavaScript

const API_KEY = process.env.API_KEY || 'YOUR_API_KEY';
const BASE_URL = 'https://api.perplexity.ai';

const response = await fetch(`${BASE_URL}/v1/resources`, {
  headers: {
    'Authorization': `Bearer ${API_KEY}`,
    'Content-Type': 'application/json'
  }
});
const data = await response.json();
console.log(data);

cURL

curl -H "Authorization: Bearer $API_KEY" \
     -H "Content-Type: application/json" \
     https://api.perplexity.ai/v1/resources

Go

package main

import (
    "net/http"
    "fmt"
    "io"
    "os"
)

func main() {
    apiKey := os.Getenv("API_KEY")
    if apiKey == "" {
        apiKey = "YOUR_API_KEY"
    }
    req, _ := http.NewRequest("GET", "https://api.perplexity.ai/v1/resources", nil)
    req.Header.Set("Authorization", "Bearer " + apiKey)
    req.Header.Set("Content-Type", "application/json")
    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()
    body, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body))
}

Pricing

The pricing model is usage-based. Pay only for what you use, with pricing based on API calls, tokens, or compute time. Visit the provider’s pricing page at https://perplexity.ai for current rates and detailed pricing information.

Use Cases

  • Integration: Connect Perplexity services to your application for seamless ai-ml functionality.
  • Automation: Automate ai-ml workflows and reduce manual operations.
  • Scaling: Handle growing ai-ml demands with Perplexity’s robust infrastructure.

Further Reading

Other languages