主题
接入 OpenAI GPT 系列
通过 WMB-AI 中转 API,调用 GPT-4o、GPT-4.1 等 OpenAI 模型,兼容 OpenAI SDK。
前提条件
- 已获取 WMB-AI API Key(前往控制台)
配置方式
Python
python
from openai import OpenAI
client = OpenAI(
api_key="你的API Key",
base_url="https://api.wmbai.com/v1",
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "你好"}],
)
print(response.choices[0].message.content)Node.js
javascript
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: '你的API Key',
baseURL: 'https://api.wmbai.com/v1',
})
const res = await client.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: '你好' }],
})
console.log(res.choices[0].message.content)curl
bash
curl https://api.wmbai.com/v1/chat/completions \
-H "Authorization: Bearer 你的API Key" \
-H "Content-Type: application/json" \
-d '{"model":"gpt-4o","messages":[{"role":"user","content":"你好"}]}'TIP
可用模型列表请参考 完整模型列表。
