Monitor your Perplexity API calls by logging requests and responses asynchronously. Track metrics like cost, duration, and performance for Perplexity’s search-augmented models.
Copy
import requestsurl = "https://api.keywordsai.co/api/request-logs/create/"payload = { "model": "llama-3.1-sonar-small-128k-online", "prompt_messages": [ { "role": "user", "content": "What are the latest developments in AI?" } ], "completion_message": { "role": "assistant", "content": "Recent AI developments include advances in large language models..." }, "cost": 0.0008, "generation_time": 4.2, "customer_params": { "customer_identifier": "user_404" }}headers = { "Authorization": "Bearer YOUR_KEYWORDS_AI_API_KEY", "Content-Type": "application/json"}response = requests.post(url, headers=headers, json=payload)