# 聊天與回應介面

OpenAI 相容聊天介面。依下方範例串接即可。

### 1. 聊天對話介面 (Chat Completions)
* **路徑**: `/v1/chat/completions`
* **請求方式**: `POST`

#### 核心請求參數說明
| 參數名稱 | 型別 | 必填 | 說明 |
| :--- | :--- | :--- | :--- |
| `model` | `string` | 是 | 目標模型名稱，例如 `gpt-4o`, `claude-3-5-sonnet-20241022`, `gemini-1.5-pro` |
| `messages` | `array` | 是 | 歷史對話訊息陣列，如 `[{"role": "user", "content": "你好"}]` |
| `stream` | `boolean` | 否 | 是否以 SSE 事件串流（串流逐字回傳）方式回傳（預設 `false`） |
| `temperature` | `number` | 否 | 取樣溫度 (0~2)，數值越高隨機性越強，建議 `0.7` ~ `1.0` |
| `max_tokens` | `integer` | 否 | 模型最大生成 Token 數量限制 |
| `tools` | `array` | 否 | 模型可呼叫的工具（Function Calling）清單 |

#### 終端機呼叫範例 (Curl)
```bash
curl -X POST https://www.tokenpad.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "請解釋什麼是量子糾纏。"}
    ],
    "stream": false
  }'
```

### 2. Responses 介面
* **路徑**: `/v1/responses`
* **請求方式**: `POST`

> [!NOTE]
> 若用戶端已使用 Responses 請求主體格式，可呼叫 `/v1/responses`。計費、配額與用量日誌仍會生效。

#### 請求範例
```json
{
  "model": "gpt-4o",
  "input": [
    {"role": "user", "content": "透傳請求內容"}
  ],
  "stream": false
} 
```