各中转站对 RPM 有限制,同时禁止分发,本教程只给出自用模式

看到群里不少佬友想在 newapi 中对接中转站,恰好我在用 RightCode,所以以 rightcode 为例,写(水)一篇教程吧。

前者要求

  • git (用于克隆仓库)
  • windows docker desktop 或者 linux docker (建议有足够的内存 + 硬盘存储)
  • 配置好 docker compose

windows docker desktop 建议选择 wsl2 作为 backend

安装部署

克隆仓库 & 启动

先克隆仓库

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

修改 docker-compose.yml

本教程采用 postgresql

```diff
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" +     - "3003: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=postgresql://root:idkpassword@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
      - REDIS_CONN_STRING=redis://redis
      - TZ=Asia/Shanghai
      - ERROR_LOG_ENABLED=true # 是否启用错误日志记录 (Whether to enable error log recording)
      - BATCH_UPDATE_ENABLED=true  # 是否启用批量更新 (Whether to enable batch update)

    depends_on:
      - redis
      - postgres
    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

  postgres:
    image: postgres:15
    container_name: postgres
    restart: always
    environment:
      POSTGRES_USER: root
-     POSTGRES_PASSWORD: 123456  # ⚠️ IMPORTANT: Change this password in production! +     POSTGRES_PASSWORD: idkpassword  # ⚠️ IMPORTANT: Change this password in production!
      POSTGRES_DB: new-api
    volumes:
      - pg_data:/var/lib/postgresql/data

volumes:
  pg_data:
#  mysql_data:

编辑完保存,继续执行命令

docker compose up -d

等待 n 秒(取决于你的网速~)

出现以下字样,拉去镜像和启动成功

[+] Running 5/5
 ✔ Network new-api_default   Created                                                                                                                   0.1s
 ✔ Volume "new-api_pg_data"  Created                                                                                                                   0.0s
 ✔ Container redis           Started                                                                                                                   0.7s
 ✔ Container postgres        Started                                                                                                                   0.7s
 ✔ Container new-api         Started                                                                                                                   1.0s

NewAPI 配置

打开浏览器,输入 http://localhost:3003/ 后,会出现配置页

如果你的数据库检查没有错误,继续下一步,填写管理员账号和密码

下一步,选择使用模式

最后 初始化系统 即可

配置渠道

打开 控制台

依次点击 渠道管理 添加渠道,并填入 类型 / 名称 / 密钥

填入 API 地址为 https://www.right.codes/codex

因为 rightcode 支持了模型列表接口,点获取模型列表即可获取可用的模型

随后确定,并提交即可

模型管理

按照图中的内容,切换刀模型管理,依次点击 同步 → 下一步 → 确定

配合 CC Switch 使用

现在 控制台 -> 令牌管理 生成令牌,并填入刀 cc switch 中

最终的 config.toml

model_provider = "custom" model = "gpt-5.2" model_reasoning_effort = "xhigh" disable_response_storage = true [model_providers.custom] name = "custom" wire_api = "responses" requires_openai_auth = false base_url = "http://localhost:3003/v1" 

保存好以后,切换供应商,可以开始 coding 了


📌 转载信息
原作者:
unsafe
转载时间:
2026/1/15 18:30:28

标签: docker, PostgreSQL, Docker Compose, newapi, API中转

添加新评论