new-api

QuantumNousAGPL-3.0活跃维护

自托管的 LLM 网关,统一兼容 OpenAI、Claude、Gemini 等接口,提供模型路由、访问控制、用量统计与成本核算,方便团队集中管理和分发大模型调用。

Open-source AI gateway. Self-hosted LLM gateway with OpenAI-, Claude- and Gemini-compatible APIs, model routing, access control, usage tracking and cost accounting.

v1.0.0-rc.49发布于 2026-11-08 05:06 UTC51,692star +179 / 7 天12,596fork同步于 2026-11-10 11:19 UTC

怎么上手

由 README 提炼,执行前请确认
mkdir -p data
docker run --name new-api -d --restart unless-stopped -p 127.0.0.1:3000:3000 -e TZ=Asia/Shanghai -v "$(pwd)/data:/data" calciumion/new-api:latest
硬件要求按 README 说明

README 未说明显存或 GPU 要求;提供 Linux amd64 / arm64 容器镜像,本地可用 Docker 单实例运行。

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

自托管 AI 网关,统一接入多家模型服务并集中管理路由、权限与成本

自托管的 LLM 网关,统一兼容 OpenAI、Claude、Gemini 等接口,提供模型路由、访问控制、用量统计与成本核算,方便团队集中管理和分发大模型调用。

核心能力

  • 兼容 OpenAI、Claude、Gemini 协议对外提供统一 API
  • 按模型映射、渠道优先级与权重做路由并支持重试
  • 按配额、订阅与表达式定价统计用量和成本
  • 支持用户分组、细粒度权限与 API Key 限制
  • 用 JavaScript 插件扩展图像、视频等异步任务接口

容易踩的坑

