APP_SECRET 全部从服务端环境变量读取。先调用模型目录确认 model_code、价格和输出限制,再选择对话入口。
Chat Completions 非流式
cURL
curl 'https://api.aichs365.com/v1/chat/completions' \
-H "Authorization: Bearer $QINGZHOUSHAN_APP_SECRET" \
-H 'Content-Type: application/json' \
--data '{
"model": "gpt-4.1-mini",
"messages": [
{"role": "system", "content": "你是一个简洁的中文助手。"},
{"role": "user", "content": "用三句话介绍杭州。"}
],
"stream": false,
"max_completion_tokens": 500
}'
Node.js
const response = await fetch(`${process.env.QINGZHOUSHAN_API_BASE_URL}/v1/chat/completions`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.QINGZHOUSHAN_APP_SECRET}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4.1-mini',
messages: [
{ role: 'system', content: '你是一个简洁的中文助手。' },
{ role: 'user', content: '用三句话介绍杭州。' }
],
stream: false,
max_completion_tokens: 500
})
})
const body = await response.json()
if (!response.ok) throw new Error(body.error?.message ?? `HTTP ${response.status}`)
console.log(body.choices?.[0]?.message?.content)
console.log('log id:', response.headers.get('x-log-id'))
Python
import os
import requests
response = requests.post(
f"{os.environ['QINGZHOUSHAN_API_BASE_URL']}/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['QINGZHOUSHAN_APP_SECRET']}"},
json={
"model": "gpt-4.1-mini",
"messages": [
{"role": "system", "content": "你是一个简洁的中文助手。"},
{"role": "user", "content": "用三句话介绍杭州。"},
],
"stream": False,
"max_completion_tokens": 500,
},
timeout=60,
)
response.raise_for_status()
print(response.json()["choices"][0]["message"]["content"])
print("log id:", response.headers.get("X-Log-Id"))
Chat Completions 流式
cURL
curl -N 'https://api.aichs365.com/v1/chat/completions' \
-H "Authorization: Bearer $QINGZHOUSHAN_APP_SECRET" \
-H 'Content-Type: application/json' \
--data '{"model":"gpt-4.1-mini","messages":[{"role":"user","content":"写一句产品标语"}],"stream":true}'
Node.js
const response = await fetch(`${process.env.QINGZHOUSHAN_API_BASE_URL}/v1/chat/completions`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.QINGZHOUSHAN_APP_SECRET}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: 'gpt-4.1-mini',
messages: [{ role: 'user', content: '写一句产品标语' }],
stream: true
})
})
if (!response.ok) throw new Error(await response.text())
const decoder = new TextDecoder()
for await (const chunk of response.body) {
process.stdout.write(decoder.decode(chunk, { stream: true }))
}
Python
import os
import requests
with requests.post(
f"{os.environ['QINGZHOUSHAN_API_BASE_URL']}/v1/chat/completions",
headers={"Authorization": f"Bearer {os.environ['QINGZHOUSHAN_APP_SECRET']}"},
json={
"model": "gpt-4.1-mini",
"messages": [{"role": "user", "content": "写一句产品标语"}],
"stream": True,
},
stream=True,
timeout=60,
) as response:
response.raise_for_status()
for line in response.iter_lines(decode_unicode=True):
if line:
print(line)
Responses 非流式
cURL
curl 'https://api.aichs365.com/v1/responses' \
-H "Authorization: Bearer $QINGZHOUSHAN_APP_SECRET" \
-H 'Content-Type: application/json' \
--data '{
"model": "gpt-4.1-mini",
"instructions": "回答要简洁,并使用中文。",
"input": "给我三个短视频选题。",
"stream": false,
"max_output_tokens": 500
}'
提示 Responses 的output可能包含消息、工具调用或推理项,不能只假设固定的output[0].content[0].text。请按每个输出项的type分支处理,并允许出现上游扩展字段。