longbenx/codex-relay

Manage multiple GPT accounts with quota monitoring, Work check-ins, session refresh, GUI, and CLI.

★ 0Forks 0PythonGitHub ↗Compare

README

Codex Relay

Codex Relay 是一个本地多 GPT / Codex 账号管理、额度查看与会话维护工具,提供图形界面和命令行模式。

核心功能:自动触发额度重置计时
新账号或尚未消耗额度的账号可能一直显示 100%,同时没有重置时间。Codex Relay 检测到这种状态后,可以自动在 Work 中发送一条 hello,触发首次额度重置倒计时。该请求必须走 Work,普通聊天不会用于签到。

它可以在每次检测时按需执行两项相互独立的维护操作:

  • 当 Work 额度剩余 100% 且尚无重置时间时,在 Work 中发送一条 hello,用于触发首次重置计时。
  • 当 session 有效期不足 24 小时时,使用刷新令牌续签 session 到期时间。

English · 简体中文


简体中文

功能

  • 通过多个独立的 auth.json 集中管理多个 GPT / Codex 账号
  • 自动为“剩余 100% 且无重置时间”的账号执行 Work 签到,触发首次重置计时
  • 查看 Codex / ChatGPT 当前额度、已用比例和本地重置时间
  • 显示会话额度、小时额度和每周额度
  • Work 自动签到和 session 自动续签可分别启用
  • 多个 auth.json 路径管理,导入后默认勾选
  • 路径、勾选状态、语言和 GUI 开关自动持久化
  • GUI 与 CLI 两种使用方式
  • 支持脱敏 JSON 输出,不输出 access token、refresh token 等凭据
  • 自动检测系统语言;无法识别时使用英语

支持的语言

English、简体中文、繁體中文、日本語、한국어、Español、Français、Deutsch、العربية、Português、Русский、Italiano、हिन्दी、Türkçe、Tiếng Việt、ไทย、Bahasa Indonesia。

额度窗口名称也会随语言切换,包括“当前会话额度”“小时额度”和“每周额度”。

工作原理

Work 自动签到

仅在同时满足以下条件时触发:

  1. 已启用 Work 自动签到;
  2. Codex Work 剩余额度为 100%;
  3. 服务端尚未返回重置倒计时或重置时间。

触发后,Codex Relay 会向 Work 发送一条 hello,然后重新查询额度,确认重置时间已经出现。普通聊天不用于该操作。

Session 自动续签

仅在同时满足以下条件时触发:

  1. 已启用 session 自动续签;
  2. access token 中可以取得有效的到期时间;
  3. 剩余有效期严格少于 24 小时;
  4. auth.json 中存在可用的 refresh token。

续签成功后会原子更新对应的 auth.json。如果新 token 没有延长有效期,原文件不会被替换。

两项功能彼此独立。启用其中一项不会隐式启用另一项。

运行环境

  • Python 3.10 或更高版本
  • GUI 模式需要 Python 包含 Tkinter
  • 无第三方 Python 依赖
  • 需要能够访问 OpenAI / ChatGPT 相关服务

快速开始

下载 Python 版 CodexRelay.py 后运行:

python CodexRelay.py

无参数运行默认打开图形界面。也可以显式指定:

python CodexRelay.py --gui

Windows 用户也可以直接下载 CodexRelay.exe。双击打开 GUI,或在终端中使用与 Python 版相同的参数:

.\CodexRelay.exe --cli

默认读取:

~/.codex/auth.json

也可以在 GUI 中导入一个或多个 auth.json。

CLI 使用

查询默认或已保存且勾选的路径:

python CodexRelay.py --cli

指定一个或多个文件:

python CodexRelay.py --cli --auth "/path/to/auth.json"
python CodexRelay.py --cli --auth "/path/one/auth.json" --auth "/path/two/auth.json"

启用 Work 签到:

python CodexRelay.py --cli --auto-checkin

启用 session 续签:

python CodexRelay.py --cli --auto-refresh-session

同时启用两项维护功能:

