結束會話
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>"
}已棄用 API
結束會話
結束現有會話以清理資源並終止對話上下文。
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
路徑參數
您的專案 ID
請求標頭
使用您的 Project API Key(以
sk_ 開頭)進行 Bearer 令牌認證。格式:Bearer {your-api-key}請求內容
要結束的會話的唯一識別符
回應
指示會話是否成功結束
已結束會話的 ID
會話已結束的確認訊息
範例
請求
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 | 內部伺服器錯誤 |
{
"error": "session_id is required"
}
{
"error": {
"message": "Invalid authentication"
}
}
最佳實踐
- 始終結束會話: 在對話完成時結束會話以防止資源洩漏
- 錯誤處理: 優雅地處理錯誤並為失敗的請求實施適當的重試邏輯
- 會話追蹤: 在您的應用程式中追蹤活躍的會話 ID,以便正確管理它們
⌘I
