Code Monkey home page Code Monkey logo

one-api's Introduction

one-api logo

One API

✨ All in one 的 OpenAI 接口,整合各种 API 访问方式,开箱即用✨

license release docker pull release GoReportCard

程序下载 · 部署教程 · 意见反馈 · 截图展示 · 在线演示

功能

  1. 支持多种 API 访问渠道,欢迎 PR 或提 issue 添加更多渠道:
  2. 支持通过负载均衡的方式访问多个渠道。
  3. 支持单个访问渠道设置多个 API Key,利用起来你的多个 API Key。
  4. 支持 HTTP SSE,可以通过流式传输实现打字机效果。
  5. 支持设置令牌的过期时间和使用次数。
  6. 支持批量生成和导出兑换码,可使用兑换码为令牌进行充值。
  7. 支持为新用户设置初始配额。
  8. 支持发布公告,在线修改关于页面,设置充值链接,自定义页脚。
  9. 支持通过系统访问令牌访问管理 API。
  10. 多种用户登录注册方式:
  11. 支持用户管理。
  12. 未来其他大模型开放 API 后,将第一时间支持,并将其封装成同样的 API 访问方式。

部署

基于 Docker 进行部署

执行:docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api

-p 3000:3000 中的第一个 3000 是宿主机的端口,可以根据需要进行修改。

数据将会保存在宿主机的 /home/ubuntu/data/one-api 目录,请确保该目录存在且具有写入权限,或者更改为合适的目录。

Nginx 的参考配置:

server{
   server_name openai.justsong.cn;  # 请根据实际情况修改你的域名
   
   location / {
          client_max_body_size  64m;
          proxy_http_version 1.1;
          proxy_pass http://localhost:3000;  # 请根据实际情况修改你的端口
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $remote_addr;
          proxy_cache_bypass $http_upgrade;
          proxy_set_header Accept-Encoding gzip;
          proxy_buffering off;  # 重要:关闭代理缓冲
   }
}

注意,为了 SSE 正常工作,需要关闭 Nginx 的代理缓冲。

之后使用 Let's Encrypt 的 certbot 配置 HTTPS:

# Ubuntu 安装 certbot:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
# 生成证书 & 修改 Nginx 配置
sudo certbot --nginx
# 根据指示进行操作
# 重启 Nginx
sudo service nginx restart

手动部署

  1. GitHub Releases 下载可执行文件或者从源码编译:
    git clone https://github.com/songquanpeng/one-api.git
    
    # 构建前端
    cd one-api/web
    npm install
    npm run build
    
    # 构建后端
    cd ..
    go mod download
    go build -ldflags "-s -w" -o one-api
  2. 运行:
    chmod u+x one-api
    ./one-api --port 3000 --log-dir ./logs
  3. 访问 http://localhost:3000/ 并登录。初始账号用户名为 root,密码为 123456

更加详细的部署教程参见此处

配置

系统本身开箱即用。

你可以通过设置环境变量或者命令行参数进行配置。

等到系统启动后,使用 root 用户登录系统并做进一步的配置。

使用方式

渠道页面中添加你的 API Key,之后在令牌页面中新增一个访问令牌。

之后就可以使用你的令牌访问 One API 了,使用方式与 OpenAI API 一致。

可以通过在令牌后面添加渠道 ID 的方式指定使用哪一个渠道处理本次请求,例如:Authorization: Bearer ONE_API_KEY-CHANNEL_ID。 注意,需要是管理员用户创建的令牌才能指定渠道 ID。

不加的话将会使用负载均衡的方式使用多个渠道。

环境变量

  1. REDIS_CONN_STRING:设置之后将使用 Redis 作为请求频率限制的存储,而非使用内存存储。
    • 例子:REDIS_CONN_STRING=redis://default:redispw@localhost:49153
  2. SESSION_SECRET:设置之后将使用固定的会话密钥,这样系统重新启动后已登录用户的 cookie 将依旧有效。
    • 例子:SESSION_SECRET=random_string
  3. SQL_DSN:设置之后将使用指定数据库而非 SQLite。
    • 例子:SQL_DSN=root:123456@tcp(localhost:3306)/one-api

命令行参数

  1. --port <port_number>: 指定服务器监听的端口号,默认为 3000
    • 例子:--port 3000
  2. --log-dir <log_dir>: 指定日志文件夹,如果没有设置,日志将不会被保存。
    • 例子:--log-dir ./logs
  3. --version: 打印系统版本号并退出。
  4. --help: 查看命令的使用帮助和参数说明。

演示

在线演示

注意,该演示站不提供对外服务: https://openai.justsong.cn

截图展示

channel token

one-api's People

Contributors

songquanpeng avatar ccbond avatar shiqimei avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.