Perplexity AI API 사용 방법 (2026)
Perplexity의 검색 증강 AI를 애플리케이션에 통합하기 위한 개발자 가이드
Hypereal로 구축 시작하기
단일 API를 통해 Kling, Flux, Sora, Veo 등에 액세스하세요. 무료 크레딧으로 시작하고 수백만으로 확장하세요.
신용카드 불필요 • 10만 명 이상의 개발자 • 엔터프라이즈 지원
Perplexity AI API 사용법 (2026)
Perplexity AI는 대규모 언어 모델(LLM)과 실시간 웹 검색을 결합한 API를 제공합니다. 정적 학습 데이터에 의존하는 표준 LLM API와 달리, Perplexity API는 웹에서 최신 정보를 검색하고 이를 인용문이 포함된 정확한 답변으로 합성합니다. 따라서 리서치 도구, 뉴스 애그리게이터, 경쟁사 분석, 고객 지원 봇 등 정보의 최신성이 중요한 모든 애플리케이션에 이상적입니다.
이 가이드는 전체 API 설정, 사용 가능한 모든 모델, 다국어 코드 예제 및 실용적인 통합 패턴을 다룹니다.
왜 Perplexity API를 사용해야 하나요?
| 기능 | Perplexity API | 표준 LLM API |
|---|---|---|
| 실시간 웹 검색 | 예 (내장됨) | 아니요 (정적 학습 데이터) |
| 출처 인용 | 예 (URL 포함) | 아니요 |
| 지식 컷오프 | 없음 (라이브 검색) | 수개월에서 수년 전 |
| 환각(Hallucination) 율 | 낮음 (검색 기반) | 높음 |
| 구조화된 출력 | JSON 모드 지원 | 제공업체마다 다름 |
| OpenAI 호환성 | 예 | 제공업체마다 다름 |
사전 요구 사항
- API 접근 권한이 있는 Perplexity 계정.
- Perplexity 개발자 대시보드에서 발급받은 API 키.
- Python 3.9+ 또는 Node.js 18+ (아래 예제 실행용).
Step 1: API 키 가져오기
- perplexity.ai/settings/api로 이동합니다.
- Generate API Key를 클릭합니다.
- 키를 복사하여 안전한 곳에 저장합니다.
- 계정에 크레딧을 추가합니다 (API는 후불제가 아닌 선불제입니다).
환경 변수를 설정합니다:
export PERPLEXITY_API_KEY="pplx-your-api-key-here"
Step 2: 첫 번째 요청 보내기
Perplexity API는 OpenAI와 호환되므로 OpenAI SDK를 사용할 수 있습니다.
pip install openai
from openai import OpenAI
client = OpenAI(
api_key="pplx-your-api-key-here",
base_url="https://api.perplexity.ai"
)
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{
"role": "system",
"content": "You are a helpful research assistant. Provide accurate, well-cited answers."
},
{
"role": "user",
"content": "What are the latest developments in nuclear fusion energy in 2026?"
}
]
)
print(response.choices[0].message.content)
# 인용 출처 접근
if hasattr(response, 'citations'):
print("\nSources:")
for citation in response.citations:
print(f" - {citation}")
사용 가능한 모델
Perplexity는 다양한 사용 사례에 최적화된 여러 모델을 제공합니다.
| 모델 | 최적 용도 | 컨텍스트 윈도우 | 검색 여부 | 가격 (Input) | 가격 (Output) |
|---|---|---|---|---|---|
sonar-pro |
복잡한 리서치, 상세한 답변 | 200K | 예 | $3/M tokens | $15/M tokens |
sonar |
일반적인 질문, 빠른 응답 | 128K | 예 | $1/M tokens | $1/M tokens |
sonar-reasoning-pro |
다단계 분석, 비교 | 128K | 예 | $2/M tokens | $8/M tokens |
sonar-reasoning |
검색을 포함한 가벼운 추론 | 128K | 예 | $1/M tokens | $5/M tokens |
sonar-deep-research |
포괄적인 보고서, 장문 작성 | 128K | 예 (심층) | $2/M tokens | $8/M tokens |
모델 선택 가이드:
- 신속한 사실 확인이나 가벼운 쿼리에는
sonar를 사용하세요. - 상세한 리서치와 복잡한 질문에는
sonar-pro를 사용하세요. - 분석과 비교가 필요한 작업에는
sonar-reasoning-pro를 사용하세요. - 여러 번의 검색 반복이 필요한 포괄적인 보고서 작성에는
sonar-deep-research를 사용하세요.
Step 3: cURL 사용하기
curl -X POST https://api.perplexity.ai/chat/completions \
-H "Authorization: Bearer pplx-your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"model": "sonar-pro",
"messages": [
{
"role": "user",
"content": "Compare the top 3 JavaScript frameworks in 2026 by popularity and performance"
}
],
"temperature": 0.2,
"max_tokens": 2000
}'
Step 4: Node.js / TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.PERPLEXITY_API_KEY,
baseURL: 'https://api.perplexity.ai',
});
async function search(query: string): Promise<string> {
const response = await client.chat.completions.create({
model: 'sonar-pro',
messages: [
{
role: 'system',
content: 'Provide concise, factual answers with source citations.',
},
{
role: 'user',
content: query,
},
],
temperature: 0.2,
max_tokens: 1500,
});
return response.choices[0].message.content ?? '';
}
// 사용 예시
const result = await search('What is the current price of Bitcoin?');
console.log(result);
Step 5: 스트리밍 응답
실시간 응답 전달을 위해:
from openai import OpenAI
client = OpenAI(
api_key="pplx-your-api-key-here",
base_url="https://api.perplexity.ai"
)
stream = client.chat.completions.create(
model="sonar",
messages=[
{
"role": "user",
"content": "What happened in 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() # 끝에 줄바꿈
Step 6: 검색 컨텍스트 제어
Perplexity의 웹 검색 방식을 제어할 수 있습니다:
response = client.chat.completions.create(
model="sonar-pro",
messages=[
{
"role": "user",
"content": "Latest Python 3.14 features and release date"
}
],
# 검색 동작 제어
search_domain_filter=["python.org", "docs.python.org", "peps.python.org"],
search_recency_filter="week", # 옵션: "hour", "day", "week", "month"
return_citations=True,
return_related_questions=True
)
print(response.choices[0].message.content)
# 사용자가 다음에 물어볼 만한 관련 질문
if hasattr(response, 'related_questions'):
print("\nRelated questions:")
for q in response.related_questions:
print(f" - {q}")
실용적인 사용 사례
1. 리서치 어시스턴트
def research_topic(topic: str, depth: str = "standard") -> dict:
model = "sonar-deep-research" if depth == "deep" else "sonar-pro"
response = client.chat.completions.create(
model=model,
messages=[
{
"role": "system",
"content": """You are a research analyst. Provide:
1. Key findings (bullet points)
2. Recent developments (last 30 days)
3. Expert opinions
4. Data and statistics
Include citations for all claims."""
},
{
"role": "user",
"content": f"Research: {topic}"
}
],
return_citations=True,
max_tokens=3000
)
return {
"content": response.choices[0].message.content,
"citations": getattr(response, 'citations', []),
"model": model
}
result = research_topic("state of AI regulation in Europe 2026", depth="deep")
print(result["content"])
2. 경쟁사 인텔리전스
def analyze_competitor(company: str) -> str:
response = client.chat.completions.create(
model="sonar-reasoning-pro",
messages=[
{
"role": "user",
"content": f"""Analyze {company} as a competitor:
- Recent product launches
- Pricing changes
- Key partnerships
- Market position
- Strengths and weaknesses
Base your analysis on the most recent information available."""
}
],
search_recency_filter="month",
return_citations=True,
max_tokens=2500
)
return response.choices[0].message.content
print(analyze_competitor("Vercel"))
3. 뉴스 집계 (News Aggregation)
def get_news_summary(topic: str) -> str:
response = client.chat.completions.create(
model="sonar",
messages=[
{
"role": "user",
"content": f"Summarize today's top 5 news stories about {topic}. Include sources."
}
],
search_recency_filter="day",
return_citations=True,
max_tokens=1500
)
return response.choices[0].message.content
print(get_news_summary("artificial intelligence"))
4. 팩트 체크 API
def fact_check(claim: str) -> str:
response = client.chat.completions.create(
model="sonar-reasoning-pro",
messages=[
{
"role": "system",
"content": """You are a fact-checker. For each claim:
1. State whether it is TRUE, FALSE, PARTIALLY TRUE, or UNVERIFIABLE
2. Provide evidence from reliable sources
3. Cite your sources
Be objective and thorough."""
},
{
"role": "user",
"content": f"Fact-check this claim: {claim}"
}
],
return_citations=True,
max_tokens=2000
)
return response.choices[0].message.content
print(fact_check("The global average temperature in 2025 was the hottest year on record"))
요금제 및 제한 사항 (Rate Limits)
| 등급 | 분당 요청 수(RPM) | 분당 토큰 수(TPM) | 월간 지출 |
|---|---|---|---|
| 무료 체험 | 5 | 20,000 | $0 (제한적) |
| Standard | 50 | 100,000 | 종량제 (Pay as you go) |
| Pro | 500 | 1,000,000 | $50+ |
| Enterprise | 별도 문의 | 별도 문의 | 영업팀 문의 |
비용 예시:
| 사용 사례 | 모델 | 일일 요청 수 | 예상 월 비용 |
|---|---|---|---|
| 개인 리서치 | sonar | 50 | ~$5 |
| 뉴스 집계 | sonar | 500 | ~$30 |
| 경쟁사 분석 | sonar-pro | 100 | ~$50 |
| 프로덕션 검색 앱 | sonar-pro | 5,000 | ~$500 |
오류 처리
from openai import OpenAI, APIError, RateLimitError, APIConnectionError
import time
client = OpenAI(
api_key="pplx-your-api-key-here",
base_url="https://api.perplexity.ai"
)
def query_with_retry(query: str, max_retries: int = 3) -> str:
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="sonar",
messages=[{"role": "user", "content": query}],
max_tokens=1500
)
return response.choices[0].message.content
except RateLimitError:
wait_time = 2 ** attempt
print(f"Rate limited. Waiting {wait_time}s...")
time.sleep(wait_time)
except APIConnectionError:
print("Connection error. Retrying...")
time.sleep(1)
except APIError as e:
print(f"API error: {e}")
raise
raise Exception("Max retries exceeded")
문제 해결
| 문제 | 해결 방법 |
|---|---|
| 401 Unauthorized | API 키가 정확한지, 크레딧이 남아 있는지 확인하십시오. |
| 429 Rate Limited | 지수 백오프(backoff)를 구현하거나 요금제 티어를 업그레이드하십시오. |
| 인용 누락 | 모든 응답에 인용이 포함되지는 않습니다. return_citations=True를 사용하십시오. |
| 오래된 정보 | search_recency_filter를 사용하여 최신 결과로 제한하십시오. |
| 응답 속도 느림 | 더 빠른 결과를 위해 sonar-pro 대신 sonar를 사용하십시오. |
| 모델을 찾을 수 없음 | 모델 이름을 확인하십시오. Perplexity는 주기적으로 모델 이름을 업데이트합니다. |
결론
Perplexity AI API는 실시간 웹 데이터에 기반한 LLM 응답이 필요한 애플리케이션을 구축하는 데 가장 적합한 옵션입니다. OpenAI와 호환되는 인터페이스 덕분에 통합이 간단하며, 내장된 검색 및 인용 기능 덕분에 웹 콘텐츠를 위한 별도의 RAG 파이프라인을 구축할 필요가 없습니다.
이미지, 비디오, 말하는 아바타 또는 음성 합성 등 AI 생성 미디어가 필요한 애플리케이션을 구축하고 있다면 Hypereal AI를 확인해 보세요. Hypereal은 생성 미디어를 위한 종량제 REST API를 제공하여, Perplexity의 검색 지능과 Hypereal의 미디어 생성 기능을 하나의 애플리케이션에서 쉽게 결합할 수 있도록 돕습니다.
