perplexity

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Perplexity AI

Perplexity AI

AI search engine that provides real-time web-grounded answers with source citations. Unlike traditional search, Perplexity synthesizes information from multiple sources into coherent responses.

一款AI搜索引擎,可提供基于实时网络信息的答案并附带来源引用。与传统搜索引擎不同,Perplexity会将多个来源的信息整合为连贯的回答。

When to Use

使用场景

Use this skill when you need to:
  • Get real-time information with source citations
  • Research topics that require up-to-date web data
  • Answer complex questions that need multi-source synthesis
  • Perform academic or SEC filings research
  • Get AI-generated summaries grounded in current web content

在以下场景中可以使用该工具:
  • 获取带来源引用的实时信息
  • 研究需要最新网络数据的主题
  • 回答需要多来源信息整合的复杂问题
  • 进行学术研究或SEC文件调研
  • 获取基于当前网络内容的AI生成摘要

Prerequisites

前置条件

  1. Create an account at https://perplexity.ai/
  2. Navigate to API settings: https://perplexity.ai/account/api
  3. Generate an API key
Set environment variable:
bash
export PERPLEXITY_API_KEY="pplx-your-api-key"

Important: When using
$VAR
in a command that pipes to another command, wrap the command containing
$VAR
in
bash -c '...'
. Due to a Claude Code bug, environment variables are silently cleared when pipes are used directly.
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .
  1. https://perplexity.ai/ 创建账户
  2. 进入API设置页面:https://perplexity.ai/account/api
  3. 生成API密钥
设置环境变量:
bash
export PERPLEXITY_API_KEY="pplx-your-api-key"

重要提示:当在包含管道操作的命令中使用
$VAR
时,请将包含
$VAR
的命令用
bash -c '...'
包裹。由于Claude Code的bug,直接使用管道时环境变量会被自动清除。
bash
bash -c 'curl -s "https://api.example.com" -H "Authorization: Bearer $API_KEY"' | jq .

How to Use

使用方法

1. Chat Completions (Recommended)

1. 对话补全(推荐)

AI-powered Q&A with web search and citations. OpenAI SDK compatible.
Basic query with sonar model:
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "What is the current price of Bitcoin?"}
  ]
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
With system prompt:
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "system", "content": "Be precise and concise. Answer in bullet points."},
    {"role": "user", "content": "What are the latest developments in AI?"}
  ]
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
Advanced query with sonar-pro:
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar-pro",
  "messages": [
    {"role": "user", "content": "Compare the latest iPhone and Samsung Galaxy flagship phones"}
  ],
  "temperature": 0.2,
  "web_search_options": {
    "search_context_size": "high"
  }
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
结合网络搜索与引用标注的AI问答功能,兼容OpenAI SDK。
使用sonar模型的基础查询:
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "What is the current price of Bitcoin?"}
  ]
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
包含系统提示词的查询:
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "system", "content": "Be precise and concise. Answer in bullet points."},
    {"role": "user", "content": "What are the latest developments in AI?"}
  ]
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
使用sonar-pro模型的高级查询:
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar-pro",
  "messages": [
    {"role": "user", "content": "Compare the latest iPhone and Samsung Galaxy flagship phones"}
  ],
  "temperature": 0.2,
  "web_search_options": {
    "search_context_size": "high"
  }
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

2. Search with Domain Filter

2. 带域名过滤的搜索

Limit search to specific domains.
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Latest research on transformer architectures"}
  ],
  "search_domain_filter": ["arxiv.org", "openai.com", "anthropic.com"]
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
Exclude domains (add
-
prefix):
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Best programming practices"}
  ],
  "search_domain_filter": ["-reddit.com", "-quora.com"]
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
将搜索范围限制在特定域名内。
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Latest research on transformer architectures"}
  ],
  "search_domain_filter": ["arxiv.org", "openai.com", "anthropic.com"]
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
排除指定域名(添加
-
前缀):
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Best programming practices"}
  ],
  "search_domain_filter": ["-reddit.com", "-quora.com"]
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

3. Search with Time Filter

3. 带时间过滤的搜索

Filter by recency.
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Major tech news"}
  ],
  "search_recency_filter": "week"
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
Filter by date range:
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "AI announcements"}
  ],
  "search_after_date_filter": "12/01/2024",
  "search_before_date_filter": "12/31/2024"
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
按内容时效性过滤搜索结果。
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Major tech news"}
  ],
  "search_recency_filter": "week"
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
按日期范围过滤:
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "AI announcements"}
  ],
  "search_after_date_filter": "12/01/2024",
  "search_before_date_filter": "12/31/2024"
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

4. Academic Search

4. 学术搜索

Search academic sources.
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Recent papers on large language model alignment"}
  ],
  "search_mode": "academic"
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
搜索学术来源的内容。
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar",
  "messages": [
    {"role": "user", "content": "Recent papers on large language model alignment"}
  ],
  "search_mode": "academic"
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

5. Raw Search API

5. 原始搜索API

