# Perplexity Sonar

**API:** Data API

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

**Tags:** Perplexity API

สร้างคำตอบกระชับพร้อมการอ้างอิงเว็บ ต้องระบุ model และ messages; ใช้ model sonar สำหรับ endpoint นี้ สัญญาสาธารณะนี้ครอบคลุมการตอบกลับ JSON แบบไม่สตรีมมิ่งด้วย stream false อ่านคำตอบจาก choices[].message.content และแหล่งที่มาจาก citations และ search_results usage รายงานการใช้ทรัพยากร ไม่ใช่ค่าบริการเครดิต Felo

### ข้อมูลอ้างอิงราคา

- การวัดปริมาณการใช้งาน: ต้นทุนการตอบกลับที่รายงาน
- ค่าประมาณคำขออ้างอิง: USD 0.12783
- ตัวคูณอ้างอิงสำหรับลูกค้า: 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": "จำนวนโทเคนสูงสุดที่จะสร้างในการตอบกลับ"
    },
    "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": "ว่าจะสตรีมการตอบกลับโดยใช้ server-sent events หรือไม่",
      "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"
      }
    }
  }
}
```

Example:

```json
{
  "model": "sonar",
  "messages": [
    {
      "role": "user",
      "content": "What is HTTP caching? Cite the relevant documentation."
    }
  ],
  "max_tokens": 512,
  "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-completion",
  "model": "sonar",
  "object": "chat.completion",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "HTTP caching reuses stored responses when permitted by cache rules. [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": 20,
    "completion_tokens": 30,
    "total_tokens": 50
  }
}
```

### 400 — ไม่สามารถประมวลผลคำขอได้ ตรวจสอบพารามิเตอร์ของคำขอ

### 401 — จำเป็นต้องใช้คีย์ API ของ Felo ที่ถูกต้อง

### 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": "ตัวระบุเฉพาะของ completion"
    },
    "model": {
      "type": "string",
      "description": "โมเดลที่ใช้สำหรับ completion"
    },
    "object": {
      "type": "string",
      "example": "chat.completion"
    },
    "created": {
      "type": "integer",
      "description": "เวลาประทับยูนิกซ์เมื่อสร้าง completion"
    },
    "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"
        }
      }
    }
  }
}
```
