跳轉到主要內容
DELETE
/
project
/
{projectId}
/
session
結束會話
curl --request DELETE \
  --url https://api.pathors.com/project/{projectId}/session \
  --header 'Authorization: <authorization>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "session_id": "<string>"
}
'
import requests

url = "https://api.pathors.com/project/{projectId}/session"

payload = { "session_id": "<string>" }
headers = {
"Authorization": "<authorization>",
"Content-Type": "application/json"
}

response = requests.delete(url, json=payload, headers=headers)

print(response.text)
const options = {
method: 'DELETE',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({session_id: '<string>'})
};

fetch('https://api.pathors.com/project/{projectId}/session', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));
<?php

$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pathors.com/project/{projectId}/session",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "DELETE",
CURLOPT_POSTFIELDS => json_encode([
'session_id' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: <authorization>",
"Content-Type: application/json"
],
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
package main

import (
"fmt"
"strings"
"net/http"
"io"
)

func main() {

url := "https://api.pathors.com/project/{projectId}/session"

payload := strings.NewReader("{\n \"session_id\": \"<string>\"\n}")

req, _ := http.NewRequest("DELETE", url, payload)

req.Header.Add("Authorization", "<authorization>")
req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))

}
HttpResponse<String> response = Unirest.delete("https://api.pathors.com/project/{projectId}/session")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<string>\"\n}")
.asString();
require 'uri'
require 'net/http'

url = URI("https://api.pathors.com/project/{projectId}/session")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Delete.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "success": true,
  "sessionId": "<string>",
  "message": "<string>"
}
已棄用。 此端點已棄用,將於 2026-07-11 下架。在此之前仍可使用。請改用 V1 路徑—完整的新舊路徑對照見遷移指南
當對話完成時結束現有會話。這對於資源清理和管理很有用。

基礎 URL

https://api.pathors.com

結束會話

DELETE /project/{projectId}/session

路徑參數

projectId
string
必填
您的專案 ID

請求標頭

Authorization
string
必填
使用您的 Project API Key(以 sk_ 開頭)進行 Bearer 令牌認證。格式:Bearer {your-api-key}

請求內容

session_id
string
必填
要結束的會話的唯一識別符

回應

success
boolean
指示會話是否成功結束
sessionId
string
已結束會話的 ID
message
string
會話已結束的確認訊息

範例

請求

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"
  }'

回應

{
  "success": true,
  "sessionId": "user-123-session-456",
  "message": "Session ended successfully"
}

使用說明

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

錯誤回應

狀態碼描述
400缺少或無效的 session_id
401無效的身份驗證
500內部伺服器錯誤
錯誤回應範例: 400 請求錯誤:
{
  "error": "session_id is required"
}
401 身份驗證失敗:
{
  "error": {
    "message": "Invalid authentication"
  }
}

最佳實踐

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