jpskill.com
🛠️ 開発・MCP コミュニティ

perplexity-api

最新情報に基づいたAI応答やファクトチェック、時事問題の解説など、LLMの学習範囲を超える知識が必要な場合に、リアルタイムなウェブ検索で情報を補強し、引用元も提示するSkill。

📜 元の英語説明(参考)

Perplexity API for real-time web-search-augmented LLM responses. Use when you need up-to-date information in AI responses, research assistants, fact-checking, current events coverage, or any task requiring knowledge beyond an LLM's training cutoff. Returns cited sources alongside answers.

🇯🇵 日本人クリエイター向け解説

一言でいうと

最新情報に基づいたAI応答やファクトチェック、時事問題の解説など、LLMの学習範囲を超える知識が必要な場合に、リアルタイムなウェブ検索で情報を補強し、引用元も提示するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o perplexity-api.zip https://jpskill.com/download/15249.zip && unzip -o perplexity-api.zip && rm perplexity-api.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/15249.zip -OutFile "$d\perplexity-api.zip"; Expand-Archive "$d\perplexity-api.zip" -DestinationPath $d -Force; ri "$d\perplexity-api.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して perplexity-api.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → perplexity-api フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Perplexity API

概要

Perplexity AI は、リアルタイムのウェブ検索によって拡張された LLM 推論を提供します。トレーニングデータに限定された標準的な LLM とは異なり、Perplexity のオンラインモデルは、すべてのクエリに対して最新のウェブ情報を取得し、合成します。応答には、ソース URL への引用が含まれます。この API は完全に OpenAI と互換性があります。カスタムの base_url を指定して openai SDK を使用してください。

セットアップ

pip install openai  # Perplexity は OpenAI 互換の API を使用します
export PERPLEXITY_API_KEY=pplx-...

利用可能なモデル

モデル タイプ 最適な用途
sonar オンライン 高速なウェブ拡張された回答
sonar-pro オンライン 深い調査、複雑なクエリ
sonar-reasoning オンライン ステップごとの推論 + 検索
sonar-reasoning-pro オンライン 高度な推論 + 深い検索
r1-1776 オフライン 検索なし、検閲なしの推論

オンラインモデル は、リクエストごとにウェブを検索します。オフラインモデル は、トレーニングデータのみを使用します。

指示

ウェブ検索による基本的なクエリ

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",  # or os.environ["PERPLEXITY_API_KEY"]
    base_url="https://api.perplexity.ai",
)

response = client.chat.completions.create(
    model="sonar",
    messages=[
        {
            "role": "system",
            "content": "正確かつ簡潔に。常にソースを引用してください。",
        },
        {
            "role": "user",
            "content": "今日の量子コンピューティングの最新の進展は何ですか?",
        },
    ],
)

print(response.choices[0].message.content)

引用へのアクセス

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

response = client.chat.completions.create(
    model="sonar-pro",
    messages=[{"role": "user", "content": "ビットコインの現在の価格はいくらですか?"}],
)

# メインの回答
print(response.choices[0].message.content)

# 引用は extra_fields / model_extra にあります
if hasattr(response, "citations"):
    for i, citation in enumerate(response.citations, 1):
        print(f"[{i}] {citation}")

# または model_extra 経由でアクセス
citations = getattr(response, "citations", [])
for url in citations:
    print(f"Source: {url}")

引用付きのストリーミング

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

