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?"
    }
  ]
}
You should see a response with real-time information and source citations. For example: “The 2025 French Open men’s singles final was won by Carlos Alcaraz…” with a citations array, search results, and usage information. See the example response below!

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.