Skip to main content

OpenAI 接口规范

支持两种 OpenAI 协议:经典的 Chat Completions(/v1/chat/completions)和新版 Responses(/v1/responses)。可直接使用 openai 官方 SDK,只需替换 Base URL 和 API Key。

项目
Base URLhttps://api.taiha.cn/v1
API Key控制台创建
Model ID模型广场查看

鉴权方式:所有协议统一使用 Authorization: Bearer <API Key> 请求头。设置 "stream": true 可启用 SSE 流式输出。

基础对话

POST /v1/chat/completions
curl -X POST 'https://api.taiha.cn/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API Key>' \
-d '{
"model": "<Model ID>",
"messages": [{
"role": "user",
"content": "hello"
}]
}'

多模态对话

curl -X POST 'https://api.taiha.cn/v1/chat/completions' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer <API Key>' \
-d '{
"model": "<Model ID>",
"messages": [{
"role": "user",
"content": [{
"type":"image_url",
"image_url": {
"url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"
}
}, {
"type": "video",
"video": {[
"https://img.alicdn.com/imgextra/i3/O1CN01K3SgGo1eqmlUgeE9b_!!6000000003923-0-tps-3840-2160.jpg",
"https://img.alicdn.com/imgextra/i4/O1CN01BjZvwg1Y23CF5qIRB_!!6000000003000-0-tps-3840-2160.jpg",
]}
}, {
"type": "text",
"text": "这是什么"
}]
}]
}'

新版基础请求(Responses API)

POST /v1/responses
curl -X POST 'https://api.taiha.cn/v1/responses' \
-H 'Authorization: Bearer <API Key>' \
-H 'Content-Type: application/json' \
-d '{
"model": "<Model ID>",
"input": [{
"role": "user",
"input": “hello”
}]
}'

常用参数

model string 必填 | 模型ID

  • 模型ID,请按照模型广场中模型所示名称填写,区分大小写。
  • 您也可以通过请求端点models来获得所有可请求的模型列表。

messages array 必填 | 对话历史

对话历史,见下方格式说明

role string 选填 | 角色

  • 可选:system 系统指令(人设、背景)
  • 必填:user 用户指令

assistant string 可选 | 对话历史

与模型的对话历史记录上下文,作用于模型短期记忆,便于模型分析推理

tool string 可选 | 工具调用结果

工具调用结果,需带 tool_call_id

stream boolean 可选 | 流式输出开关

流式输出(SSE),默认 false

max_tokens integer 可选 | 最大输出长度

最大输出长度,默认 4096,最大可输出长度请参考模型上下文长度

temperature number 可选 | 模型温度

随机性 [0, 1],越大越发散,当数值越小时,相同问题模型回复越趋于一致,默认 1
部分模型支持[0, 2]范围,具体可查看模型官方文档

top_p number 可选 | 核采样

与 temperature 二选一调即可

tools array 可选 | 工具列表

可提供模型调用的工具方法名称,具体使用方式请查看对应文档

response_format object 可选 | 输出格式

可指定模型按照要求输出格式,如 {"type":"json_object"}

多模态 content(传数组时每块需指定 type):

type说明
text文本,带 text 字段
image_url图片,带 image_url.url(支持 URL 或 base64)
video_url视频帧,带 video_url.url(仅画面)

流式输出

stream: true,响应为 SSE,每行 data: {...},结束收到 data: [DONE]

curl https://api.taiha.cn/v1/chat/completions \
-H "Authorization: Bearer <API Key>" \
-H "Content-Type: application/json" \
-d '{
"model": "<Model ID>",
"stream": true,
"messages": [{ "role": "user", "content": "hello" }]
}'

携带系统指令

input 传数组时可加入 system 角色:

curl --location --request POST 'https://api.taiha.cn/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <API Key>' \
--data-raw '{
"model": "<Model ID>",
"messages": [{
"role": "system",
"content": "你是一个全能的AI助手,必须严格按照用户需求处理问题"
}, {
"role": "user",
"content": "帮我写一篇200字的文章"
}]
}'

搜索请求

原生模型搜索请求

POST /v1/responses

cURL

curl --location --request POST 'https://api.taiha.cn/v1/responses' \
--header 'Authorization: Bearer <API Key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "<Model ID>",
"reasoning": {
"effort": "low"
},
"tools": [{
"type": "web_search"
}],
"tool_choice": "auto",
"input": "今天北京天气怎么样?"
}'

默认搜索请求

POST /v1/responses

cURL

curl --location --request POST 'https://api.taiha.cn/v1/responses' \
--header 'Authorization: Bearer <API Key>' \
--header 'Content-Type: application/json' \
--data-raw '{
"model": "<Model ID>",
"input": "今天北京天气怎么样?"
}'