python CodexRelay.py --cli --auto-checkin --auto-refresh-session

输出脱敏 JSON:

python CodexRelay.py --json

选择输出语言:

python CodexRelay.py --cli --language zh-CN
python CodexRelay.py --cli --language en
python CodexRelay.py --cli --language es

持久化路径管理

保存传入的路径并默认勾选:

python CodexRelay.py --auth "/path/to/auth.json" --save-paths --cli

查看所有已保存路径:

python CodexRelay.py --list-paths

启用或停用路径:

python CodexRelay.py --enable-path "/path/to/auth.json" --list-paths
python CodexRelay.py --disable-path "/path/to/auth.json" --list-paths

可以使用自定义配置文件:

python CodexRelay.py --config "/path/to/codex-relay.json" --cli

配置文件

默认配置保存在:

~/.codex/codex-relay.json

配置中只保存:

  • 界面语言
  • auth.json 文件路径和勾选状态
  • GUI 中两项维护功能的开关状态

配置文件不会保存 access token 或 refresh token。旧版的 codex-endurance-station.json 可以自动读取。

常用参数

参数 说明
--gui 启动图形界面
--cli 输出文字摘要
--json 输出脱敏 JSON
--auth PATH 添加一个 auth.json,可以重复传入
--language CODE 设置界面或摘要语言
--auto-checkin 启用本次 Work 自动签到
--auto-refresh-session 启用本次 session 自动续签
--save-paths 保存本次传入的路径并默认勾选
--list-paths 列出已保存路径和勾选状态
--enable-path PATH 新增或启用持久化路径
--disable-path PATH 新增或停用持久化路径
--config PATH 使用自定义配置文件
--timeout SECONDS 设置单个请求的超时时间

运行以下命令可查看完整参数:

python CodexRelay.py --help

安全与注意事项

  • auth.json 含有敏感登录凭据,请勿提交到 Git、发送给他人或放入公开日志。
  • Work 签到会发送一条真实的 hello 请求,可能产生少量额度消耗。
  • Session 续签会修改所选的 auth.json,写入过程采用临时文件和原子替换。
  • 自动维护在运行检测时执行;Codex Relay 本身不是后台定时服务。
  • 服务端接口和返回字段可能变化。如果查询失效,请先更新项目版本。
  • 本项目是社区工具,与 OpenAI 无隶属或官方认可关系。请仅用于你有权访问的账户和文件,并遵守适用的服务条款。

English

Codex Relay is a local multi-account manager, quota viewer, and session maintenance utility for GPT / Codex, with both GUI and CLI modes.

Core feature: automatically start the quota reset timer
A new or unused account may remain at 100% with no reset time. When Codex Relay detects this state, it can send hello through Work to start the initial quota reset countdown. This check-in must use Work; a regular chat is not used.

On each check, it can independently perform two optional maintenance actions:

  • Send hello in Work when the Work quota is at 100% remaining and no reset time exists, which starts the initial reset timer.
  • Refresh the session expiry when less than 24 hours remain.

Features

  • Manage multiple GPT / Codex accounts through separate auth.json files
  • Automatically check in through Work at 100% with no reset time, starting the initial reset timer
  • View current Codex / ChatGPT usage, remaining quota, and reset time in local time
  • Display session, hourly, and weekly quota windows
  • Enable Work check-in and session refresh independently
  • Manage multiple auth.json files; newly imported paths are checked by default
  • Persist paths, checked states, language, and GUI options
  • Use either a graphical interface or the command line
  • Produce sanitized JSON without access tokens, refresh tokens, or other credentials
  • Detect the system language automatically and fall back to English when unsupported

Supported languages

English, Simplified Chinese, Traditional Chinese, Japanese, Korean, Spanish, French, German, Arabic, Portuguese, Russian, Italian, Hindi, Turkish, Vietnamese, Thai, and Indonesian.

Quota window names—including current-session, hourly, and weekly quotas—are localized as well.

How it works

Work check-in

