# Perplexity Sonar Pro

**API:** Data API

**Endpoint:** `POST /v1/beta/perplexity/sonar-pro`

**Tags:** Perplexity API

透過網路搜尋與引用為多部分問題產生回答。model 與 messages 為必填；此端點請使用模型 sonar-pro。此公開契約涵蓋 stream 為 false 的非串流 JSON 回應。請從 choices[].message.content、citations 與 search_results 讀取回答及其來源。usage 回報資源消耗，並非 Felo 額度扣費。

### 定價參考

- 計量方式：依回報的回應成本計量。
- 參考請求預估：USD 0.11273。
- 參考客戶乘數：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: **yes**

### application/json

Schema:

```json
{
  "type": "object",
  "required": [
    "model",
    "messages"
  ],
  "properties": {
    "model": {
      "type": "string",
      "description": "要使用的 Sonar 模型。",
      "enum": [
        "sonar",
        "sonar-pro",
        "sonar-reasoning-pro",
        "sonar-deep-research"
      ]
    },
    "messages": {
      "type": "array",
      "description": "包含目前對話的訊息清單。",
      "items": {
        "type": "object",
        "required": [
          "role",
          "content"
        ],
        "properties": {
          "role": {
            "type": "string",
            "enum": [
              "system",
              "user",
              "assistant"
            ],
            "description": "訊息作者的角色。"
          },
          "content": {
            "type": "string",
            "description": "訊息內容。"
          }
        }
      }
    },
    "max_tokens": {
      "type": "integer",
      "description": "回應中要產生的 token 數上限。"
    },
    "temperature": {
      "type": "number",
      "description": "取樣溫度，介於 0 到 2 之間。值越低，輸出越聚焦、越確定。",
      "default": 0.2,
      "minimum": 0,
      "maximum": 2
    },
    "top_p": {
      "type": "number",
      "description": "核心取樣參數。模型只考慮累積機率達到 top_p 的 token。",
      "default": 0.9,
      "minimum": 0,
      "maximum": 1
    },
    "top_k": {
      "type": "integer",
      "description": "top-k 過濾保留的 token 數。",
      "default": 0,
      "minimum": 0,
      "maximum": 2048
    },
    "stream": {
      "type": "boolean",
      "description": "是否使用伺服器傳送事件以串流方式傳回回應。",
      "default": false
    },
    "search_context": {
      "type": "string",
      "description": "控制使用的搜尋上下文數量。會影響每次請求的成本。",
      "enum": [
        "low",
        "medium",
        "high"
      ],
      "default": "low"
    },
    "frequency_penalty": {
      "type": "number",
      "description": "依新 token 在目前文本中的出現頻率對其施加懲罰。正值會降低逐字重複同一行的可能性。",
      "default": 1,
      "minimum": 0,
      "maximum": 2
    },
    "presence_penalty": {
      "type": "number",
      "description": "依新 token 是否已出現在目前文本中對其施加懲罰。正值會提高談論新話題的可能性。",
      "default": 0,
      "minimum": -2,
      "maximum": 2
    },
    "return_citations": {
      "type": "boolean",
      "description": "是否在回應中傳回引用與搜尋結果。",
      "default": true
    },
    "search_recency_filter": {
      "type": "string",
      "description": "依新鮮度篩選搜尋結果。",
      "enum": [
        "month",
        "week",
        "day",
        "hour"
      ]
    },
    "search_domain_filter": {
      "type": "array",
      "description": "將搜尋限制在特定網域。",
      "items": {
        "type": "string"
      }
    }
  }
}
```

Example:

```json
{
  "model": "sonar-pro",
  "messages": [
    {
      "role": "user",
      "content": "Compare Cache-Control no-cache and no-store, citing HTTP documentation."
    }
  ],
  "max_tokens": 1024,
  "stream": false
}
```

## Responses

### 200 — 成功回應，包含 AI 回答與引用

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

**application/json**

Schema: `ResponseD5E2470Dd28B_ChatCompletionResponse` (`#/components/schemas/ResponseD5E2470Dd28B_ChatCompletionResponse`)

Example:

```json
{
  "id": "example-sonar-pro-completion",
  "model": "sonar-pro",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "no-cache requires validation before reuse; no-store prohibits storage. [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": 25,
    "completion_tokens": 40,
    "total_tokens": 65
  }
}
```

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

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

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

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

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

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

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

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

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

**application/json**

Schema:

```json
{}
```

## Schema definitions

### ResponseD5E2470Dd28B_ChatCompletionResponse

`#/components/schemas/ResponseD5E2470Dd28B_ChatCompletionResponse`

```json
{
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "description": "補全的唯一識別碼。"
    },
    "model": {
      "type": "string",
      "description": "用於補全的模型。"
    },
    "object": {
      "type": "string",
      "example": "chat.completion"
    },
    "created": {
      "type": "integer",
      "description": "建立補全時的 Unix 時間戳。"
    },
    "choices": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "index": {
            "type": "integer"
          },
          "message": {
            "type": "object",
            "properties": {
              "role": {
                "type": "string"
              },
              "content": {
                "type": "string",
                "description": "AI 產生的回答，帶有 [1][2] 這類行內引用標記。"
              }
            }
          },
          "finish_reason": {
            "type": "string",
            "enum": [
              "stop",
              "length"
            ]
          }
        }
      }
    },
    "citations": {
      "type": "array",
      "description": "回答中引用的來源 URL 清單。",
      "items": {
        "type": "string"
      }
    },
    "search_results": {
      "type": "array",
      "description": "包含標題、摘要與 URL 的詳細搜尋結果。",
      "items": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string"
          },
          "url": {
            "type": "string"
          },
          "snippet": {
            "type": "string"
          },
          "date": {
            "type": "string"
          },
          "source": {
            "type": "string"
          }
        }
      }
    },
    "usage": {
      "type": "object",
      "properties": {
        "prompt_tokens": {
          "type": "integer"
        },
        "completion_tokens": {
          "type": "integer"
        },
        "total_tokens": {
          "type": "integer"
        },
        "search_context_size": {
          "type": "string"
        }
      }
    }
  }
}
```
