Perplexity API Perl版

Perplexity APIメモ。
APIリファレンス
https://docs.perplexity.ai/reference/post_chat_completions
モデル
Perplexity Online Models
| Model | Parameter Count | Context Length | Model Type |
|---|---|---|---|
llama-3.1-sonar-small-128k-online |
8B | 127,072 | Chat Completion |
llama-3.1-sonar-large-128k-online |
70B | 127,072 | Chat Completion |
llama-3.1-sonar-huge-128k-online |
405B | 127,072 | Chat Completion |
Perplexity Chat Models
| Model | Parameter Count | Context Length | Model Type |
|---|---|---|---|
llama-3.1-sonar-small-128k-chat |
8B | 131,072 | Chat Completion |
llama-3.1-sonar-large-128k-chat |
70B | 131,072 | Chat Completion |
Open-Source Models
| Model | Parameter Count | Context Length | Model Type |
|---|---|---|---|
llama-3.1-8b-instruct |
8B | 131,072 | Chat Completion |
llama-3.1-70b-instruct |
70B | 131,072 | Chat Completion |
mixtral-8x7b-instruct があったんだけど、何故か表から消えている。
価格
Perplexity Online Models
| Model | Price/1000 requests | Price/1M tokens |
|---|---|---|
llama-3.1-sonar-small-128k-online |
$5 | $0.2 |
llama-3.1-sonar-large-128k-online |
$5 | $1 |
llama-3.1-sonar-huge-128k-online |
$5 | $5 |
Perplexity Chat Models
| Model | Price/1M tokens |
|---|---|
llama-3.1-sonar-small-128k-chat |
$0.2 |
llama-3.1-sonar-large-128k-chat |
$1 |
Open-Source Models
| Model | Price/1M tokens |
|---|---|
llama-3.1-8b-instruct |
$0.2 |
llama-3.1-70b-instruct |
$1 |
エンドポイント
ドキュメントにあるCURLのリクエストとレスポンス
リクエスト
curl --request POST \
--url https://api.perplexity.ai/chat/completions \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"model": "llama-3.1-sonar-small-128k-online",
"messages": [
{
"role": "system",
"content": "Be precise and concise."
},
{
"role": "user",
"content": "How many stars are there in our galaxy?"
}
]
}
'
レスポンス
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"model": "string",
"object": "string",
"created": 0,
"choices": [
{
"index": 0,
"finish_reason": "stop",
"message": {
"content": "string",
"role": "system"
},
"delta": {
"content": "string",
"role": "system"
}
}
],
"usage": {
"prompt_tokens": 0,
"completion_tokens": 0,
"total_tokens": 0
}
}
リクエスト形式、レスポンスのJSON構造は、ChatGPTとほぼ同じ。
リクエストボディには、以下も指定できる。
stream
max_tokens
frequency_penalty
temperature
top_p
top_k
presence_penalty
その他、申請すると引用や画像を返したりもできるっぽい。
続きを読むにはパスワードを入力してください。