OpenAI 创建 Live 会话
创建会话
post /live/sessions
创建 Live WebRTC 会话,或发起 SIP 外呼。配置会话时,先阅读 Live 提示词指南;中继配置与通话监控请参阅 电话与 SIP 中的说明。
使用 WebRTC 时,将 transport.type 设为 webrtc 并提供 SDP 提议;使用 SIP 时,将其设为 sip,
并提供 E.164 格式的被叫号码与中继凭据。
振铃最长为 3 分钟,接通后通话最长为 2 小时;
这些限制不能通过请求配置。
会话初始化后返回 201 Created。WebRTC 响应包含
SDP 应答。SIP 响应不会等待被叫接听。可通过
session.id 建立旁路连接,监控 SIP 通话进展。
每个 SIP 请求都会创建一次新呼叫。如果请求超时或连接 失败,重试时须谨慎:原始请求可能已成功, 重试可能再次拨出电话。
请求体参数
内容类型:application/json
session: MediaSessionConfig
Live 会话的启动配置。
model: string or "gpt-live-1"
Live 模型。无论采用哪种传输方式,均须在会话配置中指定;不要通过 URL 查询参数传入。
string
minLength: 1
"gpt-live-1"
Live 模型。无论采用哪种传输方式,均须在会话配置中指定;不要通过 URL 查询参数传入。
"gpt-live-1"
audio: optional object { output }
启动时的音频配置。WebRTC 与 SIP 通过媒体传输协商音频格式。
output: optional object { voice }
Live 模型生成语音的配置。须在启动会话前选择音色。
voice: optional string or "alloy" or "ash" or "ballad" or 35 more or CustomVoice
Live 语音使用的音色,可以是内置音色名称,也可以是包含 ID 的自定义音色对象。默认为 marin,启动后不能更改。
string
"alloy" or "ash" or "ballad" or 35 more
Live 语音使用的音色,可以是内置音色名称,也可以是包含 ID 的自定义音色对象。默认为 marin,启动后不能更改。
"alloy"
"ash"
"ballad"
"beacon"
"bossa"
"brise"
"calandria"
"cedar"
"cinder"
"compas"
"coral"
"delta"
"destello"
"echo"
"flitz"
"gleam"
"halo"
"harema"
"hornero"
"juni"
"luciernaga"
"marin"
"meridian"
"nira"
"noeul"
"nuri"
"pearl"
"quartz"
"ripple"
"sage"
"shida"
"shimmer"
"sillage"
"stone"
"tempo"
"verse"
"vesper"
"willow"
CustomVoice object { id }
id: string
minLength: 1, maxLength: 128
client: optional ClientConfig
仅在启动时设置的能力权限,适用于连接到统一 WebRTC 会话的不可信前端,不影响可信的旁路连接。
data_channel: DataChannelConfig
WebRTC 前端数据通道的客户端与服务端事件权限。
allowed_client_events: optional "all" or array of string
前端数据通道可发送的客户端事件类型。使用 'all' 允许所有客户端事件,空数组表示全部禁止。省略时保留原有的全部允许行为。
"all"
"all"
array of string
maxItems: 256
allowed_server_events: optional "all" or array of ServerEventSelector
可发送到前端数据通道的服务端事件。使用 'all' 允许所有服务端事件,空数组表示全部禁止。省略时保留原有的全部允许行为。Responses 事件通过包含 type 'response.event' 和 response_event 选择器的对象指定。
"all"
"all"
array of ServerEventSelector
maxItems: 256
type: string
外层 Live 服务端事件类型。对于 Responses 事件,使用 'response.event'。
minLength: 1, maxLength: 256
response_event: optional string
内嵌的 Responses 事件类型。type 为 'response.event' 时必填;其他事件类型禁止使用此字段。
minLength: 1, maxLength: 256
delegation: optional ClientDelegation or Responses { responses, type, acknowledgement_delay_ms } or Decisions { decisions, type, acknowledgement_delay_ms } or null
Live 模型委派任务的处理方。省略或设为 null 时,由你的应用处理;使用 responses 或 decisions,可委派给对应 API。
ClientDelegation object { type, acknowledgement_delay_ms }
将任务委派给你的应用。Live 会话发出委派事件,由你的后端处理。
type: "client" (default: "client")
委派任务的处理方。由你的应用处理时固定为 client。
"client"
acknowledgement_delay_ms: optional integer
从委派任务发出到请求自动语音确认的等待时长,单位为毫秒。模型仍可能在等待结束前发言。向会话追加任何说明(commentary)或思考(thinking)都会取消所有待处理的确认,包括其他委派任务的确认。Decisions 会话默认为 400,其他会话默认为 0,即立即请求。更新会话时省略此项会保留当前值;更新仅作用于后续委派。
minimum: 0, maximum: 800
Responses object { responses, type, acknowledgement_delay_ms }
将任务委派给由 Live 会话管理的 Responses 模型。
responses: ResponsesDelegationConfig
Live 会话将任务委派给 Responses 时所使用的后端模型、提示词和工具。
model: string
服务端管理的 Responses 委派使用的模型。
instructions: optional string or null
交给被委派的 Responses 模型的指令,与 Live 指令分开设置。参阅后端提示词。
max_output_tokens: optional integer or null
每次委派响应的最大输出词元数。
minimum: 16
parallel_tool_calls: optional boolean or null
被委派的 Responses 模型能否在单次响应中请求多个工具调用。
reasoning: optional object { effort, summary } or null
传给每次委派 Responses 请求的推理配置。
effort: optional "none" or "minimal" or "low" or 3 more or null
被委派的 Responses 模型使用的推理强度。支持的值取决于后端模型。
"none"
"minimal"
"low"
"medium"
"high"
"xhigh"
summary: optional "concise" or "detailed" or "auto" or null
向被委派的 Responses 模型请求的推理摘要类型,须模型支持。
"concise"
"detailed"
"auto"
service_tier: optional "auto" or "default" or "fast_tier_temp_pilot" or 3 more or null
委派 Responses 请求使用的服务层级。
"auto"
"default"
"fast_tier_temp_pilot"
"flex"
"priority"
"ultrafast"
text: optional object { verbosity } or null
传给每次委派 Responses 请求的文本生成配置。
verbosity: optional "low" or "medium" or "high" or null
Responses 后端生成文本的详细程度,此项不配置 Live 模型的口头表达方式。
"low"
"medium"
"high"
tool_choice: optional "auto" or "none" or "required" or Function { name, type } or Mcp { server_label, type, name } or 11 more
控制 Responses 后端在处理 Live 模型委派的任务时使用哪个工具。
LiveToolChoiceEnum = "auto" or "none" or "required"
"auto"
"none"
"required"
Function object { name, type }
name: string
要调用的函数工具名称。
type: "function" (default: "function")
要调用的工具,固定为 function。
"function"
Mcp object { server_label, type, name }
server_label: string
要调用的 MCP 服务器标签。
type: "mcp" (default: "mcp")
要调用的工具,固定为 mcp。
"mcp"
name: optional string or null
要调用的 MCP 工具名称。省略时,服务器可选择默认工具。
FileSearch object { type }
type: "file_search" (default: "file_search")
要调用的工具,固定为 file_search。
"file_search"
WebSearch object { type }
type: "web_search" (default: "web_search")
要调用的工具,固定为 web_search。
"web_search"
WebSearchPreview object { type }
type: "web_search_preview" (default: "web_search_preview")
要调用的工具,固定为 web_search_preview。
"web_search_preview"
ImageGeneration object { type }
type: "image_generation" (default: "image_generation")
要调用的工具,固定为 image_generation。
"image_generation"
Computer object { type }
type: "computer" (default: "computer")
要调用的工具,固定为 computer。
"computer"
CodeInterpreter object { type }
type: "code_interpreter" (default: "code_interpreter")
要调用的工具,固定为 code_interpreter。
"code_interpreter"
ProgrammaticToolCalling object { type }
type: "programmatic_tool_calling" (default: "programmatic_tool_calling")
要调用的工具,固定为 programmatic_tool_calling。
"programmatic_tool_calling"
Shell object { type }
需要调用工具时,强制模型调用 shell 工具。
type: "shell" (default: "shell")
要调用的工具,固定为 shell。
"shell"
Custom object { name, type }
name: string
要调用的自定义工具名称。
type: "custom" (default: "custom")
要调用的工具,固定为 custom。
"custom"
ApplyPatch object { type }
执行工具调用时,强制模型调用 apply_patch 工具。
type: "apply_patch" (default: "apply_patch")
要调用的工具,固定为 apply_patch。
"apply_patch"
LiveAllowedToolsChoiceParam object { tools, type, mode }
tools: array of Function { name, type } or Mcp { server_label, type, name } or FileSearch { type } or 9 more
被委派的 Responses 模型可以调用的工具。
minItems: 1, maxItems: 128
Function object { name, type }
name: string
要调用的函数工具名称。
type: "function" (default: "function")
要调用的工具,固定为 function。
"function"
Mcp object { server_label, type, name }
server_label: string
要调用的 MCP 服务器标签。
type: "mcp" (default: "mcp")
要调用的工具,固定为 mcp。
"mcp"
name: optional string or null
要调用的 MCP 工具名称。省略时,服务器可选择默认工具。
FileSearch object { type }
type: "file_search" (default: "file_search")
要调用的工具,固定为 file_search。
"file_search"
WebSearch object { type }
type: "web_search" (default: "web_search")
要调用的工具,固定为 web_search。
"web_search"
WebSearchPreview object { type }
type: "web_search_preview" (default: "web_search_preview")
要调用的工具,固定为 web_search_preview。
"web_search_preview"
ImageGeneration object { type }
type: "image_generation" (default: "image_generation")
要调用的工具,固定为 image_generation。
"image_generation"
Computer object { type }
type: "computer" (default: "computer")
要调用的工具,固定为 computer。
"computer"
CodeInterpreter object { type }
type: "code_interpreter" (default: "code_interpreter")
要调用的工具,固定为 code_interpreter。
"code_interpreter"
ProgrammaticToolCalling object { type }
type: "programmatic_tool_calling" (default: "programmatic_tool_calling")
要调用的工具,固定为 programmatic_tool_calling。
"programmatic_tool_calling"
Shell object { type }
需要调用工具时,强制模型调用 shell 工具。
type: "shell" (default: "shell")
要调用的工具,固定为 shell。
"shell"
Custom object { name, type }
name: string
要调用的自定义工具名称。
type: "custom" (default: "custom")
要调用的工具,固定为 custom。
"custom"
ApplyPatch object { type }
执行工具调用时,强制模型调用 apply_patch 工具。
type: "apply_patch" (default: "apply_patch")
要调用的工具,固定为 apply_patch。
"apply_patch"
type: "allowed_tools" (default: "allowed_tools")
工具选择类型,固定为 allowed_tools。
"allowed_tools"
mode: optional "none" or "auto" or "required" or null
从允许的工具集合中选择工具的方式。
"none"
"auto"
"required"
tools: optional array of FunctionTool or WebSearch { type } or FileSearch { type } or 10 more
Responses 后端处理 Live 模型委派的任务时可用的工具。
FunctionTool object { name, type, description, 2 more }
Live 模型委派任务时,Responses 后端可用的函数工具。
name: string
被委派的 Responses 模型调用此函数时使用的名称。
type: "function" (default: "function")
工具类型,固定为 function。
"function"
description: optional string or null
函数的用途,以及被委派的 Responses 模型应在何时调用它。
parameters: optional map[unknown] or null
描述函数可接受参数的 JSON Schema 对象。
strict: optional boolean or null
被委派的 Responses 模型是否必须严格遵循函数的参数模式。
WebSearch object { type }
Live 会话的 Responses 后端可用的网页搜索工具。
type: "web_search" (default: "web_search")
工具类型,固定为 web_search。
"web_search"
FileSearch object { type }
type: "file_search" (default: "file_search")
"file_search"
CodeInterpreter object { type }
type: "code_interpreter" (default: "code_interpreter")
"code_interpreter"
Shell object { type, environment }
Responses shell 工具。可使用托管容器,或通过 response.item.create 返回本地 shell 执行结果。不支持域名密钥(domain secrets)。
type: "shell" (default: "shell")
"shell"
environment: optional ContainerAuto { type, file_ids, memory_limit, 2 more } or ContainerReference { container_id, type } or Local { type, skills } or null
ContainerAuto object { type, file_ids, memory_limit, 2 more }
type: "container_auto" (default: "container_auto")
为此请求自动创建容器。
"container_auto"
file_ids: optional array of string or null
可选的已上传文件列表,这些文件将提供给代码使用。
maxItems: 50
memory_limit: optional "1g" or "4g" or "16g" or "64g" or null
容器的内存上限。
"1g"
"4g"
"16g"
"64g"
network_policy: optional Disabled { type } or Allowlist { allowed_domains, type } or null
容器的网络访问策略。
Disabled object { type }
type: "disabled" (default: "disabled")
禁用出站网络访问,固定为 disabled。
"disabled"
Allowlist object { allowed_domains, type }
allowed_domains: array of string
type 为 allowlist 时允许访问的域名列表。
minItems: 1
type: "allowlist" (default: "allowlist")
仅允许对指定域名发起出站网络访问,固定为 allowlist。
"allowlist"
skills: optional array of SkillReference { skill_id, type, version } or Inline { description, name, source, type } or null
可选的技能列表,通过 ID 或内联数据引用技能。
maxItems: 200
SkillReference object { skill_id, type, version }
skill_id: string
引用的技能 ID。
minLength: 1, maxLength: 64
type: "skill_reference" (default: "skill_reference")
引用通过 /v1/skills 接口创建的技能。
"skill_reference"
version: optional string or null
可选的技能版本。使用正整数或 'latest',省略时使用默认版本。
Inline object { description, name, source, type }
description: string
技能描述。
name: string
技能名称。
source: object { data, media_type, type }
内联技能载荷。
data: string
采用 Base64 编码的技能 ZIP 包。
minLength: 1, maxLength: 70254592
media_type: "application/zip" (default: "application/zip")
内联技能载荷的媒体类型,必须为 application/zip。
"application/zip"
type: "base64" (default: "base64")
内联技能来源的类型,必须为 base64。
"base64"
type: "inline" (default: "inline")
为此请求定义内联技能。
"inline"
ContainerReference object { container_id, type }
container_id: string
引用的容器 ID。
type: "container_reference" (default: "container_reference")
引用通过 /v1/containers 接口创建的容器。
"container_reference"
Local object { type, skills }
type: "local" (default: "local")
使用本地计算机环境。
"local"
skills: optional array of object { description, name, path } or null
可选的技能列表。
maxItems: 200
description: string
技能描述。
name: string
技能名称。
path: string
包含该技能的目录路径。
ImageGeneration object { type }
type: "image_generation" (default: "image_generation")
"image_generation"
Mcp object { type }
type: "mcp" (default: "mcp")
"mcp"
Custom object { type }
type: "custom" (default: "custom")
"custom"
Namespace object { type }
type: "namespace" (default: "namespace")
"namespace"
ToolSearch object { type }
type: "tool_search" (default: "tool_search")
"tool_search"
ProgrammaticToolCalling object { type }
type: "programmatic_tool_calling" (default: "programmatic_tool_calling")
"programmatic_tool_calling"
Computer object { type }
type: "computer" (default: "computer")
"computer"
ApplyPatch object { type }
type: "apply_patch" (default: "apply_patch")
"apply_patch"
type: "responses" (default: "responses")
委派任务的处理方。由 Responses API 处理任务时固定为 responses。
"responses"
acknowledgement_delay_ms: optional integer
从委派任务发出到请求自动语音确认的等待时长,单位为毫秒。模型仍可能在等待结束前发言。向会话追加任何说明(commentary)或思考(thinking)都会取消所有待处理的确认,包括其他委派任务的确认。Decisions 会话默认为 400,其他会话默认为 0,即立即请求。更新会话时省略此项会保留当前值;更新仅作用于后续委派。
minimum: 0, maximum: 800
Decisions object { decisions, type, acknowledgement_delay_ms }
decisions: DecisionsDelegationConfig
model: string
minLength: 1
questions: array of DecisionQuestion
按顺序一起求值的原生 Decision API 问题。
minItems: 1, maxItems: 64
Choice object { choices, instructions, type, name }
choices: array of DecisionChoiceOption
minItems: 2, maxItems: 255
value: string or boolean
string
boolean
description: optional string
instructions: string or array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
string
array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
minItems: 1
DecisionInputText object { text, type }
text: string
输入模型的文本。
maxLength: 10485760
type: "input_text" (default: "input_text")
"input_text"
InputImage object { image_url, type, detail }
image_url: string
采用 Base64 编码的图像 data URL,或可公开访问的 HTTP(S) 图像 URL。
pattern: ^(data:|https?://), maxLength: 20971520
type: "input_image" (default: "input_image")
"input_image"
detail: optional "low" or "high" or "auto" or "original" or null
发送给模型的图像细节级别,可选 high、low、auto 或 original,默认为 auto。
"low"
"high"
"auto"
"original"
InputJSON object { data, type }
data: map[unknown] or array of map[unknown]
LiveDecisionJSONObject = map[unknown]
array of map[unknown]
type: "input_json" (default: "input_json")
"input_json"
type: "choice" (default: "choice")
"choice"
name: optional string
Predicate object { instructions, type, name }
instructions: string or array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
string
array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
minItems: 1
DecisionInputText object { text, type }
InputImage object { image_url, type, detail }
image_url: string
采用 Base64 编码的图像 data URL,或可公开访问的 HTTP(S) 图像 URL。
pattern: ^(data:|https?://), maxLength: 20971520
type: "input_image" (default: "input_image")
"input_image"
detail: optional "low" or "high" or "auto" or "original" or null
发送给模型的图像细节级别,可选 high、low、auto 或 original,默认为 auto。
"low"
"high"
"auto"
"original"
InputJSON object { data, type }
data: map[unknown] or array of map[unknown]
LiveDecisionJSONObject = map[unknown]
array of map[unknown]
type: "input_json" (default: "input_json")
"input_json"
type: "predicate" (default: "predicate")
"predicate"
name: optional string
Score object { instructions, levels, type, name }
instructions: string or array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
string
array of DecisionInputText or InputImage { image_url, type, detail } or InputJSON { data, type }
minItems: 1
DecisionInputText object { text, type }
InputImage object { image_url, type, detail }
image_url: string
采用 Base64 编码的图像 data URL,或可公开访问的 HTTP(S) 图像 URL。
pattern: ^(data:|https?://), maxLength: 20971520
type: "input_image" (default: "input_image")
"input_image"
detail: optional "low" or "high" or "auto" or "original" or null
发送给模型的图像细节级别,可选 high、low、auto 或 original,默认为 auto。
"low"
"high"
"auto"
"original"
InputJSON object { data, type }
data: map[unknown] or array of map[unknown]
LiveDecisionJSONObject = map[unknown]
array of map[unknown]
type: "input_json" (default: "input_json")
"input_json"
levels: array of object { label, description }
minItems: 2, maxItems: 10
label: string
description: optional string
type: "score" (default: "score")
"score"
name: optional string
type: "decisions" (default: "decisions")
"decisions"
acknowledgement_delay_ms: optional integer
从委派任务发出到请求自动语音确认的等待时长,单位为毫秒。模型仍可能在等待结束前发言。向会话追加任何说明(commentary)或思考(thinking)都会取消所有待处理的确认,包括其他委派任务的确认。默认为 400;更新仅作用于后续委派。
minimum: 0, maximum: 800
input: optional array of InitialItem
启动前提供的有序纯文本历史记录。支持 developer、user 和 assistant 消息,每条消息包含一个文本部分;最多 128 条消息,并受配置的渲染后词元数量上限约束,默认上限为 8,192。
maxItems: 128
Developer object { content, role, id, 2 more }
包含在 Live 会话初始文本历史记录中的开发者消息。
content: array of object { text, type }
消息内容。Live 初始对话历史记录中的每条消息须恰好提供一个文本部分。
minItems: 1, maxItems: 1
text: string
要包含在 Live 会话初始对话历史记录中的消息文本。
type: optional "input_text" (default: "input_text")
文本内容类型,固定为 input_text。
"input_text"
role: "developer" (default: "developer")
此历史消息的作者,固定为 developer。
"developer"
id: optional string or null
所提供历史消息的可选标识。Live 使用消息的角色和文本初始化对话。
status: optional "incomplete" or "completed" or null
所提供消息的状态。Live 将其文本作为历史记录,不会恢复未完成的消息。
"incomplete"
"completed"
type: optional "message" (default: "message")
历史记录条目的类型,固定为 message。
"message"
User object { content, role, id, 2 more }
包含在 Live 会话初始文本历史记录中的用户消息。
content: array of object { text, type }
消息内容。Live 初始对话历史记录中的每条消息须恰好提供一个文本部分。
minItems: 1, maxItems: 1
text: string
要包含在 Live 会话初始对话历史记录中的消息文本。
type: optional "input_text" (default: "input_text")
文本内容类型,固定为 input_text。
"input_text"
role: "user" (default: "user")
此历史消息的作者,固定为 user。
"user"
id: optional string or null
所提供历史消息的可选标识。Live 使用消息的角色和文本初始化对话。
status: optional "incomplete" or "completed" or null
所提供消息的状态。Live 将其文本作为历史记录,不会恢复未完成的消息。
"incomplete"
"completed"
type: optional "message" (default: "message")
历史记录条目的类型,固定为 message。
"message"
Assistant object { content, role, id, 2 more }
包含在 Live 会话初始文本历史记录中的助手消息。
content: array of Text { text, type } or OutputText { text, type }
消息内容。Live 初始对话历史记录中的每条消息须恰好提供一个文本部分。
minItems: 1, maxItems: 1
Text object { text, type }
启动 Live 会话时作为对话历史记录提供的助手文本。
text: string
要包含在 Live 会话初始对话历史记录中的消息文本。
type: optional "text" (default: "text")
文本内容类型,固定为 text。
"text"
OutputText object { text, type }
启动 Live 会话时作为对话历史记录提供的助手输出文本。
text: string
要包含在 Live 会话初始对话历史记录中的消息文本。
type: "output_text" (default: "output_text")
文本内容类型,固定为 output_text。
"output_text"
role: "assistant" (default: "assistant")
此历史消息的作者,固定为 assistant。
"assistant"
id: optional string or null
所提供历史消息的可选标识。Live 使用消息的角色和文本初始化对话。
status: optional "incomplete" or "completed" or null
所提供消息的状态。Live 将其文本作为历史记录,不会恢复未完成的消息。
"incomplete"
"completed"
type: optional "message" (default: "message")
历史记录条目的类型,固定为 message。
"message"
instructions: optional string or null
关于音色、对话、打断及何时委派任务的前端指令。先阅读 Live 提示词指南;将业务规则和工具工作流程放在单独的后端提示词中。客户端提供的指令最多 16,384 个词元。省略或提供空白指令时使用服务端默认值。启动后不能更改。
safety_identifier: optional string or null
最终用户的稳定标识,用于安全监控和滥用检测。
maxLength: 128
store: optional boolean
是否保存会话,以便之后分叉和下载录音。新会话默认为 false。
triggers: optional array of DecisionTrigger
每种转录事件类型最多配置一个 Decisions 触发器。触发器独立于任务委派运行。更新时省略 triggers 会保留当前配置,发送列表会替换配置,发送空列表会禁用触发器。
maxItems: 2
decisions: object { questions }
使用当前转录文本与会话共享的 Decision 条目进行求值的问题。
questions: array of DecisionQuestion
按顺序一起求值的原生 Decision API 问题。
minItems: 1, maxItems: 64
Choice object { choices, instructions, type, name }
Predicate object { instructions, type, name }
Score object { instructions, levels, type, name }
event_type: "session.input_transcript.delta" or "session.output_transcript.delta"
"session.input_transcript.delta"
"session.output_transcript.delta"
type: "decisions" (default: "decisions")
"decisions"
transport: Webrtc { sdp, type } or Sip { destination, trunk, type }
WebRTC 传输包含 SDP 提议;SIP 传输包含被叫号码与逐次呼叫提供的中继凭据。
Webrtc object { sdp, type }
WebRTC 传输对象,在创建请求中携带 SDP 提议,在响应中携带 SDP 应答。
sdp: string
WebRTC 连接的会话描述协议(SDP)消息。
minLength: 1
type: "webrtc"
Live 会话使用的传输方式,固定为 webrtc。
"webrtc"
Sip object { destination, trunk, type }
通过服务提供商的中继发起 SIP 外呼。中继必须支持 TLS 信令、Opus 音频和 SDES-SRTP 媒体。参阅电话与 SIP。
destination: string
要呼叫的电话号码,须采用 E.164 格式。不支持以 SIP URI 作为被叫地址。
pattern: ^\+[1-9][0-9]{1,14}$
trunk: object { auth, caller_number, provider_url }
为此次呼叫提供的 SIP 中继配置。中继凭据须保存在你的服务器上;创建响应不会返回此配置。
auth: object { password, type, username }
用于向中继服务提供商进行 SIP Digest 认证的凭据。
password: string
服务提供商的密码,最多 4096 字节,不能包含 CR、LF 或 NUL。
minLength: 1
type: "digest"
SIP Digest 认证使用 digest,可处理 401 和 407 认证质询。
"digest"
username: string
服务提供商的用户名,须包含非空白字符,最多 256 字节,不能包含 CR、LF 或 NUL。
minLength: 1
caller_number: string
SIP From 头中使用的主叫电话号码,须采用 E.164 格式。
pattern: ^\+[1-9][0-9]{1,14}$
provider_url: string
服务提供商的端点,格式为 sips:host[:port][;transport=tcp],默认端口为 5061。IPv6 地址须用方括号括起。要求使用 TLS 信令,不支持明文 SIP。不能包含用户信息、路径、URI 头或其他 URI 参数。本地主机名,以及直接写出的私有、环回、链路本地、未指定、多播和广播 IP 地址均会被拒绝。
type: "sip"
Live 会话使用的传输方式,固定为 sip。
"sip"
返回值
session: object { id }
新创建的 Live 会话。使用其 ID 控制会话或建立旁路连接。
id: string
不透明的会话标识。须原样保留返回值,包括其前缀。
transport: Webrtc { sdp, type } or Sip { type }
WebRTC 传输包含 SDP 应答;SIP 传输不包含 SDP 或中继凭据。使用 SIP 时,通过 session.id 建立旁路连接,以接收 transport.ringing、transport.answered 和 transport.failed 通知。
Webrtc object { sdp, type }
WebRTC 传输对象,在创建请求中携带 SDP 提议,在响应中携带 SDP 应答。
sdp: string
WebRTC 连接的会话描述协议(SDP)消息。
minLength: 1
type: "webrtc"
Live 会话使用的传输方式,固定为 webrtc。
"webrtc"
Sip object { type }
SIP 传输对象,不返回中继凭据和 SDP。
type: "sip"
Live 会话使用的传输方式,固定为 sip。
"sip"
示例
## 设置 OPENAI_API_KEY,并替换会话 ID、SDP 与中继凭据;SDP 须使用实际协商内容。
curl https://api.openai.com/v1/live/sessions \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"session": {
"model": "gpt-live-1"
},
"transport": {
"sdp": "x",
"type": "webrtc"
}
}'
201:WebRTC 会话已创建(201 Created)
{
"session": {
"id": "live_123"
},
"transport": {
"type": "webrtc",
"sdp": "<SDP 应答>"
}
}
201:SIP 外呼会话已初始化(201 Created)
{
"session": {
"id": "live_123"
},
"transport": {
"type": "sip"
}
}
创建 WebRTC 会话
## 设置 OPENAI_API_KEY,并替换会话 ID、SDP 与中继凭据;SDP 须使用实际协商内容。
curl https://api.openai.com/v1/live/sessions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"session":{"model":"gpt-live-1","instructions":"表达简洁,必要时请求澄清。"},"transport":{"type":"webrtc","sdp":"<SDP 提议>"}}'
响应示例
{"session":{"id":"live_123"},"transport":{"type":"webrtc","sdp":"<SDP 应答>"}}
发起 SIP 外呼
## 设置 OPENAI_API_KEY,并替换会话 ID、SDP 与中继凭据;SDP 须使用实际协商内容。
## 请先在环境变量中设置 SIP_USERNAME 和 SIP_PASSWORD。
jq -n '{
"session": {
"model": "gpt-live-1",
"instructions": "帮助用户安排预约。",
"audio": { "output": { "voice": "marin" } },
"delegation": { "type": "client" }
},
"transport": {
"type": "sip",
"destination": "+14155550123",
"trunk": {
"provider_url": "sips:sip.example.com:5061",
"auth": {
"type": "digest",
"username": env.SIP_USERNAME,
"password": env.SIP_PASSWORD
},
"caller_number": "+14155550100"
}
}
}' | curl https://api.openai.com/v1/live/sessions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
--data-binary @-
响应示例
{"session":{"id":"live_123"},"transport":{"type":"sip"}}
TRAE-AI编程


更多建议: