主题
Perplexity LLM 实时响应
POST /v3/ai_optimization/perplexity/llm_responses/live
本接口使用 POST 方法,请求路径为:
/v3/ai_optimization/perplexity/llm_responses/live
本接口可根据参数,调用指定的 Perplexity 模型并实时获取结构化 LLM 响应。
> 说明: Perplexity 的 sonar 系列模型默认使用 web_search,但并不保证每次请求都能成功获取网页搜索结果。
接口限制
- 请求体使用 UTF-8 编码的 JSON 格式。
- 请求体是 JSON 数组,例如
[{ ... }]。 - 每次调用最多提交 1 个任务。 平台限流以认证说明中的 30/60/120 次/分钟规则为准。
- 每个平台每个账户同时执行的 Live 任务数上限为 30 个。
- 单个任务的最长执行时间约为 120 秒。
- 实扣费以响应头
X-SeerMarTech-Charge-CNY为准。
请求参数
| 参数 | 类型 | 填 | 说明 |
|---|---|---|---|
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 | 否 | 网页搜索的国家或地区 ISO 代码,用于本地化搜索结果。适用于 Perplexity Sonar 系列模型。例如:US。 |
system_message | string | 否 | 用于设定 AI 的角色、语气或行为规则。最多 500 个字符。 |
message_chain | array | 否 | 对话历史,由消息对象组成。最多 10 个消息对象。 |
tag | string | 否 | 用户自定义的任务标识,最多 255 个字符。可用于请求与响应;提交的值会原样返回在响应的 data 对象中。 |
message_chain 消息对象
数组中的每个对象以下字段:
| 字段 | 类型 | 说明 |
|---|---|---|
role | string | 消息角色,只能是 user 或 ai。 |
message | string | 消息,最多 500 个字符。 |
对于 Perplexity 模型,消息角色严格交替排列:
user → ai → user → ai
请求示例
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": "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?"
}
],
"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"
}
]'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",
}
payload = [
{
"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?",
},
],
"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",
}
]
response = requests.post(url, headers=headers, json=payload, timeout=120)
response.raise_for_status()
result = response.json()
if result.get("status_code") == 20000:
print(result)
else:
print(
f"请求失败,错误码:{result.get('status_code')},"
f"错误信息:{result.get('status_message')}"
)TypeScript
typescript
import axios from "axios";
const url =
"https://api.seermartech.cn/v3/ai_optimization/perplexity/llm_responses/live";
const payload = [
{
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?",
},
],
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",
},
];
axios
.post(url, payload, {
headers: {
Authorization: "Bearer smt_live_YOUR_KEY",
"Content-Type": "application/json",
},
timeout: 120000,
})
.then((response) => {
const result = response.data;
if (result.status_code === 20000) {
console.log(result);
} else {
console.error(
`请求失败,错误码:${result.status_code},错误信息:${result.status_message}`,
);
}
})
.catch((error) => {
console.error("请求异常:", error.message);
});响应说明
接口返回 JSON 数据 tasks 数组。每个任务对象任务状态、请求参数和模型响应结果。
顶层响应字段
| 字段 | 类型 | 说明 |
|---|---|---|
version | string | 当前 API 版本。 |
status_code | integer | 通用响应状态码。完整错误码可参考错误码文档。 |
status_message | string | 通用状态说明。 |
time | string | 请求执行耗时,单位为秒。 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
tasks_count | integer | tasks 数组中的任务总数。 |
tasks_error | integer | tasks 数组中返回错误的任务数量。 |
tasks | array | 任务结果数组。 |
任务字段
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 任务唯一标识,采用 UUID 格式。 |
status_code | integer | 任务状态码,通常位于 10000-60000 范围。 |
status_message | string | 任务状态说明。 |
time | string | 任务执行耗时,单位为秒。 |
cost | float | 平台原始 USD 成本兼容字段;人民币实扣以 X-SeerMarTech-Charge-CNY 为准。 |
result_count | integer | result 数组中的数量。 |
path | array | 请求 URL 路径。 |
data | object | 请求时提交的参数。 |
result | array | 模型响应结果数组。 |
data 字段
data 对象通常本次请求中提交的参数,例如:
apifunctionsesystem_messagemessage_chainmax_output_tokenstemperaturetop_pweb_search_country_iso_codemodel_nameuser_prompttag
result 结果字段
| 字段 | 类型 | 说明 |
|---|---|---|
model_name | string | 实使用的 AI 模型名称。 |
input_tokens | integer | Token 总数。 |
output_tokens | integer | AI 响应生成的输出 Token 总数。 |
web_search | boolean | 是否使用了网页搜索。Perplexity Sonar 系列模型默认启用网页搜索。 |
money_spent | float | AI 模型 Token 使用成本。最终扣费以响应头 X-SeerMarTech-Charge-CNY 为准。 |
datetime | string | 接收结果的 UTC 时间,格式为 yyyy-mm-dd hh-mm-ss +00:00。 |
items | array | 结构化 AI 响应项数组。 |
fan_out_queries | array/null | 从主查询派生出的扩展搜索查询,用于生成更的响应。 |
items 字段
| 字段 | 类型 | 说明 |
|---|---|---|
type | string | 响应项类型,固定为 message。 |
sections | array | 响应分段数组。 |
sections 字段
| 字段 | 类型 | 说明 |
|---|---|---|
type | string | 类型,固定为 text。 |
text | string | AI 生成的文本。 |
annotations | array/null | 生成响应时使用的来源引用。未启用网页搜索时通常为 null。即使 web_search 为 true,如果未找到网页,annotations 也可能为空数组。 |
annotations 字段
| 字段 | 类型 | 说明 |
|---|---|---|
title | string | 被引用来源的域名或标题。 |
url | string | 被引用来源的 URL。 |
start_index | integer/null | 引用的起始索引,当前通常为 null。 |
end_index | integer/null | 引用的结束索引,当前通常为 null。 |
text | string/null | 被标注的来源文本,当前通常为 null。 |
响应示例
json
{
"version": "0.1.20260717",
"status_code": 20000,
"status_message": "Ok.",
"time": "9.7257 sec.",
"cost": 0.006724,
"tasks_count": 1,
"tasks_error": 0,
"tasks": [
{
"id": "00000000-0000-0000-0000-000000000000",
"status_code": 20000,
"status_message": "Ok.",
"time": "9.7257 sec.",
"cost": 0.006724,
"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?"
}
],
"max_output_tokens": 200,
"temperature": 0.3,
"top_p": 0.5,
"web_search_country_iso_code": "FR",
"model_name": "sonar-reasoning-pro",
"user_prompt": "provide information on how relevant the amusement park business is in France now"
},
"result": [
{
"model_name": "sonar-reasoning-pro",
"input_tokens": 42,
"output_tokens": 180,
"web_search": true,
"money_spent": 0.004,
"datetime": "2019-11-15 12:57:46 +00:00",
"items": [
{
"type": "message",
"sections": [
{
"type": "text",
"text": "AI generated response",
"annotations": [
{
"title": "example.com",
"url": "https://example.com",
"start_index": null,
"end_index": null,
"text": null
}
]
}
]
}
],
"fan_out_queries": null
}
]
}
]
}状态码与异常处理
20000表示请求成功。- 顶层
status_code用于表示整体请求状态。 tasks中的status_code用于表示任务状态。- 建议在业务系统中同时检查 HTTP 状态码、顶层
status_code、任务级status_code和tasks_error。 - 对时、模型不可用、参数校验失败及平台响应异常等,应设计重试、降级或人工告警机制。
- 完整状态码和错误信息请参考错误码文档。
实用场景
- 分析品牌在 AI 搜索中的表现,结合网页搜索引用判断品牌是否被模型发现和推荐,为 AI 搜索优化提供依据。
- 生成本地化市场研究报告,通过
web_search_country_iso_code指定国家或地区,获取面向不同市场的实时行业信息。 - 评估竞争对手与细分行业趋势,向指定模型提交统一问题并比较不同品牌、地区或业务类型的回答结果。
- 构建带来源引用的调研流程,读取
annotations中的标题和 URL,追踪 AI 回答所依据的网页来源。 - 分析用户问题与 AI 回答成本,结合
input_tokens、output_tokens、web_search和money_spent,优化提示词及模型调用策略。