Files
haiyushuke-website/content/models/openai.mdx
2026-06-16 14:34:09 +08:00

63 lines
1.4 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: OpenAI 接入
sidebarTitle: OpenAI
description: 通过 OpenAI 兼容协议接入 GPT 系列模型
---
# OpenAI 兼容接入
海宇数科对 OpenAI 官方 SDK 及 HTTP API 提供兼容层,便于现有应用零改造迁移。
## 端点
| 项目 | 值 |
| --- | --- |
| Base URL | `https://api.haiyushuke.com/v1` |
| Chat Completions | `POST /chat/completions` |
| 鉴权 | `Authorization: Bearer <API_KEY>` |
## Node.js官方 SDK
```ts
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.HAIYUSHUKE_API_KEY,
baseURL: "https://api.haiyushuke.com/v1",
});
const completion = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [{ role: "user", content: "Hello" }],
});
console.log(completion.choices[0]?.message?.content);
```
## Python
```python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://api.haiyushuke.com/v1",
)
resp = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.choices[0].message.content)
```
## 常用参数
- `temperature`02控制随机性
- `max_tokens`:最大生成 token
- `stream: true`:开启流式,见 [流式调用](/docs/guides/streaming)
## 模型 ID
请在控制台 **模型广场** 查看当前可用 ID名称可能随供应商更新以控制台为准。