Responses
http
POST https://gateway.hihapi.com/v1/responsesOpenAI Responses 协议。用 input 传入内容,用 instructions 传入系统指令。Codex CLI 等较新的 OpenAI 生态工具使用这个协议。
请求示例
bash
curl https://gateway.hihapi.com/v1/responses \
-H "Authorization: Bearer $HIHAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-flash",
"instructions": "你是一个乐于助人的助手。",
"input": "用一句话介绍你自己"
}'python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["HIHAI_API_KEY"],
base_url="https://gateway.hihapi.com/v1",
)
response = client.responses.create(
model="deepseek-flash",
instructions="你是一个乐于助人的助手。",
input="用一句话介绍你自己",
)
print(response.output_text)js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.HIHAI_API_KEY,
baseURL: "https://gateway.hihapi.com/v1",
});
const response = await client.responses.create({
model: "deepseek-flash",
instructions: "你是一个乐于助人的助手。",
input: "用一句话介绍你自己",
});
console.log(response.output_text);请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,见模型列表 |
input | string / array | 是 | 输入内容。可以是一段文本,也可以是消息数组 |
instructions | string | 否 | 系统指令 |
stream | boolean | 否 | 是否流式返回,默认 false |
max_output_tokens | integer | 否 | 本次回复最多生成的 tokens 数 |
temperature | number | 否 | 采样温度 |
tools | array | 否 | 可供模型调用的工具 |
多轮对话时,把历史消息以数组形式放进 input:
json
{
"model": "deepseek-flash",
"input": [
{"role": "user", "content": "我叫小林"},
{"role": "assistant", "content": "你好,小林!"},
{"role": "user", "content": "我叫什么名字?"}
]
}响应
回复内容在 output 数组里,类型为 message 的项包含文本;用量在 usage 里。使用 OpenAI SDK 时可以直接读取 response.output_text。
json
{
"id": "resp_...",
"object": "response",
"model": "deepseek-flash",
"output": [
{
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": "我是一个 AI 助手……"}]
}
],
"usage": {
"input_tokens": 24,
"output_tokens": 18,
"total_tokens": 42
}
}和 Chat Completions 怎么选
两个协议调用的是同一批模型,价格相同。已有代码用的是哪个就继续用哪个;新项目没有特别要求时,用 Chat Completions 的兼容面更广。