import requests
url = 'https://aihubmix.com/v1/chat/completions'
headers = {
'Authorization': 'Bearer AIHUBMIX_API_KEY',
'Content-Type': 'application/json'
}
data = {
'model': 'gpt-3.5-turbo',
'messages': [
{'role': 'user', 'content': '你好'}
]
}
response = requests.post(url, headers=headers, json=data)
print(response.json())
{
"choices": [
{
"message": {
"role": "<string>",
"content": "<string>"
},
"finish_reason": "<string>"
}
],
"usage": {
"prompt_tokens": 123,
"completion_tokens": 123,
"total_tokens": 123
}
}
API 沙盒环境支持实时请求调试,直观查看接口返回数据。
为了代码安全,建议:
- 通过环境变量管理敏感信息(如 API Key),比如对于 Python 调用,使用
os.getenv("AIHUBMIX_API_KEY")
。
- 不要在日志/输出中打印敏感信息。
- 不要将密钥提交到代码仓库,将 .env 添加到 .gitignore 来防止泄漏。
Bearer 认证,需要在请求头中添加 Authorization: Bearer AIHUBMIX_API_KEY,可在 这里 获取 API 密钥
要使用的模型 ID,可在 模型广场 查看可用模型列表
消息角色,支持 user、assistant、system、developer 等
采样温度,控制输出的随机性,范围 0-2,值越大随机性越高