One API is a self-hosted LLM API management and key redistribution system that exposes many model providers through the standard OpenAI API format, aimed at developers, teams and operators who want a single endpoint, a single key model and a single quota surface across providers.
What it is
One API is an open-source API gateway for large language models, written in JavaScript and released under the MIT licence. It ships as a single executable binary and as Docker images, with an English UI, and it sits in the Developer Tools / API Development & Testing category. Its project homepage is at https://oneapi.justsong.cn/, and its topics list it as an api, api-gateway, openai-api and proxy project that also covers azure-openai-api, chatgpt, claude, ernie-bot, gemini and gpt.
The concrete problem it solves is provider fragmentation. Without it, a client must speak the native protocol and carry the native credentials of every provider it uses: OpenAI ChatGPT and Azure OpenAI API, Anthropic Claude (including AWS Claude), Google PaLM2/Gemini, Mistral, ByteDance Doubao on Volcano Engine, Baidu ERNIE, Alibaba Qwen, iFlytek Spark, Zhipu ChatGLM, 360 Zhinao, Tencent Hunyuan, Moonshot AI, Baichuan, MINIMAX, Groq, Ollama, 01.AI, StepFun, Coze, Cohere, DeepSeek, Cloudflare Workers AI, DeepL, together.ai, novita.ai, SiliconFlow and xAI. One API replaces that per-provider client integration with one OpenAI-compatible surface: requests arrive in the standard OpenAI API format, and the gateway adapts, routes and accounts for them.
Key capabilities
- Unified OpenAI API format access to the provider list above, plus Azure OpenAI API and AWS Claude endpoints.
- Channel management with load balancing across multiple channels, batch channel creation, per-channel model lists, and automatic retry on failure.
- Token management that sets token expiry, quota, allowed IP range and allowed model access.
- Redemption code management with batch generation and export, letting codes recharge user accounts.
- User groups and channel groups, each configurable with its own multiplier rate, plus quota detail views, USD-denominated quota display and user invite rewards.
- Stream mode for typewriter-style streaming output, and an image generation interface.
- Management API driven by a system access token, documented in
docs/API.md, so functionality can be extended and customised without forking the project.
- Multiple login paths: email registration with an optional whitelist and email-based password reset, Feishu authorisation, GitHub authorisation and WeChat official account authorisation, with Cloudflare Turnstile available for user verification.
- Customisation hooks: system name, logo and footer, homepage and About pages via HTML, Markdown or an iframe, and theme selection through the
THEME environment variable.
Who uses it and how
- Small installs run the single container with the default SQLite storage, while larger deployments point at MySQL through the
SQL_DSN environment variable and run multi-machine setups behind one endpoint.
- API resellers and internal platform teams use redemption codes, group multipliers, quota detail, invite rewards, announcements and charge links to operate a metered distribution service on top of upstream provider keys.
- Organisations that need managed identity use the email whitelist, Feishu, GitHub and WeChat official account login routes, with the WeChat path requiring an additional deployment of WeChat Server.
- Operators route alerts to messaging apps by pairing the gateway with Message Pusher, and deploy the Cloudflare AI Gateway as a channel proxy by filling
https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openai in the channel proxy field.
- Front-end teams customise branding, terms pages and about pages without touching application code.
Getting started
Deploy with Docker using the stable image justsong/one-api (or ghcr.io/songquanpeng/one-api), for example docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api; add -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" to use MySQL instead of SQLite. Alpha images are published as justsong/one-api-alpha and ghcr.io/songquanpeng/one-api-alpha.
How it compares
This registry entry lists no paid products that One API is documented as replacing, and it names no directly comparable gateway project in the supplied facts, so on the evidence available it stands alone here. Its position is defined by its own terms: MIT licensed, self-hosted, single binary or Docker image, with the key management and redistribution layer included rather than sold as a hosted service.
When to use it — and when not to
A self-hoster must run and back up the data store, choosing between the default SQLite file and an external MySQL instance, and must change the default root password 123456 immediately after the first login. Compliance is on the operator: the project states that users must follow OpenAI's terms of use and applicable law, and that unregistered generative AI services must not be offered to the public in China under the Interim Measures for the Management of Generative AI Services. The project also carries a large open issue count (1036 at the time of writing), so anyone expecting a quiet, fully triaged tracker should look elsewhere.
project readme (upstream, from github) — read inline
中文 | English | 日本語
One API
✨ 通过标准的 OpenAI API 格式访问所有的大模型,开箱即用 ✨
部署教程
·
使用方法
·
意见反馈
·
截图展示
·
在线演示
·
常见问题
·
相关项目
·
赞赏支持
[!NOTE]
本项目为开源项目,使用者必须在遵循 OpenAI 的使用条款以及法律法规的情况下使用,不得用于非法用途。
根据《生成式人工智能服务管理暂行办法》的要求,请勿对中国地区公众提供一切未经备案的生成式人工智能服务。
[!NOTE]
稳定版 / 预览版镜像地址:justsong/one-api
或者 ghcr.io/songquanpeng/one-api
alpha 版镜像地址:justsong/one-api-alpha
或者 ghcr.io/songquanpeng/one-api-alpha
[!WARNING]
使用 root 用户初次登录系统后,务必修改默认密码 123456!
功能
- 支持多种大模型:
- 支持配置镜像以及众多第三方代理服务。
- 支持通过负载均衡的方式访问多个渠道。
- 支持 stream 模式,可以通过流式传输实现打字机效果。
- 支持多机部署,详见此处。
- 支持令牌管理,设置令牌的过期时间、额度、允许的 IP 范围以及允许的模型访问。
- 支持兑换码管理,支持批量生成和导出兑换码,可使用兑换码为账户进行充值。
- 支持渠道管理,批量创建渠道。
- 支持用户分组以及渠道分组,支持为不同分组设置不同的倍率。
- 支持渠道设置模型列表。
- 支持查看额度明细。
- 支持用户邀请奖励。
- 支持以美元为单位显示额度。
- 支持发布公告,设置充值链接,设置新用户初始额度。
- 支持模型映射,重定向用户的请求模型,如无必要请不要设置,设置之后会导致请求体被重新构造而非直接透传,会导致部分还未正式支持的字段无法传递成功。
- 支持失败自动重试。
- 支持绘图接口。
- 支持 Cloudflare AI Gateway,渠道设置的代理部分填写
https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openai 即可。
- 支持丰富的自定义设置,
- 支持自定义系统名称,logo 以及页脚。
- 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。
- 支持通过系统访问令牌调用管理 API,进而在无需二开的情况下扩展和自定义 One API 的功能,详情请参考此处 API 文档。
- 支持 Cloudflare Turnstile 用户校验。
- 支持用户管理,支持多种用户登录注册方式:
- 支持主题切换,设置环境变量
THEME 即可,默认为 default,欢迎 PR 更多主题,具体参考此处。
- 配合 Message Pusher 可将报警信息推送到多种 App 上。
部署
基于 Docker 进行部署
# 使用 SQLite 的部署命令:
docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
# 使用 MySQL 的部署命令,在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`,请自行修改数据库连接参数,不清楚如何修改请参见下面环境变量一节。
# 例如:
docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api
其中,-p 3000:3000 中的第一个 3000 是宿主机的端口,可以根据需要进行修改。
数据和日志将会保存在宿主机的 /home/ubuntu/data/one-api 目录,请确保该目录存在且具有写入权限,或者更改为合适的目录。
如果启动失败,请添加 --privileged=true,具体参考 https://github.com/songquanpeng/one-api/issues/482 。
如果上面的镜像无法拉取,可以尝试使用 GitHub 的 Docker 镜像,将上面的 justsong/one-api 替换为 ghcr.io/songquanpeng/one-api 即可。
如果你的并发量较大,务必设置 SQL_DSN,详见下面环境变量一节。
更新命令:docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR
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_read_timeout 300s; # GPT-4 需要较长的超时时间,请自行调整
}
}
之后使用 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
初始账号用户名为 root,密码为 123456。
通过宝塔面板进行一键部署
- 安装宝塔面板9.2.0及以上版本,前往 宝塔面板 官网,选择正式版的脚本下载安装;
- 安装后登录宝塔面板,在左侧菜单栏中点击
Docker,首次进入会提示安装 Docker 服务,点击立即安装,按提示完成安装;
- 安装完成后在应用商店中搜索
One-API,点击安装,配置域名等基本信息即可完成安装;
基于 Docker Compose 进行部署
仅启动方式不同,参数设置不变,请参考基于 Docker 部署部分
# 目前支持 MySQL 启动,数据存储在 ./data/mysql 文件夹内
docker-compose up -d
# 查看部署状态
docker-compose ps
手动部署
- 从 GitHub Releases 下载可执行文件或者从源码编译:
git clone https://github.com/songquanpeng/one-api.git
# 构建前端
cd one-api/web/default
npm install
npm run build
# 构建后端
cd ../..
go mod download
go build -ldflags "-s -w" -o one-api
- 运行:
chmod u+x one-api
./one-api --port 3000 --log-dir ./logs
- 访问 http://localhost:3000/ 并登录。初始账号用户名为
root,密码为 123456。
更加详细的部署教程参见此处。
多机部署
- 所有服务器
SESSION_SECRET 设置一样的值。
- 必须设置
SQL_DSN,使用 MySQL 数据库而非 SQLite,所有服务器连接同一个数据库。
- 所有从服务器必须设置
NODE_TYPE 为 slave,不设置则默认为主服务器。
- 设置
SYNC_FREQUENCY 后服务器将定期从数据库同步配置,在使用远程数据库的情况下,推荐设置该项并启用 Redis,无论主从。
- 从服务器可以选择设置
FRONTEND_BASE_URL,以重定向页面请求到主服务器。
- 从服务器上分别装好 Redis,设置好
REDIS_CONN_STRING,这样可以做到在缓存未过期的情况下数据库零访问,可以减少延迟(Redis 集群或者哨兵模式的支持请参考环境变量说明)。
- 如果主服务器访问数据库延迟也比较高,则也需要启用 Redis,并设置 `SYN