# 即時 Perplexity LLM 回應

**API:** Data API

**Endpoint:** `POST /v1/beta/dataforseo/ai_optimization/perplexity/llm_responses/live`

**Tags:** DataForSEO

向 Perplexity 模型傳送 `user_prompt` 並同步回傳其回覆。`model_name` 必須來自 `get_dataforseo_ai_perplexity_llm_responses_models`——`sonar`、`sonar-pro` 與 `sonar-reasoning-pro`。`web_search_country_iso_code` 可限定搜尋範圍，其他三家廠商不提供此功能。回傳 `model_name`、`input_tokens`、`output_tokens`、`reasoning_tokens`、`web_search`、`money_spent`、`datetime`、`items` 與 `fan_out_queries`。讀取回應中的 `money_spent` 即可得知一次提示詞的實際成本。採用 DataForSEO 的信封結構：資料位於 `tasks[0].result`，結果狀態位於 `tasks[0].status_code`——被拒絕的請求仍會回傳 HTTP 200。

### 計費參考

- 計量方式：依回報的回應成本計量。
- 參考請求估算：0.0163 美元。
- 參考客戶倍率：1.0。不得對已結算的客戶金額再次套用。

僅供參考的中繼資料，並非帳戶報價、保證價格或消費上限。資源額度並非 Felo 額度。最終費用依 Felo 計費記錄為準。

## Base URL

- `https://openapi.felo.ai`

## Authentication

- `FeloBearerAuth` (http bearer, bearer format Felo API Key)
- `FeloApiKey` (apiKey in header `X-API-Key`)

## Request body

Required: **no**

### application/json

Schema:

```json
{
  "type": "array",
  "items": {
    "type": [
      "object",
      "null"
    ],
    "oneOf": [
      {
        "type": "object",
        "properties": {
          "user_prompt": {
            "type": "string",
            "description": "<em>AI 模型的提示詞</em><br><strong>必填欄位</strong><br>要傳送給 AI 模型的問題或任務；<br>在 <code>user_prompt</code> 欄位中最多可指定 <strong>500 個字元</strong>"
          },
          "model_name": {
            "type": "string",
            "description": "<em>AI 模型名稱</em><br><strong>必填欄位</strong><br><code>model_name</code > 由實際模型名稱與版本名稱組成；<br>如果只指定基礎模型名稱，將預設設定其最新版本；<br>可個別向以下端點發出請求，取得可用的 LLM 模型清單：<code>https://api.dataforseo.com/v3/ai_optimization/perplexity/llm_responses/models</code>"
          },
          "max_output_tokens": {
            "type": [
              "integer",
              "null"
            ],
            "description": "<em>AI 回應中的最大 token 數</em><br>選填欄位<br>最小值：<code>1</code><br>最大值：<code>4096</code>；<br>預設值：<code>2048</code>；<br><strong>注意：</strong>如果請求中指定的是推理模型，輸出 token 數可能超過指定的 <code>max_output_tokens</code> 上限"
          },
          "temperature": {
            "type": [
              "number",
              "null"
            ],
            "description": "<em>AI 回應的隨機性</em><br>選填欄位<br>值越高，輸出越多元 <br>值越低，輸出越集中<br>最小值：<code>0</code><br>最大值：<code>1.9</code><br>預設值：<code>0.77</code>"
          },
          "top_p": {
            "type": [
              "number",
              "null"
            ],
            "description": "<em>AI 回應的多樣性</em><br>選填欄位 <br>透過限制 token 選擇來控制回應的多樣性<br>最小值：<code>0</code><br>最大值：<code>1</code> <br>預設值：<code>0.9</code>"
          },
          "web_search_country_iso_code": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>網路搜尋本地化用的國家代碼</em><br>選填欄位<br>指定國家 ISO 代碼以取得本地化的網路搜尋結果<br><strong>注意：</strong>僅適用於 Perplexity Sonar 模型<br>範例：<code>US</code>"
          },
          "system_message": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>AI 行為指令</em><br>選填欄位<br>定義 AI 的角色、語氣或特定行為 <br>在 <code>system_message</code> 欄位中最多可指定 <strong>500 個字元</strong>"
          },
          "message_chain": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "type": [
                "object",
                "null"
              ],
              "oneOf": [
                {
                  "type": "object",
                  "properties": {
                    "role": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "訊息來源使用者的角色"
                    },
                    "message": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "訊息文字"
                    }
                  }
                }
              ]
            },
            "description": "對話歷史\n選填欄位\n代表先前對話輪次的訊息物件陣列；\n每個物件必須包含：\nrole 字串，值為 user 或 ai 角色；\nmessage 字串，包含訊息內容（最多 500 個字元）；\n陣列中最多可指定 10 個訊息物件；\n注意：對於 Perplexity 模型，訊息必須嚴格在 user 與 AI 角色之間交替（user → ai）；\n範例：\n\"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?\"}]"
          },
          "tag": {
            "type": [
              "string",
              "null"
            ],
            "description": "<em>使用者自訂任務識別碼</em><br>選填欄位<br><em>字元數上限為 255</em><br>可使用此參數識別任務，並將其與結果對應<br>可在回應的 <code>data</code> 物件中找到指定的 <code>tag</code> 值"
          }
        },
        "example": [
          {
            "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"
          }
        ]
      }
    ]
  },
  "example": [
    {
      "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"
    }
  ]
}
```

