主题
Perplexity LLM 实时响应
接口说明
/v3/ai_optimization/perplexity/llm_responses/live 用于实时获取指定 Perplexity AI 模型返回的结构化结果。你可以通过提示词、模型名称、上下文消息链、采样参数等控制生成结果。
注意:
- Perplexity 的
sonar系列模型默认会尝试使用web_search,但并不保证每次请求都能成功调用网页搜索。- 本接口为实时接口,单次调用支持提交 1 个任务。
- 每分钟最多可发起 2000 次 API 调用。
- LLM Responses 中,每个平台每个账户的并发 Live 任务当前限制为 30。
- 该接口的任务执行时间当前最长可达 120 秒。
请求方式
POST https://api.seermartech.cn/v3/ai_optimization/perplexity/llm_responses/live
计费说明
扣费以响应头 X-SeerMarTech-Charge-CNY 为准。 从示例响应看,参考价约 ¥0.1330 / 次。 任务费用通常基础调用成本,以及 money_spent 表示的第三方模型 token 费用。
请求体格式
所有 POST 数据使用 UTF-8 编码的 JSON,并按数组形式提交:
json
[
{
"model_name": "sonar",
"user_prompt": "provide information on how relevant the amusement park business is in France now"
}
]请求参数
| 字段名 | 类型 | 说明 |
|---|---|---|
user_prompt | string | 发送给 AI 模型的问题或任务。填。最长 500 个字符。 |
model_name | string | AI 模型名称。填。由模型名和版本名组成;如果只传基础模型名,默认使用最新版本。可通过 /v3/ai_optimization/perplexity/llm_responses/models 获取可用模型列表。 |
max_output_tokens | integer | AI 输出的最大 token 数。可选。最小值 1,最大值 4096,默认值 2048。**注意:**如果请求中使用的是推理型模型,输出 token 数可能该限制。 |
temperature | float | 输出随机性。可选。值越高,结果越发散;值越低,结果越集中。取值范围 0 到 1.9,默认 0.77。 |
top_p | float | 输出多样性控制参数。可选。通过限制候选 token 范围来控制生成分布。取值范围 0 到 1,默认 0.9。 |
web_search_country_iso_code | string | 网页搜索的国家本地化代码。可选。用于获得本地化网页搜索结果。适用于 Perplexity Sonar 模型。示例:US。 |
system_message | string | 设定 AI 的角色、语气或行为规则。可选。最长 500 个字符。 |
message_chain | array | 对话历史。可选。数组中的每个对象表示一轮历史消息,:role 和 message。最多 10 个消息对象。**注意:**Perplexity 模型要求消息角色严格交替:user → ai → user → ai。 |
message_chain[].role | string | 消息角色,只能是 user 或 ai。 |
message_chain[].message | string | 消息,单条最长 500 个字符。 |
tag | string | 自定义任务标识。可选。最长 255 个字符。可用于请求结果匹,响应中的 data 对象会返回该值。 |
响应结构
接口返回 JSON 数据,顶层 tasks 数组。
顶层字段
| 字段名 | 类型 | 说明 |
|---|---|---|
version | string | 当前 API 版本。 |
status_code | integer | 通用状态码。完整错误码见 /v3/appendix/errors。建议在业务系统中做好异常处理。 |
status_message | string | 通用状态信息。完整说明见 /v3/appendix/errors。 |
time | string | 执行耗时,单位秒。 |
cost | float | 本次请求总费用,单位 USD。 |
tasks_count | integer | tasks 数组中的任务数量。 |
tasks_error | integer | 返回错误的任务数量。 |
tasks | array | 任务结果数组。 |
tasks[] 字段
| 字段名 | 类型 | 说明 |
|---|---|---|
id | string | 任务唯一标识,UUID 格式。 |
status_code | integer | 任务状态码,范围通常为 10000 - 60000。完整列表见 /v3/appendix/errors。 |
status_message | string | 任务状态信息。 |
time | string | 任务执行耗时,单位秒。 |
cost | float | 当前任务费用,单位 USD。基础任务价格和 money_spent。 |
result_count | integer | result 数组中的数量。 |
path | array | 请求路径信息。 |
data | object | 回显请求中提交的参数。 |
result | array | 结果数组。 |
result[] 字段
| 字段名 | 类型 | 说明 |
|---|---|---|
model_name | string | 实使用的 AI 模型名称。 |
input_tokens | integer | token 总数。 |
output_tokens | integer | 输出 token 总数。 |
web_search | boolean | 是否使用了网页搜索。**注意:**Perplexity Sonar 模型默认启用网页搜索。 |
money_spent | float | AI token 成本,单位 USD,即第三方模型提供方计费金额。 |
datetime | string | 结果生成时间,UTC 格式:yyyy-mm-dd hh-mm-ss +00:00。例如:2019-11-15 12:57:46 +00:00 |
items | array | 结构化响应数组。 |
items[] 字段
| 字段名 | 类型 | 说明 |
|---|---|---|
type | string | 素类型,固定为 message。 |
sections | array | 分段数组, AI 响应的不同部分。 |
fan_out_queries | array | 扩展查询数组,表示从主问题衍生出的查询,用于补回答的完整性。 |
sections[] 字段
| 字段名 | 类型 | 说明 |
|---|---|---|
type | string | 分段类型,固定为 text。 |
text | string | AI 生成的文本。 |
annotations | array | 生成回答时引用的来源列表。如果未启用网页搜索,则通常为 null。**注意:**即使 web_search 为 true,如果模型未找到合适网页结果,annotations 也可能为空。 |
annotations[] 字段
| 字段名 | 类型 | 说明 |
|---|---|---|
title | string | 引用来源的域名或标题。 |
url | string | 引用来源的 URL。 |
请求示例
cURL
bash
curl --location --request POST "https://api.seermartech.cn/v3/ai_optimization/perplexity/llm_responses/live" \
--header "Authorization: Bearer smt_live_YOUR_KEY" \
--header "Content-Type: application/json" \
--data-raw '[
{
"system_message": "请以商务会议交流风格回答",
"message_chain": [
{
"role": "user",
"message": "你好,最近法国主题乐园行业怎么样?"
},
{
"role": "ai",
"message": "你好,我可以从市场规模、增长趋势和竞争格局几个维度进行说明。"
}
],
"max_output_tokens": 200,
"temperature": 0.3,
"top_p": 0.5,
"web_search_country_iso_code": "FR",
"model_name": "sonar",
"user_prompt": "请说明当前法国游乐园业务的市场性和发展"
}
]'Python
python
import requests
url = "https://api.seermartech.cn/v3/ai_optimization/perplexity/llm_responses/live"
headers = {
"Authorization": "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json"
}
data = [
{
"system_message": "请以商务会议交流风格回答",
"message_chain": [
{
"role": "user",
"message": "你好,最近法国主题乐园行业怎么样?"
},
{
"role": "ai",
"message": "你好,我可以从市场规模、增长趋势和竞争格局几个维度进行说明。"
}
],
"max_output_tokens": 200,
"temperature": 0.3,
"top_p": 0.5,
"web_search_country_iso_code": "FR",
"model_name": "sonar",
"user_prompt": "请说明当前法国游乐园业务的市场性和发展"
}
]
response = requests.post(url, headers=headers, json=data, timeout=120)
print(response.json)TypeScript
typescript
import axios from "axios";
async function perplexityLlmResponsesLive {
const response = await axios.post(
"https://api.seermartech.cn/v3/ai_optimization/perplexity/llm_responses/live",
[
{
system_message: "请以商务会议交流风格回答",
message_chain: [
{
role: "user",
message: "你好,最近法国主题乐园行业怎么样?"
},
{
role: "ai",
message: "你好,我可以从市场规模、增长趋势和竞争格局几个维度进行说明。"
}
],
max_output_tokens: 200,
temperature: 0.3,
top_p: 0.5,
web_search_country_iso_code: "FR",
model_name: "sonar",
user_prompt: "请说明当前法国游乐园业务的市场性和发展"
}
],
{
headers: {
Authorization: "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json"
},
timeout: 120000
}
);
console.log(response.data);
}
perplexityLlmResponsesLive.catch(console.error);响应示例
json
{
"version": "0.1.20251208",
"status_code": 20000,
"status_message": "Ok.",
"time": "4.1058 sec.",
"cost": 0.008312,
"tasks_count": 1,
"tasks_error": 0,
"tasks": [
{
"id": "7c1b2f36-2b8d-4aa1-9ef4-9a8d8f7f0001",
"status_code": 20000,
"status_message": "Ok.",
"time": "4.0211 sec.",
"cost": 0.008312,
"result_count": 1,
"path": [
"v3",
"ai_optimization",
"perplexity",
"llm_responses",
"live"
],
"data": {
"api": "ai_optimization",
"function": "llm_responses",
"se": "perplexity",
"system_message": "communicate as if we are in a business meeting",
"message_chain": [
{
"role": "user",
"message": "Hello, what's up?"
},
{
"role": "ai",
"message": "Hello! I’m doing well, thank you. How can I assist you today? Are there any specific topics or projects you’d like to discuss in our meeting?"
}
],
"max_output_tokens": 200,
"temperature": 0.3,
"top_p": 0.5,
"web_search_country_iso_code": "FR",
"model_name": "sonar",
"user_prompt": "provide information on how relevant the amusement park business is in France now"
},
"result": [
{
"model_name": "sonar",
"input_tokens": 87,
"output_tokens": 196,
"web_search": true,
"money_spent": 0.006312,
"datetime": "2025-12-08 10:25:33 +00:00",
"items": [
{
"type": "message",
"sections": [
{
"type": "text",
"text": "法国游乐园行业当前备较强市场性。根据市场资料,该市场在 2024 年已达到数十规模,并预计未来几年保持稳定增长。行业增长受益于家庭娱乐消费、恢复以及本地体验型消费需求提升。",
"annotations": [
{
"title": "example-source-1.com",
"url": "https://example-source-1.com/report"
},
{
"title": "example-source-2.com",
"url": "https://example-source-2.com/market-data"
}
]
}
],
"fan_out_queries": null
}
]
}
]
}
]
}状态码与异常处理
- 顶层
status_code表示整个请求是否成功。 tasks[].status_code表示任务处理状态。- 完整错误码与说明请参考
/v3/appendix/errors。 - 建议重点处理以下:
- 参数缺失或格式错误
- 模型名称不可用 -出并发限制 -时或平台模型响应失败
- 返回成功但
annotations为空
使用说明与注意事项
一次支持一个任务 尽管请求体格式为数组,但当前每次 Live 请求只能 1 个对象。
对话链严格交替
message_chain中的角色顺序符合user → ai → user → ai,否则可能导致请求失败或结果异常。网页搜索并非每次都有引用来源 即使 Sonar 模型默认启用网页搜索,
annotations仍可能为空,这通常意味着模型未检索到可引用的有效结果。推理模型可能出 token 限额 如果使用推理型模型,输出长度可能
max_output_tokens。本地化搜索建议显式设置国家代码 当你希望模型更特定国家市场时,可设置
web_search_country_iso_code,例如FR、US、GB。
实用场景
- 生成行业概览:某个国家和行业主题,快速获取带来源引用的市场总结,用于制作客户提案或行业简报。
- 验证事实:让模型结合网页搜索输出结构化说明,并通过
annotations回溯引用来源, SEO审核与事实校验。 - 扩展研究问题:利用
fan_out_queries获取主问题衍生出的搜索方向,帮助规划专题页、集群或进一步研究路径。 - 构建多轮分析助手:通过
message_chain传递上下文,连续追问同一主题,实现竞品、市场、趋势等场景下的会话式分析。 - 本地化市场研究:结合
web_search_country_iso_code获取面向特定国家的搜索结果,用于跨境 SEO、海外业务调研和区域策略制定。