Skip to main content
POST
Initiate Speech-to-Speech WebRTC Session

启动语音到语音 WebRTC 会话

使用 OpenAI Realtime API 建立用于实时语音到语音对话的 WebRTC 连接。

端点

说明

使用 OpenAI Realtime API 建立用于实时语音到语音对话的 WebRTC 连接。该端点接受 WebRTC SDP 提议并返回 SDP 应答,该应答可用于与 OpenAI 的实时 API 建立对等连接。

使用流程

  1. 客户端创建WebRTC报价(RTCPeerConnection.createOffer)
  2. 客户端将 SDP Offer 发送到该端点
  3. 该端点代理 OpenAI Realtime API 的报价
  4. 客户端收到SDP应答并建立WebRTC连接
  5. 客户可以与AI进行实时语音对话

S2S时间追踪

  • 每个用户都有基于其许可证的每月 S2S 时间配额
  • 时间以分钟为单位进行跟踪,并在记录会话时扣除
  • 使用/speech/s2s/status查看剩余时间
  • 使用/speech/s2s/log-session记录会话持续时间并扣除时间

SMLTP 集成

  • 所有请求均通过 SMLTP 处理,以确保安全性和合规性
  • 根据指定的 SMLTP 策略强制执行模型验证
  • 审核并记录请求以进行合规性跟踪

身份验证

必需:API 密钥

请求正文

可用型号

  • gpt-4o-mini-realtime-preview
  • gpt-4o-realtime-preview

可用的声音

  • alloy(默认)
  • echo
  • fable
  • onyx
  • nova
  • shimmer
  • ash
  • ballad
  • coral

可用的 SMLTP 策略

  • public
  • internal(默认)
  • internal-strict
  • confidential
  • hipaa
  • gdpr
  • pci-dss

请求示例

JavaScript/Node.js

###Python

回应

成功响应 (200)

内容类型:application/sdp 响应是一个 SDP 应答字符串,可与 RTCPeerConnection.setRemoteDescription() 一起使用。

错误响应

400 错误请求

403 禁止

S2S 已达到时间限制

模型验证失败

500 内部服务器错误

注释

  • SDP优惠必须是有效的WebRTC SDP优惠字符串
  • 收到 SDP 应答后,用它来设置 RTCPeerConnection 上的远程描述
  • 使用 /speech/s2s/status 启动会话之前检查 S2S 时间状态
  • 使用 /speech/s2s/log-session 完成后记录会话持续时间
  • 所有请求均通过 SMLTP 处理,以确保安全性和合规性
  • user_id 参数允许向不同的用户帐户计费

授权

Authorization
string
header
必填

API key authentication using Bearer token format. Example: Authorization: Bearer sk-your-api-key-here

请求体

application/json
sdp
string
必填

WebRTC SDP offer from the client's RTCPeerConnection

示例:

"v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n..."

model
enum<string>
默认值:gpt-4o-mini-realtime-preview

OpenAI Realtime model to use

可用选项:
gpt-4o-mini-realtime-preview,
gpt-4o-realtime-preview
voice
enum<string>
默认值:alloy

Voice to use for the AI response

可用选项:
alloy,
echo,
fable,
onyx,
nova,
shimmer,
ash,
ballad,
coral
smltp_policy
enum<string>
默认值:internal

SMLTP policy to apply for this session

可用选项:
public,
internal,
internal-strict,
confidential,
hipaa,
gdpr,
pci-dss
output_audio
boolean
默认值:true

Whether to enable audio output (default: true)

user_id
string

Optional user ID to bill this session to (defaults to API key owner)

示例:

"60a7c8f5e8b4f5001f7a8c23"

instructions
string

Optional system instructions for the AI assistant

示例:

"You are a helpful customer service agent."

响应

SDP answer from OpenAI Realtime API

SDP answer that can be used with RTCPeerConnection.setRemoteDescription()