OpenAI 接口规范
| 项目 | 值 |
|---|---|
| Base URL | https://api.taiha.cn/v1 |
| API Key | 在控制台创建 |
| Model ID | 在模型广场查看 |
鉴权方式:所有协议统一使用
Authorization: Bearer <API Key>请求头。设置"stream": true可启用 SSE 流式输出。
model string 必选
模型 ID,用于指定使用的 AI 模型。
prompt string 必选
用户输入的提示词,用于引导模型生成内容。
image string / string[]
参考图片,支持传入 URL 或 Base64 编码格式。
size string
图像尺寸,支持 2048x2048 或 2K 两种格式。
基础对话
POST /v1/chat/completions
- cURL
- Python
cURL
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": "user",
"content": "hello"
}]
}'
Python
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"])
多模态请求(Responses API)
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": [{
"role": "user",
"content": [
{ "type": "input_text", "text": "描述这张图,并生成一张类似的" },
{
"type": "input_image",
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-managefiles/zh-CN/20250925/thtclx/input1.png"
}
]
}]
}'
Python
import requests
url = "https://api.taiha.cn/v1/responses"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <API Key>",
}
payload = {
"model": "<Model ID>",
"input": [{
"role": "user",
"content": [
{ "type": "input_text", "text": "描述这张图,并生成一张类似的" },
{
"type": "input_image",
"image_url": "https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20250925/thtclx/input1.png"
}
]
}]
}
response = requests.post(url, headers=headers, json=payload, timeout=30)
response.raise_for_status()
result = response.json()
print(result)
常用参数
| 参数 | 类型 | 说明 |
|---|---|---|
model | string | 必填。Model ID |
messages | array | 必填。对话历史,见下方格式说明 |
stream | boolean | 流式输出(SSE),默认 false |
max_tokens | integer | 最大输出长度,默认 4096 |
temperature | number | 随机性 [0, 2],越大越发散,默认 1 |
top_p | number | 核采样 [0, 1],与 temperature 二选一调即可 |
tools | array | 工具列表(函数调用) |
response_format | object | 指定输出格式,如 {"type":"json_object"} |
messages 格式
| role | 说明 |
|---|---|
system | 系统指令(人设、背景) |
user | 用户输入 |
assistant | 模型回复 |
tool | 工具调用结果,需带 tool_call_id |
多模态 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)