默认监听 3000 端口,首次访问需完成安装向导创建管理员账号;Compose 部署前必须改掉示例数据库和 Redis 密码并设置持久 SESSION_SECRET;仅复制 .env.example 不会把变量注入容器,需在 Compose 的 environment 或 env_file 中配置。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v1.0.0-rc.49
  1. v1.0.0-rc.49最新正式版2026-11-08 · 2026-11-08 05:06 UTC

    [!IMPORTANT] 增加了 gpt-image-2.6 的支持。它的新参数 complexity、svg、frame_count、frame_duration_ms 和 markup 会转发给上游,可以生成 SVG 和 GIF,编辑图片时可以带 markup 标注图层。

    修复了 Redis 集群和分片 Redis 上修改用户或令牌时报 keys must in same slot 的问题。多节点部署请把所有节点一起升级,新旧版本混跑时,一个节点上的用户和令牌变更不一定能及时同步到另一个版本的节点。

    SQLITE_PATH 只写文件路径时,现在和默认配置一样开启 WAL 和写入等待。数据库旁边会多出 -wal 和 -shm 文件,备份时要一起复制。

    模型定价保存时会逐个模型列出当前价格和新价格,确认后才保存。删掉的价格在保存前可以撤销。

    Added support for gpt-image-2.6. Its new parameters complexity, svg, frame_count, frame_duration_ms, and markup are forwarded to the upstream, so it can generate SVG and GIF images, and image edits can include a markup layer.

    Fixed the problem of keys must in same slot errors when editing users or tokens on Redis Cluster or sharded Redis. Upgrade every node of a multi-node deployment together. While old and new versions run side by side, a user or token change on one node may not reach nodes on the other version in time.

    A SQLITE_PATH that is only a file path now gets WAL and the busy timeout, the same as the default setting. -wal and -shm files appear next to the database. Copy them together with it when you back up.

    Saving Model Pricing now lists the current and new price of each model and saves only after you confirm. A deleted price can be undone until you save.

    中文

    • 任务插件:增加了 Vertex AI 渠道的 Gemini Omni 1.2 Flash,视频最长 15 秒。修复了 Gemini Omni 只把第一张输入图片发给 Vertex 的问题。Gemini Omni 生成失败时会返回失败原因。从插件市场安装或上传的插件也能用顶层的 /v1 地址调用了,比如 TypeSafe 的 POST /v1/systemone。
    • 计费:模型定价会列出价格需要处理的模型,选中模型能看到原因和处理方法。只统计启用的渠道实际提供的模型,内置价格只在已保存或有渠道提供时才列出。删掉的价格在保存前只是草稿,可以撤销。改过的行会显示新旧价格,保存时逐个模型列出当前价格和新价格,确认后才保存。在手机上,标签页单独占一行可以滑动,次要操作收进了菜单。
    • 渠道:增加了 gpt-image-2.6 的支持,complexity、svg、frame_count、frame_duration_ms 和 markup 参数会转发给上游,可以生成 SVG 和 GIF,编辑图片时可以带 markup 标注图层。DeepSeek 官方 Responses 接口的工具调用历史缺少 reasoning 时会自动补上,避免 DeepSeek 因此返回 400。高级自定义渠道的入口路径增加了 /v1/tools/search 和 /v1/tools/fetch。修复了 Vertex AI 服务账号每个请求都重新换取访问令牌的问题,令牌现在缓存到过期前 5 分钟。修复了多密钥渠道的密钥全部失败后,重新启用其中一个密钥,渠道仍然处于自动禁用的问题。修复了手动禁用的渠道在请求失败后变成自动禁用、又被自动测试重新启用的问题。渠道亲和性里的会话规则可以单独清空自己的缓存,刷新统计和清空缓存的说明也写清楚了。
    • 其他:修复了 Redis 集群和分片 Redis 上修改用户或令牌时报错的问题。修复了 SQLITE_PATH 只写文件路径时丢掉 WAL 和写入等待设置,并发写入报 "database is locked" 的问题。修复了用邀请码通过 OAuth 注册的新用户没有记录邀请人的问题。

    English

    • Task plugins: Added Gemini Omni 1.2 Flash on Vertex AI channels, with videos up to 15 seconds. Fixed the problem of Gemini Omni sending only the first input image to Vertex. A failed Gemini Omni generation now returns the reason. Plugins installed from the marketplace or uploaded can now be called at their top-level /v1 paths too, such as TypeSafe's POST /v1/systemone.
    • Billing: Model Pricing lists the models whose prices need attention. Select a model to see the reason and what to change. Only models an enabled channel serves are counted, and built-in prices are listed only when saved or served by a channel. A deleted price stays a draft until you save, and you can undo it. Changed rows show the old and new prices. Every save lists the current and new price of each model and saves only after you confirm. On phones, the tabs have their own scrollable row and secondary actions are in a menu.
    • Channels: Added support for gpt-image-2.6. Its complexity, svg, frame_count, frame_duration_ms, and markup parameters are forwarded to the upstream, so it can generate SVG and GIF images, and image edits can include a markup layer. When tool call history sent to DeepSeek's official Responses API lacks reasoning, it is filled in, so DeepSeek does not reject the request with a 400. Advanced Custom channels can use the incoming paths /v1/tools/search and /v1/tools/fetch. Fixed the problem of Vertex AI service accounts requesting a new access token for every request. Tokens are now cached until 5 minutes before they expire. Fixed the problem of a multi-key channel staying auto-disabled when one key was enabled again after all keys failed. Fixed the problem of a manually disabled channel becoming auto-disa
  2. v1.0.0-rc.482026-11-04 · 2026-11-04 15:40 UTC
    查看更新说明

    [!IMPORTANT] Redis 里的用户、令牌和会话缓存加了签名。多节点部署请把所有节点一起升级,新节点遇到旧版本写的缓存会回数据库重新读取。

    任务插件可以用厂商自己的接口地址调用了,原来带前缀的地址照常可用。原生请求按客户端写的原样发给厂商。可灵、Vidu、MiniMax 和火山方舟的请求带 callback_url 时会被拒绝。

    增加了任务模型的价格提醒。插件改动后没法计费的模型,会在模型定价里标成「价格待处理」。

    User, token, and session caches in Redis are now signed. Upgrade every node of a multi-node deployment together. A new node reads from the database again when it finds a cache written by an older version.

    Task plugins can now be called at the vendors' own API paths. The prefixed paths still work. Native requests go to the vendor exactly as the client wrote them. Kling, Vidu, MiniMax, and Volcengine Ark requests with callback_url are rejected.

    Added price reminders for task models. Models a plugin can no longer charge are marked "Price needs attention" in Model Pricing.

    中文

    • 安全:Redis 里的用户、令牌和会话缓存加了签名,被改过、没有签名或已经过期的缓存会回数据库重新读取。修复了两步验证锁定结束后,再错一次就又被锁定的问题。
    • 任务插件:增加了用厂商官方接口地址调用任务插件的功能,比如可灵的 /v1/videos/text2video、Vidu 的 /ent/v2/text2video,回复保持厂商的格式和错误码。即梦改用官方的 Bearer 接口。增加了可灵 4.0,时长 3 到 30 秒,按可灵返回的金额扣费。用 /v1/videos 调可灵时,尺寸按宽高比选最接近的官方比例。增加了 Vertex AI 渠道的 Gemini Omni 视频生成,按 Vertex 报告的 token 计费,需要服务账号 JSON 密钥。
    • 计费:增加了任务模型的价格提醒。没设价格、价格用到插件不再提供的用量、插件不再提供的模型,会在模型定价里标成「价格待处理」并写明原因,可以按「价格状态」筛选。上传、安装或启用插件时也会列出这些模型,超级管理员的侧边栏会显示数量。修复了 prompt_tokens_details 里的 cache_creation_input_tokens 没有计费的问题。Gemini 向量改按上游返回的用量计费。修复了表达式里的按次计费在模型广场显示成按量计费的问题。
    • 渠道:增加了 Vertex AI 渠道切换到 v1beta1 接口的开关。增加了 Azure 渠道开启 Responses WebSocket 的功能。增加了 gemini-4-argon 的思考强度支持。gpt-6.1-sol 和 gpt-6.1-terra 按 GPT-6 的规则发参数。增加了上游 HTTP/2 连接的健康检查,设置 RELAY_HTTP2_PING_IDLE_TIMEOUT 开启,默认关闭。创建渠道的接口会返回新渠道的 ID,批量创建时每一行对应一个 ID。修复了渠道亲和的重试没有从最高优先级开始的问题。
    • 转换:修复了单独一行 [DONE] 没被当成流结束的问题。修复了 stop 数组里混有非字符串时转成 Claude 出错的问题。修复了转成 Claude 时工具参数里的大整数被改掉的问题。修复了 Gemini 同时返回文字和工具调用时丢掉文字的问题。修复了 Bedrock Invoke 丢掉 safeguards 的问题。修复了 Cloudflare 向量回复缺少 data 的问题。修复了 xAI 流式用量丢掉 token 明细的问题。改写请求时只改需要改的字段,其余部分保持客户端原样,字段顺序和数字不再变。
    • 其他:修复了退出登录后连着弹出几个「会话已过期」的问题。修复了 Turnstile 密钥和开关一起保存时报错的问题。修复了个人资料页还能设置管理员已经关掉的侧边栏项目的问题。修复了日志轮转后访问日志和崩溃日志还写进旧文件的问题。模型性能统计会算上客户端提前断开的非流式成功请求,以及插件立即完成的任务。

    English

    • Security: User, token, and session caches in Redis are now signed. A cache that was changed, has no signature, or has expired is read again from the database. Fixed the problem of one more wrong 2FA code after a lockout ended locking the account again.
    • Task plugins: Added calling task plugins at the vendors' official API paths, such as Kling's /v1/videos/text2video and Vidu's /ent/v2/text2video. Replies keep the vendor's format and error codes. Jimeng now uses the official Bearer API. Added Kling 4.0, with durations of 3 to 30 seconds, charged at the amount Kling returns. When Kling is called through /v1/videos, the size maps to the closest official aspect ratio. Added Gemini Omni video generation on Vertex AI channels, billed by the tokens Vertex reports. It needs a service account JSON key.
    • Billing: Added price reminders for task models. A model with no price, a price that uses usage the plugin no longer provides, or a model the plugin no longer offers is marked "Price needs attention" in Model Pricing with the reason, and a "Price status" filter lists them. Uploading, installing, or enabling a plugin lists these models too, and the sidebar shows the count to super administrators. Fixed the problem of cache_creation_input_tokens in prompt_tokens_details going unbilled. Gemini embeddings are billed by the usage the upstream returns. Fixed the problem of per-request expression prices showing as usage-based in the Model Square.
    • Channels: Added a switch that sends a Vertex AI channel's requests to v1beta1. Added Responses WebSocket for Azure channels. Added thinking effort support for gemini-4-argon. gpt-6.1-sol and gpt-6.1-terra now follow the GPT-6 parameter rules. Added a health check for upstream HTTP/2 connections, off by default; set RELAY_HTTP2_PING_IDLE_TIMEOUT to turn it on. Creating channels returns the new c
  3. v1.0.0-rc.472026-10-25 · 2026-10-25 09:04 UTC
    查看更新说明

    [!IMPORTANT] 增加了普通渠道和任务插件一起选择渠道的功能。同一个模型名,插件和普通渠道都有的时候,以前请求都发给插件,现在按优先级和权重选择渠道。

    这个模型的定价如果还是按任务插件写的,普通渠道会报价格错误,不会扣额度。可以单独给普通渠道设置价格。

    增加了 OpenAI 12 小时提示缓存单独计价的功能,按输入价格的 2.5 倍收费。

    修复了视频任务超过 24 小时就被退款的问题。默认等到 72 小时才退款。

    Added selecting a channel from both a regular channel and a task plugin. On image, video, and Responses endpoints, a model both can serve used to send every request to the plugin. The channel is now selected by priority and weight.

    If that model's price is still written for the task plugin, a regular channel returns a price error and does not charge. Set a regular price for it in pricing.

    Added a separate price for OpenAI's 12-hour prompt cache, at 2.5 times the input price. It was charged at the 30-minute rate.

    Fixed the problem of video tasks being refunded after 24 hours. They now wait 72 hours. If you set TASK_TIMEOUT_MINUTES yourself, that time stays.

    中文

    • 渠道:增加了图片、视频和 Responses 上,普通渠道和任务插件按优先级和权重一起选择渠道的功能。原生插件地址继续走对应的插件。普通渠道和插件各用各的价格。
    • 计费:增加了 OpenAI 12 小时提示缓存单独计价的功能,按输入价格的 2.5 倍收费。gpt-6-astra 的 12 小时写入是每百万 token 25 美元,超过 272K token 是 50 美元。修复了 Claude 缓存写入没拆成 5 分钟和 1 小时时不计费的问题,没拆开的按 5 分钟计费。
    • 价格同步:增加了按站点汇率调整上游价格的功能。可以保持来源价格,也可以乘以或除以汇率。价格相同的模型也能选出来一起改。
    • 任务:修复了视频任务超过 24 小时就被退款的问题,默认等到 72 小时。自己设过 TASK_TIMEOUT_MINUTES 的,还是用你设的数。修复了可灵按 metadata 里的时长生成、计费却按外面的时长算的问题。增加了任务插件原生接口接收文件上传的功能。任务插件可以读到客户端请求头,Authorization 和 Cookie 不会给插件。
    • 流式:修复了大段内容传得慢就被当成断开的问题。修复了 Responses 已经回复完、日志里却记成断开的问题,用量照常记。
    • 其他:修复了结构化输出和工具参数字段顺序被打乱的问题,按客户端原来的顺序发给上游。修复了 Chat 转 Gemini 时丢掉 imageConfig 的问题,图片尺寸和比例会带过去。修复了高级自定义保存后「透传请求体」丢失的问题。修复了编辑令牌或模型时,切到另一条还留着上一条内容的问题。修复了访问日志记下网址里的密钥的问题。增加了使用日志详情里复制模型名的功能。

    English

    • Channels: Added selecting a channel by priority and weight between a regular channel and a task plugin, on image, video, and Responses endpoints. A plugin's own address still goes to that plugin. Regular channels and plugins keep separate prices.
    • Billing: Added a separate price for OpenAI's 12-hour prompt cache, at 2.5 times the input price. gpt-6-astra bills 12-hour writes at $25 per million tokens, and $50 above 272K tokens. Fixed the problem of Claude cache writes going unbilled when they were not split into 5-minute and 1-hour amounts. The unsplit part is billed as 5-minute writes.
    • Price sync: Added adjusting synced upstream prices by the site exchange rate. You can keep the source price, or multiply or divide by the rate. Models that already match can be selected and adjusted too.
    • Tasks: Fixed the problem of video tasks being refunded after 24 hours. The default wait is now 72 hours. A TASK_TIMEOUT_MINUTES you already set is left as it is. Fixed the problem of Kling billing the outer duration while generating the duration in metadata. Added file uploads on a plugin's own routes. Task plugins can read the client's request headers. Authorization and Cookie are not given to the plugin.
    • Streaming: Fixed the problem of a slow transfer of a large event being recorded as a disconnect. Fixed the problem of a finished Responses reply being logged as a disconnect. The usage is still recorded.
    • Also: Fixed the problem of structured output and tool parameters having their field order rearranged. They are sent in the client's order. Fixed the problem of Chat requests losing imageConfig on the way to Gemini, so image size and aspect ratio are kept. Fixed the problem of Advanced Custom dropping Pass Through Body on save. Fixed the problem of an edit drawer keeping the previous token or model when you switch records. Fixed the problem of access logs storing keys from the URL. Added copying model names from a usage log's details.

    What's Changed

  4. v1.0.0-rc.462026-10-21 · 2026-10-21 16:25 UTC
    查看更新说明

    [!IMPORTANT] 修复 CVE-2026-111943,请尽快升级。这一版用 Go 1.26.10。Go 校验证书时,会拒绝一小批已经不再可信的中间证书。用源码编译的,Go 也要换成 1.26.10。

    Fixes CVE-2026-111943. Please upgrade soon. This release runs on Go 1.26.10. When Go checks a certificate, it rejects a small set of intermediate certificates that are no longer trusted. Builds from source need Go 1.26.10 too.

    中文

    • 安全:修复 CVE-2026-111943。运行时改为 Go 1.26.10,校验证书时会拒绝一小批已经不再可信的中间证书。
    • 邮件:新增用 Resend 发邮件的功能,可以代替 SMTP。发件地址和发件人名称单独填。
    • 数据看板:新增缓存用量的显示,和总 token 放在一起。
    • 向量:新增阿里云百炼多模态向量模型 qwen3-vl-embedding 的支持,同系列的视觉向量模型也走这个接口。
    • 任务:修复任务换渠道重试时还按上一次价格计费的问题。更贵的渠道会先补预扣,余额不够就不会发出去。修复任务提交和轮询没用上「请求头覆盖」的问题。修复轮询跳到别的地址时密钥跟着过去的问题。
    • 渠道:修复可灵不接受单个密钥的问题。插件 1.1.1,不带竖线的密钥可以直接用。修复 DeepSeek 美元余额是 0、人民币有钱时,余额显示成 0 的问题。
    • 修复:修复通知限流每到整点就重新计数的问题,超过 60 分钟也按你设的时长算。修复 Claude 流式请求在准备和重试期间断开的问题。修复连续的助手消息合并后丢掉工具调用、Claude 报错的问题。修复 Redis 清掉脚本后限流失效的问题。发给 Gemini 的向量请求里带了图片或视频时,会直接拒绝,不再计费。

    English

    • Security: Fixed CVE-2026-111943 by moving to Go 1.26.10. Certificate checks reject a small set of intermediate certificates that are no longer trusted.
    • Email: Added Resend for sending mail, in place of SMTP. The sender address and sender name are set on their own.
    • Dashboard: Added cache usage next to the total token count.
    • Embeddings: Added Alibaba Bailian multimodal embeddings, starting with qwen3-vl-embedding. The other vision embedding models on Bailian use the same endpoint.
    • Tasks: Fixed a retry on another channel still using the previous price. A more expensive channel reserves the difference first, and is not called when the balance cannot cover it. Fixed task submission and polling ignoring Request Header Override. Fixed polling redirects carrying the key to another address.
    • Channels: Fixed Kling rejecting a single key. Plugin 1.1.1 accepts a key with no vertical bar. Fixed DeepSeek balance showing 0 when the USD wallet is 0 and the CNY wallet has money.
    • Fixes: Fixed notification rate limits resetting at each hour, so a window longer than 60 minutes lasts for the time you set. Fixed Claude streams dropping during preparation and retries. Fixed merged assistant messages dropping tool calls, which made Claude reject the request. Fixed rate limiting after Redis flushed its scripts. An embedding sent to Gemini with an image or video is rejected and not billed.

    What's Changed

  5. v1.0.0-rc.452026-10-17 · 2026-10-17 15:42 UTC
    查看更新说明

    [!IMPORTANT] v1 正式版即将发布,现在是最后几个 RC 版本。新增 DeepSeek V4.1 Flash、Search 和 Fetch,通知分开开关,以及拖动排列渠道优先级的功能。

    敏感词过滤默认关着。以前填过敏感词、但没保存过这个开关的,升级后到「请求检查」里打开。

    v1 is coming soon. These are the last few release candidates. Added DeepSeek V4.1 Flash, Search and Fetch, separate notification switches, and dragging to set channel priority.

    Sensitive word filtering is off by default. If you filled in a word list and never saved the switch, turn it on under Request checks after upgrading.

    中文

    • DeepSeek:新增 DeepSeek V4.1 Flash(deepseek-flash)和 deepseek-v4-pro 的支持,后面可以加 -none、-low、-max,@thinking 和 @effort 也能用。新增 Search 和 Fetch,地址是 /v1/tools/search 和 /v1/tools/fetch。Claude Code 和 Codex 让 DeepSeek 去搜索、打开网页时,按次数计费,每 1000 次 0.75 美元。
    • 通知:新增按种类开关通知的功能,余额不足提醒默认开着。验证码、重置密码、绑定邮箱,看 SMTP 有没有配好。余额低于你设的数时提醒一次,充回去之后,下次再低才会再提醒。
    • 渠道:新增拖动调整渠道优先级的功能,在渠道列表打开「拖拽模式」。新增 New API 渠道查询上游余额的功能,也可以绑定海螺、Vidu 和 Veo。新增令牌「允许查询用户额度」,新建的默认开着,以前建的还是关的。
    • 限流和计费:修复分组限流算到一起的问题,某个分组自己设了限流,就按这个分组的次数算。修复 Vidu 收费和实际生成对不上的问题,按它实际生成的模型、时长和分辨率计费。修复 Claude 流式把上游报的 0 丢掉的问题,报了 0 就按 0 算。提示词全在缓存里时,按读缓存的价格计费。
    • 报错:修复请求内容读失败时看不出原因的问题。上游报错里,你填的地址、IP 和密钥会被藏起来,文档链接和邮箱还看得到。
    • 其他:新增 Sub2API 查询余额的功能。新增 AWS 的 Mantle(Messages API),已经在用的还是 InvokeModel。新增 Vertex 用 API Key 时填写项目 ID 的功能。任务插件这一版更快。
    • 修复:修复 Vertex 的 us、eu 访问地址错误的问题。修复容器里过载保护看错 CPU 和内存的问题,看的是容器自己的,连续大约 15 秒都过高才会拒绝请求。

    English

    • DeepSeek: Added deepseek-flash and deepseek-v4-pro. You can add -none, -low, or -max, and @thinking and @effort work too. Added Search and Fetch at /v1/tools/search and /v1/tools/fetch. When Claude Code or Codex has DeepSeek search or open a page, that is charged per request, $0.75 per 1,000.
    • Notifications: Added a switch for each kind of notification. The low balance reminder starts on. Verification codes, password resets, and email binding go out when SMTP is set up. You get one reminder when the balance goes below the number you set, and another the next time it does, after a top-up.
    • Channels: Added dragging to change channel priority. Turn on Drag mode in the channel list. Added upstream balance checks for New API channels, which can also bind Hailuo, Vidu, and Veo. Added Allow querying user quota on tokens. New tokens start with it on. Older tokens stay off.
    • Rate limits and billing: Fixed group rate limits being counted together. A group with its own limit is counted on its own. Fixed Vidu charges that did not match the video it generated. The charge uses the model, duration, and resolution it actually made. Fixed Claude streams dropping a 0 from the upstream. A reported 0 stays 0. When the whole prompt is cached, the charge is the cache-read price.
    • Errors: Fixed request failures that hid the real reason the body could not be read. If it is too large, the response is 413. In an upstream error, the address, IP, and key you entered are hidden. Documentation links and email addresses stay visible.
    • Also: Added balance checks for Sub2API channels. Added Mantle (Messages API) for AWS channels. Ones already in use stay on InvokeModel. Added a project ID field for Vertex API Key mode. Task plugins are faster in this release.
    • Fixes: Fixed wrong Vertex addresses for the us and eu regions. Fixed overload protection in containers reading the wrong CPU and memory. It uses the container's own, and turns requests away only after they stay too high for about 15 seconds.

    What's Changed

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    new-api

    New API

    An AI gateway for models, applications, and agents


    📝 Project Description

    New API is a self-hosted AI gateway for applications, agents, and teams. Connect upstream model services, expose a consistent API to your clients, and manage routing, access, usage, and costs in one place.

    Use it to share authorized model access across a team, switch providers without configuring every client again, or operate a private multi-model service with a web console. Upstreams include OpenAI, Anthropic, Google Gemini, Azure OpenAI, AWS Bedrock, Vertex AI, DeepSeek, Qwen, and other compatible services.

    [!IMPORTANT]

    • This project is intended solely for lawful and authorized AI API gateway, organization-level authentication, multi-model management, usage analytics, cost accounting, and private deployment scenarios.
    • Users must lawfully obtain upstream API keys, accounts, model services, and interface permissions, and must comply with upstream terms of service and applicable laws and regulations.
    • Users should ensure their use complies with upstream terms of service and applicable laws and regulations.
    • When providing generative AI services to the public, users should comply with applicable regulatory requirements and fulfill all filing, licensing, content safety, real-name verification, log retention, tax, and upstream authorization obligations required by their jurisdiction.

    [!WARNING] When operating this project as a public generative AI service or API resale service, users should first complete all required filing, licensing, content safety, real-name verification, log retention, tax, payment, and upstream authorization obligations.


    Screenshots

    Accounts, channels, plugin installation states, usage, prices, and costs shown below are simulated data. The marketplace displays the official plugin catalog. Click an image to view it at full size.

    Usage dashboardPlugin marketplace
    Usage dashboard with simulated requests, costs, and performance metricsOfficial plugin marketplace with simulated installation status
    Model squareUsage logs
    Model square with simulated model pricing and availabilityUsage logs with simulated tokens, costs, and response times

    🤝 Trusted Partners


    🙏 Special Thanks


    Capabilities

    AreaWhat you can do
    Model accessUse OpenAI Chat Completions, Responses, Anthropic Messages, and Gemini APIs; stream responses and use tools, reasoning, and multimodal inputs where supported
    RoutingConfigure model mappings, channel priorities and weights, retries, channel affinity, and multiple upstream keys
    Usage and costsManage quotas, subscriptions, usage logs, cache accounting, and expression-based pricing for different usage tiers
    Access controlManage users, groups, fine-grained permissions, and API key restrictions; use OAuth/OIDC, passkeys, two-factor authentication, and login session management
    Asynchronous tasksExtend image, video, and other task APIs with JavaScript plugins, including task status and output retrieval
    Web consoleConfigure channels and models, inspect usage and audit logs, and try models in the playground; available in English, Simplified Chinese, Traditional Chinese, French, Japanese, Russian, and Vietnamese

    Protocols and endpoints

    InterfaceCommon endpoints
    OpenAI Chat / ResponsesPOST /v1/chat/completions, POST /v1/responses
    Anthropic MessagesPOST /v1/messages
    GeminiPOST /v1beta/models/{model}:generateContent, POST /v1beta/models/{model}:streamGenerateContent
    Realtime / Responses WebSocketGET /v1/realtime, GET /v1/responses (WebSocket upgrade)
    Images / audio/v1/images/generations, /v1/images/edits, /v1/audio/speech, /v1/audio/transcriptions, /v1/audio/translations
    Embeddings / rerankPOST /v1/embeddings, POST /v1/rerank
    Task pluginsPOST /v1/tasks/{pluginKey}, GET /v1/tasks/{taskId}, plus routes declared by each plugin

    RelayKit provides request, response, and streaming conversion between the four text protocols. Available features depend on the channel, upstream model, and conversion path; protocol-specific tools and fields may not map exactly. WebSocket support also requires a compatible upstream and channel configuration.

    This README describes the current source tree. Check the release notes for the version you deploy.

    Quick start

    Try locally with Docker

    This starts a single instance with SQLite and binds it to localhost:

    mkdir -p data
    docker run --name new-api -d --restart unless-stopped \
      -p 127.0.0.1:3000:3000 \
      -e TZ=Asia/Shanghai \
      -v "$(pwd)/data:/data" \
      calciumion/new-api:latest
    

    Open http://localhost:3000 and complete the setup wizard to create the administrator account. The data directory persists the SQLite database across container replacements.

    Make your first request

    1. Add a channel with your upstream API key, available models, and group assignment; run a channel test.
    2. Configure model pricing and ensure the user has quota or a valid subscription.
    3. Create an API key in the console with access to the same group and models.
    4. Set your client's base URL to http://localhost:3000/v1 for OpenAI-compatible clients and use the New API-issued key.

    Set NEW_API_KEY in your shell to that key. List the models accessible to it:

    curl --fail-with-body http://localhost:3000/v1/models \
      -H "Authorization: Bearer ${NEW_API_KEY}"
    

    Then call Responses, replacing your-enabled-model with an enabled model that supports this interface:

    curl --fail-with-body http://localhost:3000/v1/responses \
      -H "Authorization: Bearer ${NEW_API_KEY}" \
      -H "Content-Type: application/json" \
      -d '{"model":"your-enabled-model","input":"Hello!"}'
    

    Deployment

    Docker Compose

    The repository's Compose configuration starts New API + PostgreSQL + Redis by default. It also contains examples for MySQL and a separate ClickHouse log database.

    git clone https://github.com/QuantumNous/new-api.git
    cd new-api
    

    Before starting, edit docker-compose.yml: replace the database and Redis example passwords in both the services and connection strings, and set a persistent random SESSION_SECRET (generate one with openssl rand -hex 32). For an HTTPS console, configure SESSION_COOKIE_SECURE=true and SESSION_COOKIE_TRUSTED_URL with its exact public HTTPS origin.

    docker compose up -d
    docker compose logs -f new-api
    

    Storage and configuration

    ComponentOptions
    Main databaseSQLite, MySQL ≥ 5.7.8, or PostgreSQL ≥ 9.6
    Separate log databaseConfigure with LOG_SQL_DSN; also supports ClickHouse
    CacheOptional Redis plus in-memory caching; use shared Redis when application nodes need shared rate limits
    Container platformsLinux amd64 / arm64
    VariablePurpose
    SQL_DSNMain database connection; unset uses SQLite
    LOG_SQL_DSNOptional separate log database connection
    REDIS_CONN_STRINGRedis connection string
    SESSION_SECRETPersistent authentication secret; all nodes must use the same value
    CRYPTO_SECRETDefaults to SESSION_SECRET; nodes sharing Redis must use the same effective value
    SESSION_COOKIE_SECURESet to true for an HTTPS console; enables Secure refresh cookies and strict refresh/logout origin checks
    SESSION_COOKIE_TRUSTED_URLRequired in Secure mode: comma-separated exact HTTPS origins, without paths or wildcards; leave unset for local HTTP
    TRUSTED_PROXIESTrusted reverse-proxy IPs/CIDRs, or none; explicitly configure for your network

    See the environment example, environment reference, and authentication and session guide for full configuration. Configure container variables in Compose's environment or env_file; copying .env.example alone does not inject variables into the container.

    For production, put the console behind HTTPS and configure your reverse proxy for streaming and WebSocket upgrades. Persist and back up the database and mounted data. Multi-node deployments must share the main database and authentication secrets; separate Redis instances or in-memory rate limiters count limits independently per node. The session guide describes propagation behavior for each topology.

    Pin an image version from Releases, review its upgrade notes, and back up before upgrading. The latest tag follows published builds and can change; migrations and compatibility must be assessed for your existing installation.

    Development and extensions

    The backend uses Go and Gin. The web console uses React 19, TypeScript, Rsbuild, TanStack, and Tailwind CSS 4. Use Bun for frontend dependencies and scripts; see go.mod for the Go language baseline and Dockerfile for the container build toolchain.

    Build the frontend before starting the backend, which embeds web/dist:

    # Repository root
    cd web
    bun install --frozen-lockfile
    bun run build
    cd ..
    go run .
    

    In a second terminal, start the frontend development server:

    cd web
    bun run dev -- --port 5173
    

    Open http://localhost:5173; the development server proxies API requests to the backend on port 3000. For a containerized development backend, see docker-compose.dev.yml and the make dev target in makefile.

    LocationResponsibility
    router/, middleware/, controller/HTTP routes, access checks, and API handlers
    relay/Upstream adapters and request routing
    service/, model/Business logic and persistence
    relaykit/Independently buildable Go module for protocol DTOs and conversions
    plugins/tasks/JavaScript task plugins; see Task Plugin API v1 for authoring and host boundaries
    web/Web console; see frontend conventions
    electron/Desktop wrapper and packaging

    Read AGENTS.md before contributing. Run checks appropriate to your change, including make test for the Go modules and bun check -b, bun run lint, bun run test, and bun run build in web/ for frontend changes. Changes to RelayKit must also pass GOWORK=off go build ./... from relaykit/.

    Documentation and community

    ResourceLink
    Official documentationGuides · Installation · API reference
    Project explorationDeepWiki
    Questions and discussionFAQ · Community
    Bugs and feature requestsGitHub Issues
    Security reportsFollow the security policy for private reporting

    For bug reports, include the version, deployment method, reproduction steps, and redacted logs. Documentation, translations, provider integrations, and focused regression tests are all welcome contributions.


    🔗 Related Projects

    Upstream Projects

    ProjectDescription
    One APIOriginal project base
    Midjourney-ProxyMidjourney interface support

    Supporting Tools

    ProjectDescription
    new-api-key-toolKey quota query tool
    new-api-horizonNew API high-performance optimized version

    📜 License

    This project is licensed under the GNU Affero General Public License v3.0 (AGPLv3).

    Additional terms under AGPLv3 Section 7 apply. Modified versions must preserve the author attribution notice Frontend design and development by New API contributors. in the appropriate legal notices and in any prominent about, legal, footer, or attribution location presented by the user interface.

    Modified versions that present a user interface must also preserve a visible link to the original project: https://github.com/QuantumNous/new-api.

    This is an open-source project developed based on One API (MIT License).

    If your organization's policies do not permit the use of AGPLv3-licensed software, or if you wish to avoid the open-source obligations of AGPLv3, please contact us at: [email protected]

    See NOTICE and third-party licenses for attribution and dependency notices.


    🌟 Star History

    Star History Chart


    💖 Thank you for using New API

    If this project is helpful to you, welcome to give us a ⭐️ Star!

    Official Documentation • Issue Feedback • Latest Release

    Built with ❤️ by QuantumNous