> ## Documentation Index
> Fetch the complete documentation index at: https://doc.iqqz.com/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI官方SDK使用教程

:::tip
我们的API，完全兼容OpenAI接口协议，支持无缝对接各种支持OpenAI接口的应用。
注意： 所有聊天模型（包括非openai模型）都支持openai官方库，请求url和格式请都遵循openai的请求方式。
参考：[官方开发文档](https://platform.openai.com/docs/introduction/overview)

Cluade模型同时支持官方与OpenAi两种请求方式。

请求接口时将 `https://api.openai.com` 改为我们的 API 地址（在 `iqqz 控制台` -> `控制台` 中可查看 API 地址）
你的 KEY 要与 iqqz 控制台对应，千万别将混合站点与官转站点弄混了。
:::

## OpenAi官方python库

> [官方项目地址](https://github.com/openai/openai-python)
> ⚠️ 注意：请将openai库升级到1.25+版本或最新版本，否则调用出错不提供任何帮助。

### 安装

```sh theme={null}
pip install openai
```

### 请求示例：

注意：`base_url`需要传入`/v1/`后缀。

```python theme={null}
import os
import openai

openai.api_key = "您的apikey"

openai.base_url = "https://api.iqqz.com/v1/"
openai.default_headers = {"x-foo": "true"}

completion = openai.chat.completions.create(
    model="gpt-4.1-mini",
    messages=[
        {
            "role": "user",
            "content": "Hello world!",
        },
    ],
)
print(completion.choices[0].message.content)

# 正常会输出结果：Hello there! How can I assist you today ?
```

## OpenAi官方node库

> [官方项目地址](https://github.com/openai/openai-node)
> ⚠️ 注意：请将openai库升级到最新版本，否则调用出错不提供任何帮助。

### 安装

```sh theme={null}
npm install openai
```

### 请求示例：

注意：`base_url`需要传入`/v1`后缀。

```js theme={null}
const { Configuration, OpenAIApi } = require("openai");

const configuration = new Configuration({
  apiKey: "您的apikey",
  basePath: "https://api.iqqz.com/v1"
});
const openai = new OpenAIApi(configuration);

const chatCompletion = await openai.createChatCompletion({
  model: "gpt-3.5-turbo",
  messages: [{role: "user", content: "Hello world"}],
});

console.log(chatCompletion.data.choices[0].message.content);
```