Get raw search results without AI synthesis.
Write to
/tmp/perplexity_request.json
:
json
{
  "query": "Claude AI Anthropic",
  "max_results": 5
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/search" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
With domain and time filters:
Write to
/tmp/perplexity_request.json
:
json
{
  "query": "machine learning tutorials",
  "max_results": 10,
  "search_domain_filter": ["github.com", "medium.com"],
  "search_recency_filter": "month",
  "country": "US"
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/search" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
获取未经AI整合的原始搜索结果。
创建
/tmp/perplexity_request.json
文件:
json
{
  "query": "Claude AI Anthropic",
  "max_results": 5
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/search" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
带域名和时间过滤的原始搜索:
创建
/tmp/perplexity_request.json
文件:
json
{
  "query": "machine learning tutorials",
  "max_results": 10,
  "search_domain_filter": ["github.com", "medium.com"],
  "search_recency_filter": "month",
  "country": "US"
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/search" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

6. Deep Research (Long-form)

6. 深度研究(长文本)

For comprehensive research reports.
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar-deep-research",
  "messages": [
    {"role": "user", "content": "Write a comprehensive analysis of the electric vehicle market in 2024"}
  ],
  "reasoning_effort": "high"
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'
用于生成全面的研究报告。
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar-deep-research",
  "messages": [
    {"role": "user", "content": "Write a comprehensive analysis of the electric vehicle market in 2024"}
  ],
  "reasoning_effort": "high"
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

7. Reasoning Model

7. 推理模型

For complex problem-solving.
Write to
/tmp/perplexity_request.json
:
json
{
  "model": "sonar-reasoning-pro",
  "messages": [
    {"role": "user", "content": "Analyze the pros and cons of microservices vs monolithic architecture for a startup"}
  ]
}
Then run:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

用于解决复杂问题。
创建
/tmp/perplexity_request.json
文件:
json
{
  "model": "sonar-reasoning-pro",
  "messages": [
    {"role": "user", "content": "Analyze the pros and cons of microservices vs monolithic architecture for a startup"}
  ]
}
然后执行命令:
bash
bash -c 'curl -s -X POST "https://api.perplexity.ai/chat/completions" --header "Authorization: Bearer ${PERPLEXITY_API_KEY}" --header "Content-Type: application/json" -d @/tmp/perplexity_request.json'

Models

模型列表

ModelDescriptionBest For
sonar
Lightweight, cost-effectiveQuick facts, news, simple Q&A
sonar-pro
Advanced search, deeper understandingComplex queries, detailed research
sonar-reasoning-pro
Multi-step reasoning with searchProblem-solving, analysis
sonar-deep-research
Exhaustive research, reportsAcademic research, market analysis

模型描述适用场景
sonar
轻量型,性价比高快速查事实、新闻、简单问答
sonar-pro
高级搜索能力,理解深度更强复杂查询、详细研究
sonar-reasoning-pro
结合搜索的多步骤推理问题解决、分析类任务
sonar-deep-research
全面调研,生成报告学术研究、市场分析

Response Format

返回格式

Chat completions return:
json
{
  "id": "uuid",
  "model": "sonar",
  "choices": [
  {
  "message": {
  "role": "assistant",
  "content": "The answer with [1] citations..."
  }
  }
  ],
  "citations": ["https://source1.com", "https://source2.com"],
  "search_results": [
  {
  "title": "Source Title",
  "url": "https://source.com",
  "snippet": "Relevant excerpt..."
  }
  ],
  "usage": {
  "prompt_tokens": 10,
  "completion_tokens": 150,
  "total_tokens": 160
  }
}

对话补全接口返回示例:
json
{
  "id": "uuid",
  "model": "sonar",
  "choices": [
  {
  "message": {
  "role": "assistant",
  "content": "The answer with [1] citations..."
  }
  }
  ],
  "citations": ["https://source1.com", "https://source2.com"],
  "search_results": [
  {
  "title": "Source Title",
  "url": "https://source.com",
  "snippet": "Relevant excerpt..."
  }
  ],
  "usage": {
  "prompt_tokens": 10,
  "completion_tokens": 150,
  "total_tokens": 160
  }
}

Guidelines

使用指南

  1. Model Selection: Use
    sonar
    for simple queries,
    sonar-pro
    for complex ones
  2. Cost Optimization: Lower
    search_context_size
    reduces costs (low/medium/high)
  3. Domain Filters: Limit to 20 domains max; use
    -
    prefix to exclude
  4. Recency Filters: Options are
    day
    ,
    week
    ,
    month
    ,
    year
  5. Temperature: Lower (0.1-0.3) for factual queries, higher for creative
  6. Rate Limits: Vary by tier; check https://docs.perplexity.ai/guides/rate-limits-usage-tiers
  7. Citations: Response includes numbered citations
    [1]
    that map to
    citations
    array
  1. 模型选择:简单查询使用
    sonar
    ,复杂查询使用
    sonar-pro
  2. 成本优化:降低
    search_context_size
    可减少成本(可选值:low/medium/high)
  3. 域名过滤:最多限制20个域名;使用
    -
    前缀表示排除该域名
  4. 时效性过滤:可选值为
    day
    week
    month
    year
  5. Temperature参数:事实类查询设置较低值(0.1-0.3),创意类查询设置较高值
  6. 调用限制:根据不同层级有所差异;查看https://docs.perplexity.ai/guides/rate-limits-usage-tiers
  7. 引用标注:回答中包含带编号的引用
    [1]
    ,对应返回结果中的
    citations
    数组