快速开始
本指南介绍如何使用 NexusModels API 发起第一个模型请求。
API 基础地址
text
https://api.nexusmodels.cn/v1获取 API Key
您需要使用 NexusModels 虚拟 Key 调用接口。
虚拟 Key 的格式通常为:
text
sk-xxxxxxxxxxxxxxxx请妥善保管 API Key,不要将其提交到公开代码仓库或暴露在浏览器前端代码中。
使用 curl 调用
bash
curl https://api.nexusmodels.cn/v1/chat/completions \
-H "Authorization: Bearer YOUR_NEXUSMODELS_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.4",
"messages": [
{
"role": "user",
"content": "你好"
}
]
}'使用 Python 调用
安装 OpenAI SDK:
bash
pip install openai调用示例:
python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_NEXUSMODELS_API_KEY",
base_url="https://api.nexusmodels.cn/v1",
)
response = client.chat.completions.create(
model="gpt-5.4",
messages=[
{
"role": "user",
"content": "你好",
}
],
)
print(response.choices[0].message.content)使用 Node.js 调用
安装 OpenAI SDK:
bash
npm install openai调用示例:
javascript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_NEXUSMODELS_API_KEY",
baseURL: "https://api.nexusmodels.cn/v1",
});
const response = await client.chat.completions.create({
model: "gpt-5.4",
messages: [
{
role: "user",
content: "你好",
},
],
});
console.log(response.choices[0].message.content);环境变量
生产环境建议通过环境变量保存 API Key:
bash
export NEXUSMODELS_API_KEY="YOUR_NEXUSMODELS_API_KEY"不要将真实 API Key 直接写入源代码。