Step 1: Create a Perplexity Account
Navigate to perplexity.ai and create an account if you don't already have one. You can sign up using:
- Email and password
- Google account (OAuth)
- Apple ID
- Single Sign-On (SSO) for enterprise accounts
Note that having a Perplexity Pro subscription for the chat interface doesn't automatically grant API access - these are billed separately.
Step 2: Access the API Console
Once logged in to your Perplexity account, navigate to the API section: 1.Go to perplexity.ai/settings/api 2. Or click on your profile icon and select "API" from the dropdown menu 3. You may also access it directly at perplexity.ai/console
If you don't see the API option, you may need to:
- Verify your email address
- Complete your account profile
- Contact Perplexity support to enable API access for your account
Step 3: Set Up Billing
Before generating an API key, you must configure billing:
- Click on "Billing" or "Add Payment Method" in the API console
- Enter your credit card information
- Configure your billing preferences:
- Pay-as-you-go: Charged monthly based on usage
- Prepaid credits: Purchase credits in advance (may offer discounts)
- Set spending limits:
- Configure monthly maximum spending
- Enable alerts at different threshold levels (50%, 75%, 90%)
- Set up auto-recharge for prepaid credits (optional)
Step 4: Navigate to API Keys Section
In the API console, locate the "API Keys" tab or section. This interface will show:
- Any existing API keys you've created
- Key creation dates
- Last used timestamps
- Usage statistics per key
- Options to create, regenerate, or revoke keys
Step 5: Generate Your API Key
Click the "Generate New Key" or "Create API Key" button. You'll be prompted to:
- Name your key: Use descriptive names like "Production Search API", "Development Testing", or "Research Assistant Bot"
- Select model access: Choose which Perplexity models this key can access:
- pplx-7b-online: Smaller, faster model with internet access
- pplx-70b-online: Larger model with internet access
- pplx-7b-chat: Conversational model without internet
- pplx-70b-chat: Larger conversational model
- sonar-small-online: Latest small model with web search
- sonar-medium-online: Latest medium model with web search
- Set rate limits (optional): Configure custom rate limits for this specific key
Step 6: Save Your API Key Securely
Critical: Your API key will be displayed only once. Copy it immediately:
pplx-________________________________
Perplexity API keys typically start with "pplx-". Store your key securely using:
- Environment variables: PERPLEXITY_API_KEY or PPLX_API_KEY
- Secret management services (AWS Secrets Manager, Azure Key Vault)
- Encrypted configuration files
- Never hardcode in source code or expose in client-side applications
Step 7: Configure API Settings
Customize your API configuration:
-
Rate Limits:
- Requests per minute (RPM): Default varies by plan
- Requests per day: Set daily maximums
- Concurrent requests: Limit parallel API calls
-
Model Preferences:
- Default model selection
- Fallback models if primary is unavailable
- Temperature and parameter defaults
-
Security Settings:
- IP allowlisting (restrict to specific IP addresses)
- Domain restrictions for web applications
- Enable/disable specific endpoints
Step 8: Test Your API Key
Verify your key with a test request using curl:
curl https://api.perplexity.ai/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{
"model": "pplx-70b-online",
"messages": [
{
"role": "user",
"content": "What is the weather in San Francisco today?"
}
],
"stream": false
}'
Replace YOUR_API_KEY_HERE with your actual API key. A successful response will include Perplexity's answer with cited sources.
Step 9: Understand Pricing and Models
Perplexity uses a per-request pricing model: Model Pricing Tiers (subject to change):
- Small models (pplx-7b, sonar-small): ~$0.20 per 1M tokens
- Medium models (sonar-medium): ~$0.60 per 1M tokens
- Large models (pplx-70b, sonar-large): ~$1.00 per 1M tokens
- Online models: Include real-time web search at no extra cost
Special Features:
- Internet access included in "online" models
- Source citations provided automatically
- No additional charges for web searches
Step 10: Implement Best Practices
Optimize for Perplexity's strengths:
- Use online models for current information queries
- Leverage built-in citation features for research applications
- Implement caching for repeated queries
- Use streaming for real-time user interfaces
Request optimization:
import os
import requests
headers = {
"Authorization": f"Bearer {os.getenv('PERPLEXITY_API_KEY')}",
"Content-Type": "application/json"
}
payload = {
"model": "sonar-medium-online",
"messages": [{"role": "user", "content": "Your query here"}],
"temperature": 0.2, # Lower for factual accuracy
"max_tokens": 1000,
"stream": False,
"return_citations": True # Ensure sources are included
}
Security Guidelines
Protect your Perplexity API keys:
- Rotate regularly: Generate new keys every 60-90 days
- Use separate keys: Different keys for development, staging, and production
- Monitor usage: Check for unusual patterns or unexpected spikes
- Implement rate limiting: Add client-side throttling to prevent abuse
- Audit access: Regularly review who has access to your API keys
Managing Team Access
For organizations:
- Create project-specific keys: Separate keys for different applications
- Assign ownership: Designate key owners responsible for rotation
- Document usage: Maintain records of which services use which keys
- Centralized management: Use a single dashboard for all key management
- Access logs: Enable logging to track key usage by team members
Monitoring and Analytics
Track your API usage effectively:
-
Perplexity Dashboard:
- Real-time usage statistics
- Model-specific breakdowns
- Cost tracking and projections
- Error rate monitoring
-
Custom monitoring:
- Implement logging in your application
- Track response times and latency
- Monitor citation quality and relevance
- Analyze search query patterns
-
Set up alerts for:
- Approaching rate limits
- Unusual usage patterns
- High error rates
- Budget thresholds
Troubleshooting Common Issues
"Invalid API key" error:
- Verify the key is correctly formatted with "Bearer " prefix
- Check if the key has been revoked or regenerated
- Ensure billing is active and current
"Rate limit exceeded" error:
- Check your current rate limits in the console
- Implement exponential backoff retry logic
- Consider upgrading your plan for higher limits
- Distribute requests over time to avoid bursts
"Model not available" error:
- Verify your key has access to the requested model
- Check model name spelling (e.g., "pplx-70b-online" not "pplx-70b")
- Ensure the model is available in your region
Empty or no citations:
- Use "online" model variants for web search capabilities
- Ensure return_citations is set to true
- Check that queries benefit from web search context
Advanced Features
Streaming responses:
import requests
import json
response = requests.post(
'https://api.perplexity.ai/chat/completions',
headers=headers,
json={
"model": "sonar-medium-online",
"messages": messages,
"stream": True
},
stream=True
)
for line in response.iter_lines():
if line:
# Process streaming chunks
data = json.loads(line.decode('utf-8').replace('data: ', ''))
Custom search parameters:
- Configure search depth and breadth
- Specify domains to include or exclude
- Set recency requirements for sources
- Define language preferences for results
Migration from Other Providers
Key differences when switching to Perplexity:
- Built-in web search: No need for separate search API integration
- Automatic citations: Sources included without extra configuration
- Different model names: Use Perplexity-specific model identifiers
- Simplified pricing: Per-request rather than token-based for some models
- Real-time information: Strength in current events and recent data
Use Cases and Applications
Perplexity API excels at:
- Research assistants: Academic and market research tools
- Fact-checking systems: Verify claims with cited sources
- Content generation: Articles with automatic source attribution
- Customer support: Answer questions with up-to-date information
- Educational tools: Provide learning content with references
- News aggregation: Summarize current events with sources
Next Steps
With your API key ready:
- Review the official Perplexity API documentation
- Explore different models to find the best fit for your use case
- Implement proper error handling and retry logic
- Set up comprehensive logging and monitoring
- Test citation quality and relevance for your domain
- Consider hybrid approaches using both online and offline models
Additional Resources
- Join the Perplexity developer community on Discord
- Review example implementations on GitHub
- Subscribe to the Perplexity API changelog for updates
- Explore webhook integration for async operations
- Check the status page for API availability and incidents
Compliance and Best Practices
When using Perplexity API:
- Always display citations when presenting information to end users
- Respect source website robots.txt and terms of service
- Implement appropriate content filtering for your use case
- Follow rate limits to ensure service availability
- Cache responses appropriately to minimize redundant queries
- Monitor and handle edge cases where web search might fail
Remember that Perplexity's strength lies in providing accurate, up-to-date information with sources. Design your applications to leverage these unique capabilities, particularly for use cases requiring current information and verifiable facts.
Ready to get started?
Scale your integration strategy and deliver the integrations your customers need in record time.