Skip to content

开发接入

AK46平台完全兼容OpenAI的接口协议,因此可以放心的使用OpenAI的SDK,无缝对接各种兼容OpenAI接口协议的模型。

只需使用<AK46接口地址><AK46令牌>,即可使用所有主流厂商的近400个AI模型,切换成本几乎为零,架构灵活,生态成熟。

  • <AK46接口地址>: 在 AK46平台 -> 控制台 中可查看
  • <AK46令牌>: 在 AK46平台 -> 控制台 -> 令牌管理 可创建和复制

OpenAI官方文档

使用HTTP请求

请求<AK46接口地址>,并在header中设置Authorization = Bearer <令牌>,其余参数可查阅OpenAI接口参考

示例:

shell
curl --location --request POST '<AK46接口地址>/v1/chat/completions' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <AK46令牌>' \
--data-raw '{
  "model": "gpt-3.5-turbo",
  "messages": [{"role": "user", "content": "Hello AK46!"}],
  "temperature": 0.7
 }'

使用Python SDK

⚠️ 请使用1.25+版本或更新的版本。

安装

sh
pip install openai

设置base_urlapi_key后,即可正常调用方法。

示例:

python
import os
import openai

openai.api_key = "<AK46令牌>"

openai.base_url = "<AK46接口地址>"
openai.default_headers = {"x-foo": "true"}

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

使用Node.js SDK

⚠️ 请使用最新版本。

安装

sh
npm install openai

设置base_url和api_key后,即可正常调用方法。

请求示例:

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

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

const configuration = new Configuration({
  apiKey: "<AK46令牌>",
  basePath: "<AK46接口地址>"
});
const openai = new OpenAIApi(configuration);

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

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

Please be aware that our API is intended for testing and experiential learning. Use in compliance with your local laws. Illegal use is prohibited. No liability assumed for misuse.