stream = client.chat.completions.create(
    model="sonar",
    messages=[{"role": "user", "content": "今日のトップテクノロジーニュースを要約してください。"}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

sonar-pro による深い調査

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

# sonar-pro は、包括的な回答を得るためにより多くのウェブ検索を実行します
response = client.chat.completions.create(
    model="sonar-pro",
    messages=[
        {
            "role": "system",
            "content": "あなたはリサーチアナリストです。詳細で、十分な情報源に基づいた分析を提供してください。",
        },
        {
            "role": "user",
            "content": (
                "最近の法律や今後の提案を含め、AI規制の現状について世界的に包括的な分析を提供してください。"
            ),
        },
    ],
    max_tokens=2000,
)

print(response.choices[0].message.content)

sonar-reasoning による推論

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

# sonar-reasoning は思考の連鎖 + ウェブ検索を表示します
response = client.chat.completions.create(
    model="sonar-reasoning",
    messages=[
        {
            "role": "user",
            "content": (
                "現在の市場データに基づいて、NVIDIA 株と AMD 株のどちらに投資すべきですか?"
                "最近の収益と市場のトレンドを考慮してください。"
            ),
        }
    ],
)

print(response.choices[0].message.content)
# レスポンスには、推論プロセスを含む <think> ブロックが含まれます

複数ターンの調査セッション

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

messages = [
    {
        "role": "system",
        "content": "あなたは、現在のウェブ情報にアクセスできるリサーチアシスタントです。"
                   "常にソースを引用し、情報が時間の影響を受けやすい可能性がある場合は示してください。",
    }
]

def research_chat(user_message: str) -> str:
    messages.append({"role": "user", "content": user_message})

    response = client.chat.completions.create(
        model="sonar-pro",
        messages=messages,
    )

    answer = response.choices[0].message.content
    messages.append({"role": "assistant", "content": answer})
    return answer

# 複数ターンの調査
print(research_chat("2025年にモデルをリリースする主な AI ラボは何ですか?"))
print(research_chat("それらのモデルのうち、現在 API 経由で利用できるものはどれですか?"))
print(research_chat("100万トークンあたりの価格を比較してください。"))

レート制限とエラー処理

from openai import OpenAI, RateLimitError
import time

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

def search_with_retry(query: str, retries: int = 3) -> str:
    for attempt in range(retries):
        try:
            response = client.chat.completions.create(
                model="sonar",
                messages=[{"role": "user", "content": query}],
                timeout=30,
            )
            return response.choices[0].message.content
        except RateLimitError:
            wait = 2 ** attempt
            print(f"レート制限されました。{wait}秒後に再試行します...")
            time.sleep(wait)
    raise Exception("最大再試行回数を超えました")

オンラインモデルとオフラインモデル

機能 オンライン (sonar*) オフライン (r1-1776)
ウェブ検索 ✅ リアルタイム

(原文がここで切り詰められています)

📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Perplexity API

Overview

Perplexity AI provides LLM inference augmented with real-time web search. Unlike standard LLMs limited to training data, Perplexity's online models fetch and synthesize current web information on every query. Responses include citations to source URLs. The API is fully OpenAI-compatible — use the openai SDK with a custom base_url.

Setup

pip install openai  # Perplexity uses OpenAI-compatible API
export PERPLEXITY_API_KEY=pplx-...

Available Models

Model Type Best For
sonar Online Fast web-augmented answers
sonar-pro Online Deep research, complex queries
sonar-reasoning Online Step-by-step reasoning + search
sonar-reasoning-pro Online Advanced reasoning + deep search
r1-1776 Offline No search, uncensored reasoning

Online models search the web on every request. Offline models use only training data.

Instructions

Basic Query with Web Search

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",  # or os.environ["PERPLEXITY_API_KEY"]
    base_url="https://api.perplexity.ai",
)

response = client.chat.completions.create(
    model="sonar",
    messages=[
        {
            "role": "system",
            "content": "Be precise and concise. Always cite your sources.",
        },
        {
            "role": "user",
            "content": "What are the latest developments in quantum computing as of today?",
        },
    ],
)

print(response.choices[0].message.content)

Accessing Citations

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

response = client.chat.completions.create(
    model="sonar-pro",
    messages=[{"role": "user", "content": "What is the current price of Bitcoin?"}],
)

# Main answer
print(response.choices[0].message.content)

# Citations are in the extra_fields / model_extra
if hasattr(response, "citations"):
    for i, citation in enumerate(response.citations, 1):
        print(f"[{i}] {citation}")

# Or access via model_extra
citations = getattr(response, "citations", [])
for url in citations:
    print(f"Source: {url}")

Streaming with Citations

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

stream = client.chat.completions.create(
    model="sonar",
    messages=[{"role": "user", "content": "Summarize the top tech news today."}],
    stream=True,
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)
print()

Deep Research with sonar-pro

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

# sonar-pro performs more web searches for comprehensive answers
response = client.chat.completions.create(
    model="sonar-pro",
    messages=[
        {
            "role": "system",
            "content": "You are a research analyst. Provide detailed, well-sourced analysis.",
        },
        {
            "role": "user",
            "content": (
                "Provide a comprehensive analysis of the current state of "
                "AI regulation globally, including recent legislation and upcoming proposals."
            ),
        },
    ],
    max_tokens=2000,
)

print(response.choices[0].message.content)

Reasoning with sonar-reasoning

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

# sonar-reasoning shows chain-of-thought + searches web
response = client.chat.completions.create(
    model="sonar-reasoning",
    messages=[
        {
            "role": "user",
            "content": (
                "Based on current market data, should I invest in NVIDIA or AMD stock? "
                "Consider recent earnings and market trends."
            ),
        }
    ],
)

print(response.choices[0].message.content)
# Response includes <think> blocks with reasoning process

Multi-Turn Research Session

from openai import OpenAI

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

messages = [
    {
        "role": "system",
        "content": "You are a research assistant with access to current web information. "
                   "Always cite sources and indicate when information may be time-sensitive.",
    }
]

def research_chat(user_message: str) -> str:
    messages.append({"role": "user", "content": user_message})

    response = client.chat.completions.create(
        model="sonar-pro",
        messages=messages,
    )

    answer = response.choices[0].message.content
    messages.append({"role": "assistant", "content": answer})
    return answer

# Multi-turn research
print(research_chat("What are the main AI labs releasing models in 2025?"))
print(research_chat("Which of those models are available via API right now?"))
print(research_chat("Compare their pricing per million tokens."))

Rate Limiting & Error Handling

from openai import OpenAI, RateLimitError
import time

client = OpenAI(
    api_key="pplx-...",
    base_url="https://api.perplexity.ai",
)

def search_with_retry(query: str, retries: int = 3) -> str:
    for attempt in range(retries):
        try:
            response = client.chat.completions.create(
                model="sonar",
                messages=[{"role": "user", "content": query}],
                timeout=30,
            )
            return response.choices[0].message.content
        except RateLimitError:
            wait = 2 ** attempt
            print(f"Rate limited. Retrying in {wait}s...")
            time.sleep(wait)
    raise Exception("Max retries exceeded")

Online vs Offline Models

Feature Online (sonar*) Offline (r1-1776)
Web search ✅ Real-time ❌ Training data only
Citations ✅ URL sources ❌ Not applicable
Current events ✅ Up to today ❌ Training cutoff
Latency Higher (~2–5s) Lower (~0.5s)
Cost Higher Lower

Use online models when freshness matters. Use offline models for tasks that don't need current data (reasoning, creative writing, code).

Guidelines

  • Online models search the web on every request — expect 2–5 second latency.
  • Citations appear in the response.citations list (URLs).
  • sonar is fastest for simple lookups; sonar-pro does multiple searches for complex topics.
  • Perplexity's search is English-centric but supports other languages.
  • For real-time price data or stock quotes, combine Perplexity with direct API calls for accuracy.
  • The system prompt cannot disable web search for online models — use offline models if you need pure LLM responses.
  • Token costs include search overhead — budget accordingly for high-volume use.