Perplexity
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/perplexity-ai
Example fetch requestcurl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/perplexity-ai/chat/completions \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --header 'Authorization: Bearer {perplexity_token}' \ --data '{ "model": "mistral-7b-instruct", "messages": [ { "role": "user", "content": "What is Cloudflare?" } ] }'
Perplexity doesn’t have their own SDK, but they have compatibility with the OpenAI SDK. You can use the OpenAI SDK to make a Perplexity call through AI Gateway as follows:
index.jsimport OpenAI from "openai";
const perplexity = new OpenAI({ apiKey: env.PERPLEXITY_API_KEY, baseURL: "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_slug}/perplexity-ai"
});
const chatCompletion = await perplexity.chat.completions.create({ model: "mistral-7b-instruct", messages: [{role: "user", content: "What is Cloudflare?"}], max_tokens: 20,
});