创建模型响应
POST/v1/responses 创建模型响应
POST /responses
完整请求地址:
https://www.vortapapi.com/v1/responses
用于通过 Vortap 创建一次模型响应。部分模型仅支持 Responses API 格式,例如 o3-pro、codex-mini-latest 等。
请求头
| 名称 | 必填 | 说明 |
|---|---|---|
Content-Type | 是 | 固定为 application/json |
Accept | 是 | 建议设置为 application/json |
Authorization | 是 | 使用 Bearer Token,例如 Bearer sk-*** |
请求体
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 要调用的模型名称 |
input | string 或 array | 是 | 输入内容。可以是纯文本,也可以是消息数组 |
instructions | string | 否 | 提供给模型的系统级指令 |
temperature | number | 否 | 控制输出随机性,值越高结果越发散 |
max_output_tokens | integer | 否 | 限制模型最多生成的 token 数 |
stream | boolean | 否 | 是否启用流式响应 |
请求示例
curl https://www.vortapapi.com/v1/responses \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "o3-pro",
"input": "你好,请用一句话介绍你自己。"
}'
使用消息数组作为输入
{
"model": "o3-pro",
"input": [
{
"role": "user",
"content": "请解释什么是 API 网关。"
}
]
}
响应示例
{
"id": "resp_123",
"object": "response",
"created_at": 1677652288,
"status": "completed",
"model": "o3-pro",
"output": [
{
"id": "msg_123",
"type": "message",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "API 网关是客户端与后端服务之间的统一入口,用于处理请求转发、鉴权、限流和监控等能力。"
}
]
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 31,
"total_tokens": 43
}
}
提取文本输出
Responses API 的返回内容通常位于:
output[0].content[0].text
示例:
const text = response.output[0].content[0].text;
console.log(text);
流式响应
将 stream 设置为 true 可启用流式输出。
curl https://www.vortapapi.com/v1/responses \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-H "Authorization: Bearer sk-***" \
-d '{
"model": "o3-pro",
"input": "写一首关于夏天的短诗。",
"stream": true
}'