OpenAI 接口管理 & 分发系统,支持 Azure、Anthropic Claude、Google PaLM 2 & Gemini、智谱 ChatGLM、百度文心一言、讯飞星火认知、阿里通义千问、360 智脑以及腾讯混元,可用于二次分发管理 key,仅单可执行文件,已打包好 Docker 镜像,一键部署,开箱即用. OpenAI key management & redistribution system, using a single API for all LLMs, and features an English UI.
Go to file
2023-05-20 12:10:52 +05:30
.github ci: build arm version 2023-05-15 15:14:33 +08:00
bin feat: add database migration script 2023-05-16 11:36:00 +08:00
common Update init.go 2023-05-19 22:36:01 +05:30
controller Update wechat.go 2023-05-19 23:13:11 +05:30
middleware Update turnstile-check.go 2023-05-19 23:18:18 +05:30
model Update user.go 2023-05-19 23:31:52 +05:30
router feat: support redirecting frontend url now (close #89) 2023-05-18 12:26:18 +08:00
web Update RedemptionsTable.js 2023-05-20 12:10:52 +05:30
.gitignore chore: update gitignore 2023-04-26 13:04:11 +08:00
docker-compose.yml feat: add Docker Compose support (#55) 2023-05-11 16:56:14 +08:00
Dockerfile chore: update Dockerfile 2023-04-26 13:04:01 +08:00
go.mod refactor: use built in smtp library (close #34) 2023-05-13 15:30:09 +08:00
go.sum refactor: use built in smtp library (close #34) 2023-05-13 15:30:09 +08:00
LICENSE docs: update LICENSE 2023-04-26 13:04:41 +08:00
main.go feat: now slave server can sync options with master server (close #88) 2023-05-18 12:48:20 +08:00
one-api.service feat: add Docker Compose support (#55) 2023-05-11 16:56:14 +08:00
README.md Update README.md 2023-05-19 22:29:14 +05:30

one-api logo

One API

All in one's OpenAI interface, integrating various API access methods, out of the box

license release docker pull release GoReportCard

Program Download · Deployment Tutorial · Feedback · Screenshot display · Online Demo · FAQ

Warning

: Upgrading from v0.2 to v0.3 requires manual database migration, please manually execute database migration script .

Function

  1. Multiple API access channels are supported. PRs or issues are welcome to add more channels:
  2. Support access to multiple channels through load balancing.
  3. Support stream mode, you can achieve typewriter effect through streaming.
  4. Support multi-machine deployment, [see here for details](#multi-machine deployment).
  5. Support token management, set the expiration time and usage times of the token.
  6. Supports redemption code management, supports batch generation and export of redemption codes, and can use redemption codes to recharge accounts.
  7. Support channel management, create channels in batches.
  8. Support for publishing announcements, setting recharge links, and setting initial quotas for new users.
  9. Support rich custom settings,
    1. Support custom system name, logo and footer.
    2. Support custom homepage and about page, you can choose to use HTML & Markdown code to customize, or use a separate webpage to embed through iframe.
  10. Support accessing management API through system access token.
  11. Support user management, support multiple user login and registration methods:
    • Email login registration and password reset through email.
    • GitHub Open License.
    • WeChat official account authorization (requires additional deployment of WeChat Server).
  12. In the future, after other large models open their APIs, they will be supported as soon as possible and encapsulated into the same API access method.

deployment

Deploy based on Docker

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

The first 3000 in -p 3000:3000 is the port of the host machine, which can be modified as needed.

The data will be saved in the /home/ubuntu/data/one-api directory of the host machine, please make sure the directory exists and has write permission, or change to a suitable directory.

Reference configuration of Nginx:

server {
    server_name openai.justsong.cn; # Please modify your domain name according to the actual situation
   
    location / {
           client_max_body_size 64m;
           proxy_http_version 1.1;
           proxy_pass http://localhost:3000; # Please modify your port according to the actual situation
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $remote_addr;
           proxy_cache_bypass $http_upgrade;
           proxy_set_header Accept-Encoding gzip;
    }
}

Then configure HTTPS with Let's Encrypt's certbot:

# Ubuntu install certbot:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
# Generate certificate & modify Nginx configuration
sudo certbot --nginx
# Follow instructions
# restart nginx
sudo service nginx restart

Manual deployment

  1. Download the executable from GitHub Releases or compile from source:
    git clone https://github.com/songquanpeng/one-api.git
    
    # Build the front end
    cd one-api/web
    npm install
    npm run build
    
    # Build the backend
    cd..
    go mod download
    go build -ldflags "-s -w" -o one-api
    
  2. Run:
    chmod u+x one-api
    ./one-api --port 3000 --log-dir ./logs
    
  3. Visit http://localhost:3000/ and log in. The initial account username is root, and the password is 123456.

A more detailed deployment tutorial see here.

Multi-machine deployment

  1. All servers SESSION_SECRET set the same value.
  2. SQL_DSN must be set, use the MySQL database instead of SQLite, please configure the synchronization of the main and standby databases by yourself.
  3. All slave servers must set SYNC_FREQUENCY to periodically synchronize configuration from the database.
  4. The slave server can optionally set FRONTEND_BASE_URL to redirect page requests to the master server.

For details on how to use environment variables, see [here](#environment variables).

configuration

The system itself works out of the box.

You can configure it by setting environment variables or command line parameters.

After the system starts, use root user to log in to the system and do further configuration.

How to use

Add your API Key in the Channels page, and then add an access token in the Tokens page.

Then you can use your token to access the One API in the same way as OpenAI API.

You can specify which channel to use to process this request by adding the channel ID after the token, for example: Authorization: Bearer ONE_API_KEY-CHANNEL_ID. Note that a token created by an admin user is required to specify a channel ID.

If not added, multiple channels will be used in a load balancing manner.

Environment variables

  1. REDIS_CONN_STRING: After setting, Redis will be used as the storage for request frequency limit instead ofUse memory storage.
    • Example: REDIS_CONN_STRING=redis://default:redispw@localhost:49153
  2. SESSION_SECRET: After setting, a fixed session key will be used, so that the logged-in user's cookie will still be valid after the system restarts.
    • Example: SESSION_SECRET=random_string
  3. SQL_DSN: After setting, the specified database will be used instead of SQLite.
    • Example: SQL_DSN=root:123456@tcp(localhost:3306)/one-api
  4. FRONTEND_BASE_URL: After setting, the specified front-end address will be used instead of the back-end address.
    • Example: FRONTEND_BASE_URL=https://openai.justsong.cn
  5. SYNC_FREQUENCY: After setting, the configuration will be periodically synchronized with the database, in seconds, if not set, no synchronization will be performed.
    • Example: SYNC_FREQUENCY=60

Command Line Arguments

  1. --port <port_number>: Specify the port number that the server listens to, the default is 3000.
    • Example: --port 3000
  2. --log-dir <log_dir>: Specify the log folder, if not set, the log will not be saved.
    • Example: --log-dir ./logs
  3. --version: Print system version number and exit.
  4. --help: View the help and parameter description of the command.

Demo

Online Demo

Note that this demo site does not provide external services: https://openai.justsong.cn

Screenshot display

channel token

common problem

  1. Why is it prompted that the account limit is insufficient?
    • Please check whether your token limit is sufficient, this is separate from the account limit.
    • The token quota is only for the user to set the maximum usage, and the user can set it freely.
  2. A blank page appears after the pagoda is deployed?
    • For automatic configuration issues, see #97 for details.