POST
/
api
/
project
/
{projectId}
/
integration
/
vapi
/
chat
/
completions
curl --request POST \
  --url https://app.pathors.com/api/project/{projectId}/integration/vapi/chat/completions \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
  "messages": [
    {}
  ],
  "stream": true,
  "call": {},
  "phoneNumber": {},
  "customer": {}
}'
{
  "id": "<string>",
  "object": "<string>",
  "created": 123,
  "model": "<string>",
  "choices": [
    {}
  ],
  "session_id": "<string>"
}

VAPI 集成

VAPI 集成提供了一个专门设计用于通过语音 API 服务处理电话通话对话的聊天完成端点。

聊天完成

路径参数

projectId
string
required

您的项目 ID

请求体

messages
array
required

对话中的消息数组。每条消息都应该有一个 role(“system”、“user” 或 “assistant”)和 content

stream
boolean

是否流式传输响应。默认为 false。

call
object
required

当前通话会话的信息。

{
  id: string;          // 通话 ID
  orgId: string;       // 组织 ID
  createdAt: string;   // 通话创建时间戳
  updatedAt: string;   // 通话更新时间戳
  type: string;        // 通话类型
  status: string;      // 通话状态
  assistantId: string; // 助手 ID
  customer?: {
    number: string;    // 客户电话号码
  };
  phoneNumberId?: string;        // 电话号码 ID
  phoneCallProvider?: string;    // 通话提供商(如 Twilio)
  phoneCallProviderId?: string;  // 提供商特定的通话 ID
  phoneCallTransport?: string;   // 通话传输方式
}
phoneNumber
object

可选的电话号码配置。

{
  id: string;              // 电话号码 ID
  orgId: string;           // 组织 ID
  number: string;          // 电话号码
  createdAt: string;       // 创建时间戳
  updatedAt: string;       // 更新时间戳
  twilioAccountSid: string;// Twilio 账户 SID
  twilioAuthToken: string; // Twilio 认证令牌
  name: string;            // 电话号码名称
  provider: string;        // 电话提供商
}
customer
object

可选的客户信息。

{
  number: string;  // 客户电话号码
}

请求示例:

{
  "messages": [
    {
      "role": "user",
      "content": "你好!"
    }
  ],
  "stream": false,
  "call": {
    "id": "call_abc123",
    "orgId": "org_xyz789",
    "type": "inbound",
    "status": "in-progress",
    "assistantId": "asst_def456"
  }
}

响应

响应格式与 API 集成的聊天完成端点相同,并增加了电话通话的会话管理。

id
string

完成的唯一标识符

object
string

对象类型(“chat.completion”)

created
number

完成创建时的 Unix 时间戳

model
string

用于完成的模型

choices
array

完成选项数组

session_id
string

对话的会话 ID

响应示例:

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

流式响应

流式响应格式与 API 集成的流式格式相同。

错误响应

状态码描述
400无效的请求体或缺少通话 ID
500内部服务器错误

会话管理

VAPI 集成基于通话 ID 自动管理会话。它将:

  1. 为回访的来电者查找现有会话
  2. 为首次来电者创建新会话
  3. 在整个通话过程中维护对话上下文