Skip to main content

OpenAI 接口规范

项目
Base URLhttps://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

图像尺寸,支持 2048x20482K 两种格式。

基础对话

POST /v1/chat/completions

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"
}]
}'

多模态请求(Responses API)

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": [{
"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"
}
]
}]
}'

常用参数

参数类型说明
modelstring必填。Model ID
messagesarray必填。对话历史,见下方格式说明
streamboolean流式输出(SSE),默认 false
max_tokensinteger最大输出长度,默认 4096
temperaturenumber随机性 [0, 2],越大越发散,默认 1
top_pnumber核采样 [0, 1],与 temperature 二选一调即可
toolsarray工具列表(函数调用)
response_formatobject指定输出格式,如 {"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

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": "今天北京天气怎么样?"
}'