> ## 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>

當對話完成時結束現有會話。這對於資源清理和管理很有用。

## 基礎 URL

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

## 結束會話

```bash theme={null}
DELETE /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>

### 回應

<ResponseField name="success" type="boolean">
  指示會話是否成功結束
</ResponseField>

<ResponseField name="sessionId" type="string">
  已結束會話的 ID
</ResponseField>

<ResponseField name="message" type="string">
  會話已結束的確認訊息
</ResponseField>

## 範例

### 請求

```bash theme={null}
curl -X DELETE https://api.pathors.com/project/{projectId}/session \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "session_id": "user-123-session-456"
  }'
```

### 回應

```json theme={null}
{
  "success": true,
  "sessionId": "user-123-session-456",
  "message": "Session ended successfully"
}
```

## 使用說明

* **資源清理**: 結束會話有助於釋放伺服器資源，應該在對話完成時執行
* **會話變數**: 當會話結束時，所有會話變數和對話上下文都將被永久刪除
* **會話管理**: API將嘗試結束指定的會話。無論會話是否處於活躍狀態，都會回傳成功回應

## 錯誤回應

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

錯誤回應範例：

**400 請求錯誤:**

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

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

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

## 最佳實踐

1. **始終結束會話**: 在對話完成時結束會話以防止資源洩漏
2. **錯誤處理**: 優雅地處理錯誤並為失敗的請求實施適當的重試邏輯
3. **會話追蹤**: 在您的應用程式中追蹤活躍的會話 ID，以便正確管理它們
