Create a model response
使用 OpenAI Responses API 格式创建模型响应,支持流式和非流式两种模式。该端点仅支持 OpenAI 兼容渠道(gpt-5.x 等),不支持 Claude / Gemini 原生渠道。
Authentication
AuthorizationstringRequired格式为 Bearer $HY_API_KEY。
Headers
Content-TypestringOptional通常为 application/json。
Request
modelstringRequired模型 ID,仅支持 OpenAI 兼容渠道。例如 gpt-5.4、gpt-5.4-mini、gpt-5.3-chat。具体可用模型以你的 API Key 权限为准。
inputstring | array of objectsRequired模型的输入内容,等价于 Chat Completions 中的 messages。传字符串时视为单条用户消息;传数组时格式与 Chat Completions messages 兼容(支持 role: system / user / assistant / tool)。
instructionsstringOptional系统提示词,等价于 Chat Completions 中 messages 数组里 role: "system" 的消息。用于设定模型的角色、行为或任务背景。
streambooleanOptional是否使用 SSE 流式返回。默认 false;为 true 时返回 text/event-stream,逐步推送 response.output_text.delta 等事件,直至最终的 response.completed 事件(含 usage)。
max_output_tokensintegerOptional最大输出 token 数量(仅限可见输出,不含推理 token)。Responses API 专用字段,对应 Chat Completions 中的 max_completion_tokens。
reasoning_effortstringOptional推理强度。仅部分 OpenAI 模型支持,常见取值为 low、medium、high;影响模型的思考深度与延迟。
temperaturenumberOptional采样温度,取值 0–2。推理模型通常仅支持默认值 1;启用推理时建议省略此参数。
toolsarray of objectsOptional函数调用工具定义,格式兼容 OpenAI tools 结构。
textobjectOptional指定响应文本的输出格式。
previous_response_idstringOptional上一次 response 的 ID,用于多轮对话时衔接上文。等价于在 input 中手动传入历史消息。
Errors
| 1 | import OpenAI from 'openai' |
| 2 | |
| 3 | const client = new OpenAI({ |
| 4 | apiKey: process.env.HY_API_KEY, |
| 5 | baseURL: 'https://apiclaw.cc/v1', |
| 6 | }) |
| 7 | |
| 8 | const response = await client.responses.create({ |
| 9 | model: 'gpt-5.4', |
| 10 | instructions: 'You are a helpful assistant.', |
| 11 | input: 'Write a one-sentence product description.', |
| 12 | max_output_tokens: 256, |
| 13 | }) |
| 14 | |
| 15 | // 输出第一条文本内容 |
| 16 | for (const item of response.output) { |
| 17 | for (const part of item.content ?? []) { |
| 18 | if (part.type === 'output_text') { |
| 19 | console.log(part.text) |
| 20 | } |
| 21 | } |
| 22 | } |
Authorization
获取 API Key →Body Parameters
modelstring必填模型 ID,仅支持 OpenAI 兼容渠道。例如 gpt-5.4、gpt-5.4-mini、gpt-5.3-chat。具体可用模型以你的 API Key 权限为准。
inputstring | array of objects必填模型的输入内容,等价于 Chat Completions 中的 messages。传字符串时视为单条用户消息;传数组时格式与 Chat Completions messages 兼容(支持 role: system / user / assistant / tool)。
instructionsstring可选系统提示词,等价于 Chat Completions 中 messages 数组里 role: "system" 的消息。用于设定模型的角色、行为或任务背景。
streamboolean可选是否使用 SSE 流式返回。默认 false;为 true 时返回 text/event-stream,逐步推送 response.output_text.delta 等事件,直至最终的 response.completed 事件(含 usage)。
max_output_tokensinteger可选最大输出 token 数量(仅限可见输出,不含推理 token)。Responses API 专用字段,对应 Chat Completions 中的 max_completion_tokens。
reasoning_effortstring可选推理强度。仅部分 OpenAI 模型支持,常见取值为 low、medium、high;影响模型的思考深度与延迟。
temperaturenumber可选采样温度,取值 0–2。推理模型通常仅支持默认值 1;启用推理时建议省略此参数。
toolsarray of objects可选函数调用工具定义,格式兼容 OpenAI tools 结构。
textobject可选指定响应文本的输出格式。
previous_response_idstring可选上一次 response 的 ID,用于多轮对话时衔接上文。等价于在 input 中手动传入历史消息。
| 1 | const response = await fetch("https://apiclaw.cc/v1/responses", { |
| 2 | method: "POST", |
| 3 | headers: { |
| 4 | "Authorization": "Bearer YOUR_API_KEY", |
| 5 | "Content-Type": "application/json", |
| 6 | }, |
| 7 | body: JSON.stringify({ |
| 8 | "model": "gpt-5.4", |
| 9 | "input": "Say hello in one sentence.", |
| 10 | "stream": false, |
| 11 | "max_output_tokens": 512, |
| 12 | "reasoning_effort": "medium", |
| 13 | "temperature": 1 |
| 14 | }), |
| 15 | }); |
| 16 | const data = await response.json(); |
| 17 | console.log(data); |
点击 Send request 查看响应
| 1 | { |
| 2 | "id": "resp_abc123", |
| 3 | "object": "response", |
| 4 | "created_at": 1747756800, |
| 5 | "status": "completed", |
| 6 | "model": "gpt-5.4", |
| 7 | "output": [ |
| 8 | { |
| 9 | "id": "msg_xyz456", |
| 10 | "type": "message", |
| 11 | "role": "assistant", |
| 12 | "status": "completed", |
| 13 | "content": [ |
| 14 | { |
| 15 | "type": "output_text", |
| 16 | "text": "Here is a concise product description.", |
| 17 | "annotations": [] |
| 18 | } |
| 19 | ] |
| 20 | } |
| 21 | ], |
| 22 | "usage": { |
| 23 | "input_tokens": 22, |
| 24 | "output_tokens": 9, |
| 25 | "total_tokens": 31 |
| 26 | } |
| 27 | } |

