Files

251 lines
12 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<div align="center">
![new-api](/web/public/logo.png)
# New API 高级定制版
> 🍰 基于 [QuantumNous/new-api](https://github.com/QuantumNous/new-api) `v1.0.0-rc.36` 的深度定制 Fork
> **线上实例:<https://ai.88531.cn>** — 注册送体验金,每日签到再领额度
</div>
---
## 🎨 定制功能一览
本页只介绍相对官方版本的修改内容,官方能力请见 [官方文档](https://docs.newapi.pro) 与上游仓库。
### 💰 计费与钱包
| 功能 | 说明 |
| ---- | ---- |
| **人民币原生计费** | 额度与账单全部按人民币展示,充值多少人民币到账等额额度,钱包环节不再做汇率换算;易支付、Waffo 等全部充值渠道适配(`controller/topup.go`、`model/topup.go`) |
| **充值优惠「充 1 元到账 2 元」** | 统一赠送比例 `payment_setting.amount_bonus = 1.0`,充多少送多少(100% 赠送、上不封顶);到账额度在 `topupQuotaFromAmount` / `getTopUpQuota` 统一乘以 `(1 + bonus)`,覆盖易支付 / Waffo / Pancake / 管理员补单全部到账路径;关闭只需把配置改回 `0` |
| **充值页优惠展示** | 充值页顶部优惠横幅、每个金额档显示「到账 ¥x」与「已省 ¥x」、自定义金额的到账预估、支付确认弹窗新增「到账金额」行 |
| **每日签到** | 新增 `checkin_setting`(签到送额度)与认证/游客头部 `CheckinButton` 组件(支持 Turnstile),匿名访客引导注册,每日签到可领额度 |
| **订阅/包月套餐 `/subscribe`** | 公开套餐页(未登录读 `plans.json` 快照、登录后走系统 API),支持支付宝购买、余额支付、免费领取;购买自动升级分组、周期性额度重置、到期自动降级 |
### 🧩 模型广场与价格
| 功能 | 说明 |
| ---- | ---- |
| **「免费」定价筛选** | 模型广场「定价类型」筛选新增免费类型,一键筛出当前 0 价格的免费模型,免费模型在卡片上显示绿色标签 |
| **「今日免费模型」闪光横幅** | 广场最顶部常驻横幅,自动列出当天免费模型名单与数量,标题为蓝色流光渐变 + 光晕动画,点击「查看全部免费模型」直达免费筛选 |
| **官方价格每日自动同步** | 每天凌晨自动抓取 OpenCode Go 官方价格表(models.dev 镜像数据源),限免恢复收费、价格涨跌与缓存价调整全部自动生效,无需人工改库(`scripts/sync-zen-prices.py`) |
| **模型云与供应商管理** | 新增模型元数据目录(vendors / models 表)、模型广场上下架策略、上游模型巡检与自动同步 |
### 🛠️ 前端体验
| 功能 | 说明 |
| ---- | ---- |
| **中文优先 i18n** | 站点语言默认中文、不再跟随浏览器语言(保留手动切换;旧语言缓存通过新存储键重置);充值等关键页面文案直接以中文输出 |
| **使用文档 `/docs`** | 全新 12 节新手图文指南(介绍、快速开始、签到、充值、分组、密钥、价格、Playground、第三方客户端、API 示例、FAQ),带吸顶锚点导航 |
| **首页霓虹促销横幅** | 渐变发光 `PromoBanner`,链接到文档页 |
| **i18n 全语种同步** | 新增文案同步至 en / zh / zh-TW / fr / ja / ru / vi 七种语言 |
---
## 🗒️ 更新日志
**2026-09-30 · 蓝·大·今天免费(RC45)**
1. 模型广场新增「免费」定价筛选类型(含实时计数),免费模型统一绿色标签
2. 广场顶部新增「今日免费模型」横幅:名单 + 数量徽章 + 蓝色流光闪光标题,一键查看全部免费模型
3. i18n 七语种新增对应文案
4. 部署镜像更新至 `new-api-custom:rc45`(内嵌新前端与同版本 Go 网关)
**2026-09-24 · 充值优惠(RC42)**
1. 后端统一赠送比例 `payment_setting.amount_bonus`,全部到账路径生效并附回归测试
2. 钱包页优惠横幅、到账金额展示、支付确认弹窗到账行
3. 文档页与关于页新增优惠说明
---
## 🚀 部署
### 方式一:Docker 运行(最小启动)
```bash
docker network create new-api-network
docker run -d --name redis --network new-api-network \
redis:latest redis-server --requirepass 123456
docker run -d --name postgres --network new-api-network \
-e POSTGRES_USER=root -e POSTGRES_PASSWORD=123456 -e POSTGRES_DB=new-api \
-v new_api_pg_data:/var/lib/postgresql/data \
postgres:15
docker run -d --name new-api --network new-api-network -p 3000:3000 \
-e SQL_DSN='postgresql://root:123456@postgres:5432/new-api' \
-e REDIS_CONN_STRING='redis://:123456@redis:6379' \
-e TZ=Asia/Shanghai \
-e ERROR_LOG_ENABLED=true \
-v "$PWD/data:/data" -v "$PWD/logs:/app/logs" \
calciumion/new-api:latest --log-dir /app/logs
```
> 默认口令仅为本地体验用,生产环境务必改成随机强口令。
### 方式二:Docker Compose部署
仓库根目录 `docker-compose.yml` 完整内容(与仓库文件一致,含全部 ports / volumes / environment):
```yaml
# New-API Docker Compose Configuration
#
# Quick Start:
# 1. docker-compose up -d
# 2. Access at http://localhost:3000
#
# Using MySQL instead of PostgreSQL:
# 1. Comment out the postgres service and SQL_DSN line 15
# 2. Uncomment the mysql service and SQL_DSN line 16
# 3. Uncomment mysql in depends_on (line 28)
# 4. Uncomment mysql_data in volumes section (line 64)
#
# ⚠️ IMPORTANT: Change all default passwords before deploying to production!
version: '3.4' # For compatibility with older Docker versions
services:
new-api:
image: calciumion/new-api:latest
container_name: new-api
restart: always
command: --log-dir /app/logs
ports:
- "3000:3000"
volumes:
- ./data:/data
- ./logs:/app/logs
environment:
- SQL_DSN=postgresql://root:123456@postgres:5432/new-api # ⚠️ IMPORTANT: Change the password in production!
# - SQL_DSN=root:123456@tcp(mysql:3306)/new-api # Point to the mysql service, uncomment if using MySQL
# - LOG_SQL_DSN=postgresql://root:123456@postgres:5432/new-api-log # OPTIONAL: If you want a separate database for logging, uncomment and set this
# - LOG_SQL_DSN=clickhouse://default:123456@clickhouse:9000/new_api_logs # OPTIONAL: Use ClickHouse for logs only; also uncomment clickhouse in depends_on and the clickhouse service below
# - LOG_SQL_CLICKHOUSE_TTL_DAYS=0 # OPTIONAL: ClickHouse log retention days. Unset or 0 disables automatic deletion; set to e.g. 30 to keep 30 days
- REDIS_CONN_STRING=redis://:123456@redis:6379 # ⚠️ IMPORTANT: Change the password in production!
- TZ=Asia/Shanghai
- ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
- BATCH_UPDATE_ENABLED=true # 是否启用批量更新 (Whether to enable batch update)
- NODE_NAME=new-api-node-1 # 节点名称,用于审计日志中标识节点身份;多节点/容器部署时建议设置 (Node name used in audit logs; recommended when running multiple instances or in containers)
# - STREAMING_TIMEOUT=300 # 流模式无响应超时时间,单位秒,默认120秒,如果出现空补全可以尝试改为更大值 (Streaming timeout in seconds, default is 120s. Increase if experiencing empty completions)
# - RELAY_IDLE_CONN_TIMEOUT=90 # Relay HTTP 客户端空闲连接超时时间,单位秒,默认跟随 Go 标准库,设置为0表示不限制 (Relay HTTP client idle keep-alive timeout in seconds, defaults to Go standard library; set 0 to disable)
# - SESSION_SECRET=random_string # 多机部署时设置,必须修改这个随机字符串!! (multi-node deployment, set this to a random string!!!!!!!)
# - SESSION_COOKIE_SECURE=true # true:启用 Secure Refresh Cookie 和严格 refresh/logout OriginGuard;false/未配置:关闭 OriginGuard,仅用于本地 HTTP (true: Secure cookie + strict refresh/logout OriginGuard; false/unset: guard disabled for local HTTP only)
# - SESSION_COOKIE_TRUSTED_URL=https://example.com,https://admin.example.com # Secure=true 时必填的精确 HTTPS Origin;不是 relay CORS 白名单,不支持通配符/路径 (Required exact HTTPS origins when Secure=true; not a relay CORS allowlist, no wildcard/path)
# - TRUSTED_PROXIES=172.20.0.0/16 # 未配置时信任回环/RFC1918/fc00::/7 并告警,none 为严格模式,显式列表替代默认值 (Unset trusts loopback/RFC 1918/fc00::/7 with a warning; none trusts no proxies; an explicit list replaces defaults)
# - USER_SESSION_ACTIVE_LIMIT=50
# - USER_SESSION_ISSUANCE_LIMIT=100
# - USER_SESSION_ISSUANCE_WINDOW_SECONDS=86400 # 不得大于 revoked 保留期 (must not exceed revoked retention)
# - USER_SESSION_REVOKED_RETENTION_DAYS=7
# - USER_SESSION_HOURLY_ALERT_THRESHOLD=5000 # 仅告警,不做全局拒绝 (alert only; never globally rejects login)
# - SYNC_FREQUENCY=60 # Uncomment if regular database syncing is needed
# - GOOGLE_ANALYTICS_ID=G-XXXXXXXXXX # Google Analytics 的测量 ID (Google Analytics Measurement ID)
# - UMAMI_WEBSITE_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx # Umami 网站 ID (Umami Website ID)
# - UMAMI_SCRIPT_URL=https://analytics.umami.is/script.js # Umami 脚本 URL,默认为官方地址 (Umami Script URL, defaults to official URL)
depends_on:
- redis
- postgres
# - mysql # Uncomment if using MySQL
# - clickhouse # Uncomment if using ClickHouse for LOG_SQL_DSN
networks:
- new-api-network
healthcheck:
test: ["CMD-SHELL", "wget -q -O - http://localhost:3000/api/status | grep -o '\"success\":\\s*true' || exit 1"]
interval: 30s
timeout: 10s
retries: 3
redis:
image: redis:latest
container_name: redis
restart: always
command: ["redis-server", "--requirepass", "123456"] # ⚠️ IMPORTANT: Change this password in production!
networks:
- new-api-network
postgres:
image: postgres:15
container_name: postgres
restart: always
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
POSTGRES_DB: new-api
volumes:
- pg_data:/var/lib/postgresql/data
networks:
- new-api-network
# ports:
# - "5432:5432" # Uncomment if you need to access PostgreSQL from outside Docker
# mysql:
# image: mysql:8.2
# container_name: mysql
# restart: always
# environment:
# MYSQL_ROOT_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
# MYSQL_DATABASE: new-api
# volumes:
# - mysql_data:/var/lib/mysql
# networks:
# - new-api-network
# ports:
# - "3306:3306" # Uncomment if you need to access MySQL from outside Docker
# clickhouse:
# image: clickhouse/clickhouse-server:24.8
# container_name: clickhouse
# restart: always
# environment:
# CLICKHOUSE_DB: new_api_logs
# CLICKHOUSE_USER: default
# CLICKHOUSE_PASSWORD: 123456 # ⚠️ IMPORTANT: Change this password in production!
# CLICKHOUSE_DEFAULT_ACCESS_MANAGEMENT: 1
# volumes:
# - clickhouse_data:/var/lib/clickhouse
# networks:
# - new-api-network
# ports:
# - "8123:8123" # HTTP interface, uncomment if you need external access
# - "9000:9000" # Native interface used by the LOG_SQL_DSN example above
volumes:
pg_data:
# mysql_data:
# clickhouse_data:
networks:
new-api-network:
driver: bridge
```
启动 / 停止:
```bash
docker compose up -d
# 访问
# http://localhost:3000
docker compose ps
docker compose down
```
## 📝 使用声明
> [!IMPORTANT]
> - 本项目仅用于合法且经授权的 AI API 网关、组织级鉴权、多模型管理、用量统计、成本核算与私有化部署场景。
> - 用户须依法取得上游 API Key、账号、模型服务及接口权限,并遵守上游服务条款与所在地区法律法规。
> - 向公众提供生成式 AI 服务时,应遵守相应监管要求并履行备案、许可、内容安全、实名认证、日志留存、税务及上游授权等义务。
## 📄 许可证与致谢
本项目基于上游 [QuantumNous/new-api](https://github.com/QuantumNous/new-api) 的 [Apache 2.0 修订许可](./LICENSE)(附加商用限制条款)修改,所有修改同样遵循该许可证;上游项目的商标与版权归属原作者。本仓库为自用定制版,不对外提供任何形式的官方支持。
官方文档 / 问答:`docs.newapi.pro` · 上游 issues:`github.com/QuantumNous/new-api/issues`