AgentSkillsCN

perplexity

通过 Perplexity API,利用人工智能驱动的问答与引文功能畅游网络。适用于需要获取最新资讯并附带可靠来源的研究查询。环境变量:PERPLEXITY_API_KEY。

SKILL.md
--- frontmatter
name: perplexity
description: Search the web with AI-powered answers and citations via Perplexity API. Use for research queries needing current info with sources. Env: PERPLEXITY_API_KEY.

Perplexity Search

Web search with AI synthesis and citations.

Setup

bash
export PERPLEXITY_API_KEY=pplx-...  # Get at perplexity.ai/settings/api

Search Query

bash
curl -s --request POST \
  --url https://api.perplexity.ai/chat/completions \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": "What are the latest developments in quantum computing?"}]
  }' | jq -r '.choices[0].message.content'

Models

ModelUse Case
sonarFast, simple queries
sonar-proComplex questions (default)
sonar-deep-researchThorough research
sonar-reasoning-proMulti-step reasoning

Streaming

bash
curl --request POST \
  --url https://api.perplexity.ai/chat/completions \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "model": "sonar-pro",
    "messages": [{"role": "user", "content": "Explain machine learning"}],
    "stream": true
  }'

Raw Search API

For web results without AI synthesis ($5/1000 requests, no token costs):

bash
curl -s --request POST \
  --url https://api.perplexity.ai/search \
  --header "Authorization: Bearer $PERPLEXITY_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "query": "latest AI developments",
    "max_results": 5,
    "max_tokens_per_page": 2048
  }'

Response Parsing

bash
# Get answer
| jq -r '.choices[0].message.content'

# Get citations
| jq -r '.citations[]'

# Get usage stats
| jq '.usage'

Errors

  • 401 — Invalid API key
  • 429 — Rate limited (wait/retry)