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

# 建立會話

> 建立一個帶有可選初始變數的新會話。

<Warning>
  **已棄用。** 此端點已棄用，將於 **2026-07-11 下架**。在此之前仍可使用。請改用 V1 路徑--完整的新舊路徑對照見[遷移指南](/zh-Hant/migrations/2026-06-outbound-api-v1)。
</Warning>

建立一個新會話，可用於在多個 API 呼叫之間維護對話上下文。

## 基礎 URL

```
https://api.pathors.com
```

## 建立會話

```bash theme={null}
POST /project/{projectId}/session
```

### 路徑參數

<ParamField path="projectId" type="string" required>
  您的專案 ID
</ParamField>

### 請求標頭

<ParamField header="Authorization" type="string" required>
  使用您的 Project API Key（以 `sk_` 開頭）進行 Bearer 令牌認證。格式：`Bearer {your-api-key}`
</ParamField>

### 請求主體

<ParamField body="session_id" type="string" required>
  會話的唯一識別符。這可以是您選擇的任何字串來識別對話會話。
</ParamField>

<ParamField body="variables" type="object">
  可在路徑內使用的可選初始會話變數。這些變數可以在您的路徑配置中引用。
</ParamField>

<ParamField body="provider" type="string">
  會話的可選提供商規範（例如："api"、"web"）
</ParamField>

### 回應

<ResponseField name="sessionId" type="string">
  建立的會話 ID（與請求中提供的相同）
</ResponseField>

<ResponseField name="pathwayId" type="string">
  此專案的路徑 ID
</ResponseField>

## 範例

### 請求

```bash theme={null}
curl -X POST https://api.pathors.com/project/{projectId}/session \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "session_id": "user-123-session-456",
    "variables": {
      "userName": "王小明",
      "userRole": "admin",
      "customData": "value"
    },
    "provider": "api"
  }'
```

### 回應

```json theme={null}
{
  "sessionId": "user-123-session-456",
  "pathwayId": "project-id-xxx"
}
```

## 使用說明

* **會話 ID**: 為每個對話選擇一個唯一識別符。這可以是 UUID、使用者 ID + 時間戳記或任何其他唯一字串。
* **變數**: 會話變數可以在您的路徑邏輯中使用。它們在整個會話期間持續存在，並可在對話流程中引用。
* **可重複使用性**: 建立後，透過包含 `session_id` 參數或 `X-Session-ID` 標頭，會話可以在多個完成請求中使用。

## 錯誤回應

| 狀態碼 | 描述                 |
| --- | ------------------ |
| 400 | 缺少或無效的 session\_id |
| 401 | 無效的認證              |
| 500 | 內部伺服器錯誤            |

錯誤回應範例：

**400 請求錯誤:**

```json theme={null}
{
  "error": "session_id is required"
}
```

**401 身份驗證失敗:**

```json theme={null}
{
  "error": {
    "message": "Invalid authentication"
  }
}
```
