快速开始
5 分钟快速接入 HuanCode API
1. 注册并获取 API Key
前往 HuanCode 注册账号,注册后在 控制台 创建 API Key。
2. 发送第一个请求
cURL
curl https://api.huancode.com/v1/responses \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"input": "Write a short bedtime story about a unicorn."
}'3. 使用 SDK
HuanCode API 兼容 OpenAI 格式,直接使用 OpenAI 官方 SDK 即可。
pip install openainpm install openaiPython
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.huancode.com/v1"
)
response = client.responses.create(
model="gpt-5.4",
input="Write a short bedtime story about a unicorn."
)
print(response.output_text)Node.js
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.huancode.com/v1',
});
const response = await client.responses.create({
model: 'gpt-5.4',
input: 'Write a short bedtime story about a unicorn.',
});
console.log(response.output_text);4. 流式输出
支持 Server-Sent Events (SSE) 流式返回,适合实时对话场景:
Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.huancode.com/v1"
)
stream = client.responses.create(
model="gpt-5.4",
input="Write a short bedtime story about a unicorn.",
stream=True
)
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="")Node.js
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'YOUR_API_KEY',
baseURL: 'https://api.huancode.com/v1',
});
const stream = await client.responses.create({
model: 'gpt-5.4',
input: 'Write a short bedtime story about a unicorn.',
stream: true,
});
for await (const event of stream) {
if (event.type === 'response.output_text.delta') {
process.stdout.write(event.delta);
}
}