9.4 KiB
One API
✨ All in one 的 OpenAIInterface, integrating various API access methods, out of the box ✨
program download · Deployment Tutorial · Feedback · screenshot display · online demo · common problem
Warning
:Upgrading from
v0.2
tov0.3
requires manual database migration, please manually execute database migration script.
Function
- Multiple API access channels are supported. PRs or issues are welcome to add more channels:
- Support access to multiple channels through load balancing. 3.Support stream mode, you can achieve typewriter effect through streaming.
- Support multi-machine deployment, [see here for details](#multi-machine deployment).
- Support token management, set the expiration time and usage times of the token.
- 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.
- Support for publishing announcements, setting recharge links, and setting new user initial quotas。
- Support rich custom settings,
- Support custom system name, logo and footer.
- 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.
- Support for accessing the management API through system access tokens. 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).
- In the future, after other large models open APIs, they will be supported as soon as possible and encapsulated into the same API access method.
deployment
Deploy based on Docker
implement:docker run -d --restart always -p 3000:3000 -v /home/ubuntu/data/one-api:/data justsong/one-api
-p 3000:3000
The first 3000
in is the host port, 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.
Nginx The reference configuration:
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
- 从 GitHub Releases Download the executable 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 backend cd .. go mod download go build -ldflags "-s -w" -o one-api
- run:
chmod u+x one-api ./one-api --port 3000 --log-dir ./logs
- Visit http://localhost:3000/ and log in. The initial account username is
root
, and the password is123456
.
A more detailed deployment tutorial see here.
Multi-machine deployment
- All servers
SESSION_SECRET
set the same value. SQL_DSN
must be set, use the MySQL database instead of SQLite, please configure the synchronization of the main and standby databases by yourself.- All slave servers must set
SYNC_FREQUENCY
to periodically synchronize configuration from the database. - 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
REDIS_CONN_STRING
: After setting, Redis will be used as the storage for request frequency limit instead of memory storage.- Example:
REDIS_CONN_STRING=redis://default:redispw@localhost:49153
- Example:
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
- Example:
SQL_DSN
: After setting, the specified database will be used instead of SQLite.- Example:
SQL_DSN=root:123456@tcp(localhost:3306)/one-api
- Example:
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
- Example:
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
- Example:
Command Line Arguments
--port <port_number>
: Specify the port number that the server listens to, the default is3000
.- Example:
--port 3000
- Example:
--log-dir <log_dir>
: Specify the log folder, if not set, the log will not be saved.- Example:
--log-dir ./logs
- Example:
--version
: Print system version number and exit.--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
common problem
- 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.
- A blank page appears after the pagoda is deployed?
- For automatic configuration issues, see #97。