## Responses

### 200 — 操作成功

Headers:
- `X-Request-Id` (string) — 聯絡 Felo 支援時需提供的請求識別碼。

**application/json**

Schema: object | null

```json
{
  "type": [
    "object",
    "null"
  ],
  "oneOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResponseInfo"
    }
  ]
}
```

### 400 — 無法處理該要求。請檢查請求參數。

### 401 — 需要有效的 Felo API 金鑰。

### 402 — 由於未符合計費要求，要求無法繼續。

### 403 — 該帳戶無權執行此操作。

### 429 — 已達到要求或支出上限。

### 502 — 服務無法完成該要求。

### 503 — API 或計費服務暫時無法使用。

### 504 — 服務在處理要求時逾時。

### default — 錯誤回應；上游透傳回應可能採用供應商格式

**application/json**

Schema:

```json
{}
```

## Schema definitions

### Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResponseInfo

`#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResponseInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseInfo"
    },
    {
      "type": "object",
      "properties": {
        "tasks": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveTaskInfo"
              }
            ]
          },
          "description": "<em>任務陣列</em>"
        }
      }
    }
  ]
}
```

### Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResultInfo

`#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResultInfo`

```json
{
  "type": "object",
  "properties": {
    "model_name": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>所用 AI 模型的名稱</em>"
    },
    "input_tokens": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>輸入中的 token 數</em><br>處理的 token 總數"
    },
    "output_tokens": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>輸出中的 token 數</em><br>AI 回應中產生的 token 總數"
    },
    "reasoning_tokens": {
      "type": [
        "integer",
        "null"
      ]
    },
    "web_search": {
      "type": [
        "boolean",
        "null"
      ],
      "description": "<em>表示是否使用了網路搜尋</em><br><strong>注意：</strong>在 Perplexity Sonar 模型中，網路搜尋預設為啟用"
    },
    "money_spent": {
      "type": [
        "number",
        "null"
      ],
      "description": "<em>AI token 成本（美元）</em><br>第三方 AI 模型供應商依其<a href=\"https://docs.perplexity.ai/guides/pricing\" target=\"_blank\">定價</a>收取的費用"
    },
    "datetime": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>收到結果的日期與時間</em><br>採用 UTC 格式：“yyyy-mm-dd hh-mm-ss +00:00”<br>範例：<br><code class=\"long-string\">2019-11-15 12:57:46 +00:00</code>"
    },
    "items": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "object",
          "null"
        ],
        "oneOf": [
          {
            "$ref": "#/components/schemas/Response36Afe1097B20_MessageAiOptimizationLlmResponseElementItem"
          }
        ]
      },
      "description": "<em>回應項目陣列</em><br>包含結構化的 AI 回應資料"
    },
    "fan_out_queries": {
      "type": [
        "object",
        "null"
      ],
      "description": "<em>扇出查詢陣列</em><br>包含從主查詢衍生的相關搜尋查詢，以提供更全面的回答"
    }
  }
}
```

### Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveTaskInfo

`#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveTaskInfo`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo"
    },
    {
      "type": "object",
      "properties": {
        "result": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_AiOptimizationPerplexityLlmResponsesLiveResultInfo"
              }
            ]
          },
          "description": "<em>結果陣列</em>"
        }
      }
    }
  ]
}
```

### Response36Afe1097B20_AnnotationInfo

`#/components/schemas/Response36Afe1097B20_AnnotationInfo`

```json
{
  "type": "object",
  "properties": {
    "title": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>引用來源的網域或標題</em>"
    },
    "url": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>指向引用來源的重新導向 URL</em><br>包含指向原始來源的 Vertex AI 重新導向"
    },
    "direct_url": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>引用來源的直接 URL</em><br>包含 `url` 欄位中的 Vertex AI 重新導向所指向的原始來源 URL"
    },
    "start_index": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>註解索引的開始位置</em>"
    },
    "end_index": {
      "type": [
        "integer",
        "null"
      ],
      "description": "<em>註解索引的結束位置</em>"
    },
    "text": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>推理鏈章節的文字</em><br>概述模型思考過程的推理鏈章節文字"
    }
  }
}
```

