OpenAI 接口规范
支持两种 OpenAI 协议:经典的 Chat Completions(/v1/chat/completions)和新版 Responses(/v1/responses)。可直接使用 openai 官方 SDK,只需替换 Base URL 和 API Key。
| 项目 | 值 |
|---|---|
| Base URL | https://api.taiha.cn/v1 |
| API Key | 在控制台创建 |
| Model ID | 在模型广场查看 |
鉴权方式:所有协议统一使用
Authorization: Bearer <API Key>请求头。设置"stream": true可启用 SSE 流式输出。
基础对话
POST /v1/chat/completions
- cURL
- Python
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"
}]
}'
import requests
url = "https://api.taiha.cn/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"messages": [{
"role": "user",
"content": "hello"
}]
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
if "choices" in result:
print("Assistant:", result["choices"][0]["message"]["content"])
多模态对话
- cURL
- Python
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": "这是什么"
}]
}]
}'
import requests
url = "https://api.taiha.cn/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"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": "这是什么"
}]
}]
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
if "choices" in result:
print("Assistant:", result["choices"][0]["message"]["content"])
新版基础请求(Responses API)
POST /v1/responses
- cURL
- Python
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”
}]
}'
import requests
url = "https://api.taiha.cn/v1/responses"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"input": "hello"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
常用参数
model string 必填 | 模型ID
string 必填 | 模型ID- 模型ID,请按照模型广场中模型所示名称填写,区分大小写。
- 您也可以通过请求端点models来获得所有可请求的模型列表。
messages array 必填 | 对话历史
array 必填 | 对话历史对话历史,见下方格式说明 role assistant tool string 选填 | 角色system 系统指令(人设、背景)user 用户指令string 可选 | 对话历史与模型的对话历史记录上下文,作用于模型短期记忆,便于模型分析推理string 可选 | 工具调用结果工具调用结果,需带 tool_call_id
stream boolean 可选 | 流式输出开关
boolean 可选 | 流式输出开关流式输出(SSE),默认
falsemax_tokens integer 可选 | 最大输出长度
integer 可选 | 最大输出长度最大输出长度,默认 4096,最大可输出长度请参考模型上下文长度
temperature number 可选 | 模型温度
number 可选 | 模型温度随机性 [0, 1],越大越发散,当数值越小时,相同问题模型回复越趋于一致,默认 1
部分模型支持[0, 2]范围,具体可查看模型官方文档
top_p number 可选 | 核采样
number 可选 | 核采样与 temperature 二选一调即可
tools array 可选 | 工具列表
array 可选 | 工具列表可提供模型调用的工具方法名称,具体使用方式请查看对应文档
response_format object 可选 | 输出格式
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
- Python
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": "今天北京天气怎么样?"
}'
Python
import requests
url = "https://api.taiha.cn/v1/responses"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"reasoning": {
"effort": "low"
},
"tools": [{
"type": "web_search"
}],
"tool_choice": "auto",
"input": "今天北京天气怎么样?"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
默认搜索请求
POST /v1/responses
- cURL
- Python
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": "今天北京天气怎么样?"
}'
Python
import requests
url = "https://api.taiha.cn/v1/responses"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"input": "今天北京天气怎么样?"
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)