Generating an API Key

Get your Sonar API Key

Navigate to the API Keys tab in the API Portal and generate a new key.
See the API Groups page to set up an API group.
OpenAI SDK Compatible: Perplexity’s API supports the OpenAI Chat Completions format. You can use OpenAI client libraries by pointing to our endpoint. See our OpenAI SDK Guide for examples.

Making Your First API Call

cURL is a command-line tool for making HTTP requests. Set your API key and run the command:
'export SONAR_API_KEY="your_api_key"

curl --location 'https://api.perplexity.ai/chat/completions' \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--header "Authorization: Bearer $SONAR_API_KEY" \
--data '{
  "model": "sonar-pro",
  "messages": [
    {
      "role": "user",
      "content": "What are the most popular open-source alternatives to OpenAIs GPT models?"
    }
  ]
}
For a full guide on streaming, including parsing, error handling, citation management, and best practices, see our streaming guide.

Next Steps

Now that you’ve made your first API call, here are some recommended next steps:
Need help? Check out our community for support and discussions with other developers.
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy