MCPcopy Index your code
hub / github.com/GakkiNoOne/oai-rt

github.com/GakkiNoOne/oai-rt @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
238 symbols 610 edges 36 files 145 documented · 61%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

OAI RT 管理系统

一个用于管理和自动刷新 OpenAI Refresh Token 的系统。

<img width="5100" height="2410" alt="Image" src="https://github.com/GakkiNoOne/oai-rt/raw/main/resource/screenshot.png" />

快速部署

1. 准备配置文件

在项目目录创建 config 目录和 config.yml 配置文件:

mkdir -p config data

config/config.yml 配置示例:

server:
  host: "0.0.0.0"
  port: 8080
  mode: "release"  # debug, release, test

database:
  # SQLite 配置(默认)
  type: "sqlite"
  database: "./data/tokens.db"

  # MySQL 配置(如需使用请取消注释并注释掉 SQLite 配置)
  # type: "mysql"
  # host: "localhost"
  # port: 3306
  # user: "root"
  # password: "your_mysql_password"
  # database: "rt_manage"

  # 通用配置
  table_prefix: ""
  max_idle_conns: 10
  max_open_conns: 100
  conn_max_lifetime: 3600

auth:
  username: "admin"  # 管理后台登录用户名
  password: "admin123"  # 管理后台登录密码
  jwt_secret: "your-secret-key-change-this-in-production"  # JWT 签名密钥(生产环境必须修改)
  jwt_expire_hours: 240  # JWT 过期时间(小时)
  api_secret: "my-api-secret-2025"  # 对外 API 密钥
  public_api_prefix: "/public-api"  # 对外 API 路由前缀(可选,默认 /public-api)

2. 使用 Docker Compose 启动

创建 docker-compose.yml 文件:

services:
  rt-manage:
    image: ghcr.io/gakkinoone/oai-rt:latest
    container_name: rt-manage
    restart: unless-stopped
    ports:
      - "8080:8080"
    volumes:
      - ./data:/app/data
      - ./config:/app/config  # 配置文件目录,需将 config.yml 放在 ./config/ 目录下
    environment:
      - TZ=Asia/Shanghai

启动服务:

docker-compose up -d

查看日志:

docker-compose logs -f

配置说明

服务器配置

配置项 类型 默认值 说明
server.host string 0.0.0.0 服务监听地址
server.port int 8080 服务监听端口
server.mode string debug 运行模式:debug / release / test

数据库配置

配置项 类型 默认值 说明
database.type string sqlite 数据库类型:sqlitemysql
database.database string ./data/tokens.db SQLite 数据库文件路径(type=sqlite 时使用)
database.host string localhost MySQL 主机地址(type=mysql 时使用)
database.port int 3306 MySQL 端口(type=mysql 时使用)
database.user string root MySQL 用户名(type=mysql 时使用)
database.password string - MySQL 密码(type=mysql 时使用)
database.table_prefix string - 表名前缀(可选)
database.max_idle_conns int 10 最大空闲连接数
database.max_open_conns int 100 最大打开连接数
database.conn_max_lifetime int 3600 连接最大生命周期(秒)

认证配置

配置项 类型 默认值 说明
auth.username string admin 管理后台登录用户名
auth.password string admin123 管理后台登录密码
auth.jwt_secret string - JWT 签名密钥,生产环境必须修改, 可以使用https://jwtsecrets.com/去生成
auth.jwt_expire_hours int 240 JWT 过期时间(小时)
auth.api_secret string - 对外 API 密钥,用于 API 接口鉴权
auth.public_api_prefix string /public-api 对外 API 路由前缀,可自定义(如 /external/v1

访问地址

  • 管理后台:http://localhost:8080
  • 健康检查:http://localhost:8080/health
  • API 文档:管理后台登录后可查看

对外 API 使用

所有对外 API 接口需要在 HTTP Header 中添加 API Secret:X-API-Secret

路由前缀说明: - 默认路由前缀为 /public-api - 可在配置文件 config.yml 中通过 auth.public_api_prefix 自定义路由前缀 - 以下示例使用默认前缀 /public-api,实际使用时请替换为您配置的前缀

1. 刷新 RT 并获取 AT

支持使用 biz_idemail 查询:

# 使用 biz_id 查询
curl -X POST http://localhost:8080/public-api/refresh \
  -H "Content-Type: application/json" \
  -H "X-API-Secret: my-api-secret-2025" \
  -d '{
    "biz_id": "user001"
  }'

# 使用 email 查询
curl -X POST http://localhost:8080/public-api/refresh \
  -H "Content-Type: application/json" \
  -H "X-API-Secret: my-api-secret-2025" \
  -d '{
    "email": "user@example.com"
  }'

2. 获取 AT(不刷新)

支持使用 biz_idemail 查询:

# 使用 biz_id 查询
curl -X POST http://localhost:8080/public-api/get-at \
  -H "Content-Type: application/json" \
  -H "X-API-Secret: my-api-secret-2025" \
  -d '{
    "biz_id": "user001"
  }'

# 使用 email 查询
curl -X POST http://localhost:8080/public-api/get-at \
  -H "Content-Type: application/json" \
  -H "X-API-Secret: my-api-secret-2025" \
  -d '{
    "email": "user@example.com"
  }'

3. 健康检查

curl -X GET http://localhost:8080/public-api/health \
  -H "X-API-Secret: my-api-secret-2025"

注意:代理、自动刷新等 OpenAI 相关配置可在 Web 管理界面的"配置管理"页面进行设置。

数据库表结构

完整的表结构 SQL 文件:resource/table.sql

License

MIT

Extension points exported contracts — how you extend this code

RTServiceInterface (Interface)
RTServiceInterface 定义RT服务接口,避免循环导入 [1 implementers]
internal/scheduler/manager.go
RTService (Interface)
RTService RT 服务接口 [1 implementers]
internal/service/rt_service.go
RTRepository (Interface)
RTRepository RT 数据仓库接口 [1 implementers]
internal/repository/rt_repository.go
RTFormModalProps (Interface)
(no doc)
frontend/src/pages/RTs/components/RTFormModal.tsx
ConfigService (Interface)
ConfigService 配置服务接口 [1 implementers]
internal/service/config_service.go
ConfigRepository (Interface)
ConfigRepository 配置数据仓库接口 [1 implementers]
internal/repository/config_repository.go
BatchImportModalProps (Interface)
(no doc)
frontend/src/pages/RTs/components/BatchImportModal.tsx
SearchFormProps (Interface)
(no doc)
frontend/src/pages/RTs/components/SearchForm.tsx

Core symbols most depended-on inside this repo

Info
called by 85
pkg/logger/logger.go
Error
called by 56
pkg/logger/logger.go
Set
called by 32
internal/repository/config_repository.go
Warn
called by 16
pkg/logger/logger.go
loadData
called by 12
frontend/src/pages/RTs/index.tsx
Update
called by 10
internal/service/rt_service.go
Get
called by 10
internal/config/config.go
GetByBizId
called by 7
internal/service/rt_service.go

Shape

Method 103
Function 91
Struct 26
Interface 18

Languages

Go76%
TypeScript24%

Modules by API surface

internal/service/rt_service.go41 symbols
frontend/src/pages/RTs/index.tsx25 symbols
internal/repository/rt_repository.go23 symbols
internal/service/config_service.go20 symbols
internal/api/handler/rt.go13 symbols
internal/scheduler/manager.go11 symbols
internal/repository/config_repository.go11 symbols
pkg/logger/logger.go8 symbols
internal/config/config.go8 symbols
internal/model/rt.go7 symbols
frontend/src/api/rts.ts7 symbols
internal/api/handler/config.go6 symbols

For agents

$ claude mcp add oai-rt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact