> ## Documentation Index
> Fetch the complete documentation index at: https://aisa.one/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Sonar

> Sonar — 轻量级搜索与回答

Sonar 是 Perplexity 的轻量级搜索模型，将 LLM 能力与内置网络搜索相结合。它会返回 AI 生成的答案，并包含来自网络来源的行内引用。

**最适合：** 快速事实查询、简单问答和实时信息检索。

**模型：** `sonar`

## 示例

```bash theme={null}
curl -X POST "https://api.aisa.one/apis/v1/perplexity/sonar" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sonar",
    "messages": [
      {"role": "user", "content": "What are the latest developments in quantum computing?"}
    ]
  }'
```

## 响应

响应遵循 OpenAI 聊天补全格式，并包含额外的 `citations` 和 `search_results` 字段，其中列出了生成答案时使用的网络来源。


## OpenAPI

````yaml openapi/zh/perplexity-openapi.json POST /perplexity/sonar
openapi: 3.0.0
info:
  title: Perplexity Sonar API
  version: 1.0.0
  description: Perplexity Sonar API——内置网页搜索功能的 LLM。返回 AI 生成的答案，并附有网页来源引用。
servers:
  - url: https://api.aisa.one/apis/v1
security:
  - bearerAuth: []
paths:
  /perplexity/sonar:
    post:
      tags:
        - Perplexity Sonar
      summary: Sonar — 轻量级搜索与回答
      description: |-
        适用于快速网页搜索并生成 AI 答案的高性价比模型。最适合简单的事实性查询。使用模型 `sonar`。

        **价格：** 每次请求 $0.012
      operationId: post_perplexity-sonar
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatCompletionRequest'
            example:
              model: sonar
              messages:
                - role: user
                  content: What are the latest developments in quantum computing?
      responses:
        '200':
          description: 包含 AI 答案和引用的成功响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatCompletionResponse'
components:
  schemas:
    ChatCompletionRequest:
      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: 响应中要生成的最大词元数。
        temperature:
          type: number
          description: 介于 0 和 2 之间的采样温度。较低的值会使输出更集中且更具确定性。
          default: 0.2
          minimum: 0
          maximum: 2
        top_p:
          type: number
          description: 核采样参数。模型会考虑累计概率质量达到 top_p 的词元。
          default: 0.9
          minimum: 0
          maximum: 1
        top_k:
          type: integer
          description: 用于 top-k 筛选的保留词元数。
          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: 根据新词元目前在文本中的出现频率对其施加惩罚。正值会降低逐字重复同一行的可能性。
          default: 1
          minimum: 0
          maximum: 2
        presence_penalty:
          type: number
          description: 根据新词元此前是否已出现在文本中对其施加惩罚。正值会提高谈论新主题的可能性。
          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
    ChatCompletionResponse:
      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
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````