数据 API / Perplexity / Sonar
Perplexity Sonar
Generate a concise answer with web citations. model and messages are required; use model sonar for this endpoint. This public contract covers non-streaming JSON responses with stream false. Read the answer from choices[].message.content and sources from citations and search_results. usage reports resource consumption, not a Felo credit charge.
参数
没有路径、查询或请求头参数。
请求体
modelstring必填允许值: sonar · sonar-pro · sonar-reasoning-pro · sonar-deep-research
The Sonar model to use.
messagesobject[]必填A list of messages comprising the conversation so far.
rolestring必填允许值: system · user · assistant
The role of the message author.
contentstring必填The content of the message.
max_tokensinteger可选The maximum number of tokens to generate in the response.
temperaturenumber可选Sampling temperature between 0 and 2. Lower values make output more focused and deterministic.
top_pnumber可选Nucleus sampling parameter. The model considers tokens with top_p probability mass.
top_kinteger可选The number of tokens to keep for top-k filtering.
streamboolean可选允许值: false
Only non-streaming JSON responses are covered by this public contract. Set false.
search_contextstring可选允许值: low · medium · high
Controls how much search context to use. Affects per-request cost.
frequency_penaltynumber可选Penalizes new tokens based on their existing frequency in the text so far. Positive values decrease the likelihood of repeating the same line verbatim.
presence_penaltynumber可选Penalizes new tokens based on whether they appear in the text so far. Positive values increase the likelihood of talking about new topics.
return_citationsboolean可选Whether to return citations and search results in the response.
search_recency_filterstring可选允许值: month · week · day · hour
Filter search results by recency.
search_domain_filterstring[]可选Limit search to specific domains.
请求示例
curl -X POST "https://openapi.felo.ai/v1/beta/perplexity/sonar" \
-H "Authorization: Bearer $FELO_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "<string>",
"messages": [
{}
],
"max_tokens": 0,
"temperature": 0,
"top_p": 0,
"top_k": 0,
"stream": false,
"search_context": "<string>"
}'响应
响应示例
{
"id": "example-sonar-completion",
"model": "sonar",
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "HTTP caching reuses stored responses when permitted by cache rules. [1]"
},
"finish_reason": "stop"
}
],
"citations": [
"https://www.rfc-editor.org/rfc/rfc9111.html"
],
"search_results": [
{
"title": "HTTP Caching",
"url": "https://www.rfc-editor.org/rfc/rfc9111.html"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 30,
"total_tokens": 50
}
}响应字段
idstring可选Unique identifier for the completion.
modelstring可选The model used for the completion.
objectstring可选createdinteger可选Unix timestamp of when the completion was created.
choicesobject[]可选indexinteger可选messageobject可选rolestring可选contentstring可选The AI-generated answer, with inline citation references like [1][2].
finish_reasonstring可选允许值: stop · length
citationsstring[]可选List of source URLs referenced in the answer.
search_resultsobject[]可选Detailed search results with titles, snippets, and URLs.
titlestring可选urlstring可选snippetstring可选datestring可选sourcestring可选usageobject可选prompt_tokensinteger可选completion_tokensinteger可选total_tokensinteger可选search_context_sizestring可选