The check-in runs only when all of these conditions are met:

  1. Work check-in is enabled;
  2. the Codex Work quota has 100% remaining;
  3. the service has not provided a reset countdown or reset timestamp.

Codex Relay then sends hello specifically through Work and checks the quota again until a reset time appears. A regular chat is not used for this action.

Session refresh

The refresh runs only when all of these conditions are met:

  1. session refresh is enabled;
  2. a valid expiry can be read from the access token;
  3. strictly less than 24 hours remain;
  4. a usable refresh token exists in auth.json.

After a successful refresh, the matching auth.json is updated atomically. If the new token does not extend the expiry, the original file is preserved.

These features are independent. Enabling one never implicitly enables the other.

Requirements

  • Python 3.10 or later
  • A Python build with Tkinter for GUI mode
  • No third-party Python dependencies
  • Network access to the relevant OpenAI / ChatGPT services

Quick start

Download the Python version, CodexRelay.py, then run:

python CodexRelay.py

Running without arguments opens the GUI. You can also request it explicitly:

python CodexRelay.py --gui

Windows users can alternatively download CodexRelay.exe. Double-click it to open the GUI, or use the same CLI options as the Python version:

.\CodexRelay.exe --cli

The default credential path is:

~/.codex/auth.json

You may also import one or more auth.json files in the GUI.

CLI usage

Check the default path, or all saved and enabled paths:

python CodexRelay.py --cli

Specify one or more files:

python CodexRelay.py --cli --auth "/path/to/auth.json"
python CodexRelay.py --cli --auth "/path/one/auth.json" --auth "/path/two/auth.json"

Enable Work check-in:

python CodexRelay.py --cli --auto-checkin

Enable session refresh:

python CodexRelay.py --cli --auto-refresh-session

Enable both maintenance actions:

python CodexRelay.py --cli --auto-checkin --auto-refresh-session

Print sanitized JSON:

python CodexRelay.py --json

Select the output language:

python CodexRelay.py --cli --language en
python CodexRelay.py --cli --language zh-CN
python CodexRelay.py --cli --language es

Persistent path management

Save input paths and enable them by default:

python CodexRelay.py --auth "/path/to/auth.json" --save-paths --cli

List all saved paths:

python CodexRelay.py --list-paths

Enable or disable a path:

python CodexRelay.py --enable-path "/path/to/auth.json" --list-paths
python CodexRelay.py --disable-path "/path/to/auth.json" --list-paths

Use a custom configuration file:

python CodexRelay.py --config "/path/to/codex-relay.json" --cli

Configuration

The default configuration file is:

~/.codex/codex-relay.json

It stores only:

  • the selected language;
  • auth.json paths and their checked states;
  • the two GUI maintenance toggles.

Access tokens and refresh tokens are never copied into this configuration. The legacy codex-endurance-station.json configuration can still be read automatically.

Common options

Option Description
--gui Open the graphical interface
--cli Print a text summary
--json Print sanitized JSON
--auth PATH Add an auth.json path; may be repeated
--language CODE Select the GUI or summary language
--auto-checkin Enable Work check-in for this run
--auto-refresh-session Enable session refresh for this run
--save-paths Persist input paths and enable them by default
--list-paths List saved paths and checked states
--enable-path PATH Add or enable a persistent path
--disable-path PATH Add or disable a persistent path
--config PATH Use a custom configuration file
--timeout SECONDS Set the per-request timeout

Run the following command for the complete option list:

python CodexRelay.py --help

Security and notes

  • auth.json contains sensitive login credentials. Never commit it to Git, share it, or include it in public logs.
  • Work check-in sends a real hello request and may consume a small amount of quota.
  • Session refresh modifies the selected auth.json using a temporary file and atomic replacement.
  • Automatic maintenance runs when a check is performed; Codex Relay is not a background scheduler by itself.
  • Server endpoints and response fields may change. Update the project first if checks stop working.
  • This is a community project and is not affiliated with or endorsed by OpenAI. Use it only with accounts and files you are authorized to access, and follow all applicable terms of service.

Contributors

longbenx

Issues