Completions API
curl --request POST \
--url https://api.pathors.com/project/{projectId}/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{}
],
"stream": true,
"session_id": "<string>",
"tools": [
{}
]
}
'import requests
url = "https://api.pathors.com/project/{projectId}/chat/completions"
payload = {
"messages": [{}],
"stream": True,
"session_id": "<string>",
"tools": [{}]
}
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({messages: [{}], stream: true, session_id: '<string>', tools: [{}]})
};
fetch('https://api.pathors.com/project/{projectId}/chat/completions', 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}/chat/completions",
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([
'messages' => [
[
]
],
'stream' => true,
'session_id' => '<string>',
'tools' => [
[
]
]
]),
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}/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\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}/chat/completions")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pathors.com/project/{projectId}/chat/completions")
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 \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{}
],
"session_id": "<string>",
"choices[].message.tool_calls": [
{}
],
"choices[].finish_reason": "<string>"
}已棄用 API
Completions API
使用我們的 OpenAI 兼容聊天完成 API 與任何平台整合。
POST
/
project
/
{projectId}
/
chat
/
completions
Completions API
curl --request POST \
--url https://api.pathors.com/project/{projectId}/chat/completions \
--header 'Authorization: <authorization>' \
--header 'Content-Type: application/json' \
--data '
{
"messages": [
{}
],
"stream": true,
"session_id": "<string>",
"tools": [
{}
]
}
'import requests
url = "https://api.pathors.com/project/{projectId}/chat/completions"
payload = {
"messages": [{}],
"stream": True,
"session_id": "<string>",
"tools": [{}]
}
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({messages: [{}], stream: true, session_id: '<string>', tools: [{}]})
};
fetch('https://api.pathors.com/project/{projectId}/chat/completions', 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}/chat/completions",
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([
'messages' => [
[
]
],
'stream' => true,
'session_id' => '<string>',
'tools' => [
[
]
]
]),
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}/chat/completions"
payload := strings.NewReader("{\n \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\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}/chat/completions")
.header("Authorization", "<authorization>")
.header("Content-Type", "application/json")
.body("{\n \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pathors.com/project/{projectId}/chat/completions")
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 \"messages\": [\n {}\n ],\n \"stream\": true,\n \"session_id\": \"<string>\",\n \"tools\": [\n {}\n ]\n}"
response = http.request(request)
puts response.read_body{
"id": "<string>",
"object": "<string>",
"created": 123,
"model": "<string>",
"choices": [
{}
],
"session_id": "<string>",
"choices[].message.tool_calls": [
{}
],
"choices[].finish_reason": "<string>"
}已棄用。 此端點已棄用,將於 2026-07-11 下架。在此之前仍可使用。請改用 V1 路徑—完整的新舊路徑對照見遷移指南。
基礎 URL
https://api.pathors.com
聊天完成
POST /project/{projectId}/chat/completions
路徑參數
您的專案 ID
請求頭
使用您的 Project API Key(以
sk_ 開頭)進行 Bearer 令牌認證。格式:Bearer {your-api-key}會話 ID,用於對話連續性。強烈建議使用此標頭傳遞會話 ID,而不是請求體中的
session_id 參數。
請求體
對話中的訊息陣列。每條訊息都應該有一個
role(“system”、“user” 或
“assistant”)和 content。是否流式傳輸回應。默認為 false。
(deprecated) 會話 ID,用於對話連續性。建議使用 X-Session-ID
標頭代替。僅在不支持自訂標頭的環境中使用此參數。
可供助手使用的外部工具定義陣列。每個工具應該有一個
type(目前僅支持 “function”)和一個包含 name、description 和 parameters(JSON Schema 格式)的 function 物件。{
"messages": [
{
"role": "user",
"content": "你好!"
}
],
"stream": false
}
{
"messages": [
{
"role": "user",
"content": "舊金山的天氣怎麼樣?"
}
],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "獲取當前天氣資訊",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "城市名稱"
}
},
"required": ["location"]
}
}
}
]
}
回應頭
對話的會話 ID。此頭部會在回應中返回,可用於後續請求。
回應
完成的唯一標識符
物件類型(“chat.completion”)
完成創建時的 Unix 時間戳
用於完成的模型
完成選項陣列
對話的會話 ID
助手進行的工具調用陣列(當提供並使用工具時)
完成終止的原因。正常完成時為 “stop”,調用工具時為 “tool_calls”。
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677858242,
"model": "pathway-default",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好!我能幫你什麼忙?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": -1,
"completion_tokens": -1,
"total_tokens": -1
},
"session_id": "session-xyz789"
}
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1677858242,
"model": "pathway-default",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"舊金山\"}"
}
}
]
},
"finish_reason": "tool_calls"
}
],
"usage": {
"prompt_tokens": -1,
"completion_tokens": -1,
"total_tokens": -1
},
"session_id": "session-xyz789"
}
流式回應
當stream 設置為 true 時,回應將以伺服器發送事件(SSE)的形式流式傳輸。每個事件包含以下格式的回應塊:
{
"id": "chatcmpl-abc123",
"object": "chat.completion.chunk",
"created": 1677858242,
"model": "pathway-default",
"choices": [
{
"index": 0,
"delta": {
"content": "你好"
},
"finish_reason": null
}
],
"session_id": "session-xyz789"
}
finish_reason: "stop",並跟隨 data: [DONE]。
錯誤回應
| 狀態碼 | 描述 |
|---|---|
| 400 | 無效的請求體 |
| 401 | 無效的認證 |
| 500 | 內部伺服器錯誤 |
使用工具
當您在請求中提供工具時,助手可以在對話中調用它們。在收到帶有tool_calls 的回應後,您應該:
- 使用提供的參數執行請求的工具
- 在後續請求中以 “tool” 角色訊息發送工具結果
- 助手然後將使用工具結果來製定其最終回應
工具訊息格式
收到工具調用後,發送結果:{
"messages": [
{"role": "user", "content": "天氣怎麼樣?"},
{
"role": "assistant",
"content": "",
"tool_calls": [
{
"id": "call_123",
"type": "function",
"function": {
"name": "get_weather",
"arguments": "{\"location\": \"舊金山\"}"
}
}
]
},
{
"role": "tool",
"content": "22°C,晴朗",
"tool_call_id": "call_123",
"name": "get_weather"
}
],
"session_id": "existing_session_id"
}
設置指南
- 前往 Project Settings > API Keys 建立新的 API 金鑰
- 立即複製金鑰(金鑰僅顯示一次)
- 在請求中使用
Authorization: Bearer {your-api-key}頭部 - (可選)使用會話 API建立會話以維持對話連續性
- (可選)定義並提供工具以擴展功能
⌘I
