---
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`：0–2，控制随机性
- `max_tokens`：最大生成 token
- `stream: true`：开启流式，见 [流式调用](/docs/guides/streaming)

## 模型 ID

请在控制台 **模型广场** 查看当前可用 ID；名称可能随供应商更新，以控制台为准。
