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

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

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

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

print(response.text)
const options = {
method: 'POST',
headers: {Authorization: '<authorization>', 'Content-Type': 'application/json'},
body: JSON.stringify({session_id: '<string>', variables: {}, provider: '<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 => "POST",
CURLOPT_POSTFIELDS => json_encode([
'session_id' => '<string>',
'variables' => [

],
'provider' => '<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 \"variables\": {},\n \"provider\": \"<string>\"\n}")

req, _ := http.NewRequest("POST", 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.post("https://api.pathors.com/project/{projectId}/session")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"session_id\": \"<string>\",\n \"variables\": {},\n \"provider\": \"<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::Post.new(url)
request["Authorization"] = '<authorization>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"session_id\": \"<string>\",\n \"variables\": {},\n \"provider\": \"<string>\"\n}"

response = http.request(request)
puts response.read_body
{
  "sessionId": "<string>",
  "pathwayId": "<string>"
}
已棄用。 此端點已棄用,將於 2026-07-11 下架。在此之前仍可使用。請改用 V1 路徑—完整的新舊路徑對照見遷移指南
建立一個新會話,可用於在多個 API 呼叫之間維護對話上下文。

基礎 URL

https://api.pathors.com

建立會話

POST /project/{projectId}/session

路徑參數

projectId
string
必填
您的專案 ID

請求標頭

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

請求主體

session_id
string
必填
會話的唯一識別符。這可以是您選擇的任何字串來識別對話會話。
variables
object
可在路徑內使用的可選初始會話變數。這些變數可以在您的路徑配置中引用。
provider
string
會話的可選提供商規範(例如:“api”、“web”)

回應

sessionId
string
建立的會話 ID(與請求中提供的相同)
pathwayId
string
此專案的路徑 ID

範例

請求

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

回應

{
  "sessionId": "user-123-session-456",
  "pathwayId": "project-id-xxx"
}

使用說明

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

錯誤回應

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