### Response36Afe1097B20_BaseAiOptimizationLlmResponseElementItem

`#/components/schemas/Response36Afe1097B20_BaseAiOptimizationLlmResponseElementItem`

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": [
        "string",
        "null"
      ],
      "description": "元素類型"
    }
  },
  "additionalProperties": false,
  "discriminator": {
    "propertyName": "type",
    "mapping": {
      "reasoning": "#/components/schemas/Response36Afe1097B20_ReasoningAiOptimizationLlmResponseElementItem",
      "message": "#/components/schemas/Response36Afe1097B20_MessageAiOptimizationLlmResponseElementItem"
    }
  }
}
```

### Response36Afe1097B20_BaseResponseInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseInfo`

```json
{
  "properties": {
    "version": {
      "type": [
        "string",
        "null"
      ],
      "description": "API 的目前版本"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "一般狀態碼\n完整回應碼清單請見此處"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "一般資訊訊息\n完整的一般資訊訊息清單請見此處"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "總執行時間，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任務總費用，美元",
      "format": "double"
    },
    "tasks_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 陣列中的任務數",
      "format": "int64"
    },
    "tasks_error": {
      "type": [
        "integer",
        "null"
      ],
      "description": "tasks 陣列中傳回錯誤的任務數",
      "format": "int64"
    }
  }
}
```

### Response36Afe1097B20_BaseResponseTaskInfo

`#/components/schemas/Response36Afe1097B20_BaseResponseTaskInfo`

```json
{
  "properties": {
    "id": {
      "type": [
        "string",
        "null"
      ],
      "description": "任務識別碼\n我們系統中 UUID 格式的唯一任務識別碼"
    },
    "status_code": {
      "type": [
        "integer",
        "null"
      ],
      "description": "任務的狀態碼\n由 DataForSEO 產生，範圍如下：10000-60000\n完整回應碼清單請見此處"
    },
    "status_message": {
      "type": [
        "string",
        "null"
      ],
      "description": "任務的資訊訊息\n完整的一般資訊訊息清單請見此處"
    },
    "time": {
      "type": [
        "string",
        "null"
      ],
      "description": "執行時間，秒"
    },
    "cost": {
      "type": [
        "number",
        "null"
      ],
      "description": "任務總費用，美元",
      "format": "double"
    },
    "result_count": {
      "type": [
        "integer",
        "null"
      ],
      "description": "result 陣列中的元素數",
      "format": "int64"
    },
    "path": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "string",
          "null"
        ]
      },
      "description": "URL 路徑"
    },
    "data": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": {
        "type": [
          "object",
          "null"
        ]
      },
      "description": "包含你在 POST 請求中指定的相同參數"
    }
  }
}
```

### Response36Afe1097B20_LlmMessageSectionInfo

`#/components/schemas/Response36Afe1097B20_LlmMessageSectionInfo`

```json
{
  "type": "object",
  "properties": {
    "type": {
      "type": [
        "string",
        "null"
      ],
      "description": "元素類型"
    },
    "text": {
      "type": [
        "string",
        "null"
      ],
      "description": "<em>推理鏈章節的文字</em><br>概述模型思考過程的推理鏈章節文字"
    },
    "annotations": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": [
          "object",
          "null"
        ],
        "oneOf": [
          {
            "$ref": "#/components/schemas/Response36Afe1097B20_AnnotationInfo"
          }
        ]
      },
      "description": "<em>用於產生回應的參照陣列</em><br>若 <code>web_search</code> 參數未設為 <code>true</code>，則為 <code>null</code><br><strong>注意：</strong>即使 <code>web_search</code> 為 <code>true</code>，<code>annotations</code> 也可能傳回空值，因為 AI 會嘗試擷取網路資訊，但可能找不到相關結果"
    }
  }
}
```

### Response36Afe1097B20_MessageAiOptimizationLlmResponseElementItem

`#/components/schemas/Response36Afe1097B20_MessageAiOptimizationLlmResponseElementItem`

```json
{
  "type": "object",
  "allOf": [
    {
      "$ref": "#/components/schemas/Response36Afe1097B20_BaseAiOptimizationLlmResponseElementItem"
    },
    {
      "type": "object",
      "properties": {
        "sections": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": [
              "object",
              "null"
            ],
            "oneOf": [
              {
                "$ref": "#/components/schemas/Response36Afe1097B20_LlmMessageSectionInfo"
              }
            ]
          },
          "description": "<em>推理鏈章節</em><br>包含 LLM 產生的推理鏈章節之物件陣列"
        }
      }
    }
  ]
}
```
