Skip to main content

Interactive TUI for querying sub2api backend usage stats (Claude / OpenAI / Gemini)

Project description

sub2api-usage

CI PyPI Python License: MIT

sub2api 后台用量查询的命令行工具。终端里直接看请求数、Token、成本、明细,默认展示今天,支持今天 / 7 天 / 30 天 / 全部切换。

安装

# 推荐:uv tool install (隔离环境)
uv tool install sub2api-usage

# 或者用 pipx
pipx install sub2api-usage

# 或者直接 pip
pip install sub2api-usage

用法

# 首次运行会引导填写账号、密码、后台地址、时区,
# 配置保存到 ~/.config/sub2api-usage/config.json (chmod 600)
# 默认打开今天视图
sub2api-usage

# 重新配置账号
sub2api-usage setup

# 非交互打印 (脚本 / 管道用)
# 默认打印今天;用 --period week 可看最近 7 天
sub2api-usage print
sub2api-usage print --period week --list --page-size 20
sub2api-usage print --period month --json

交互面板键位

功能
1 / 2 / 3 / 4 今天 / 7 天 / 30 天 / 全部
/ 在标签间切换
n / p 下一页 / 上一页
r 刷新
q 退出

数据拉取时表格会显示加载指示器,避免误以为卡死。

单位

数量统一用计算机领域的 K/M/G/T,耗时按 ms/s/min/h/d 自动选择最适合的尺度。

管理员模式

如果你的账号在 sub2api 后端有 role=admin,可以用 admin 子命令查看上游账户用量窗口/配额、平台用户消费排行、用户订阅(每日/每周/每月用量与到期时间)等。管理员凭据保存在 ~/.config/sub2api-usage/config.jsonadmin_profiles 命名空间,与普通账号互不影响。

# 首次运行会引导填写管理员邮箱/密码,登录后会校验 role=admin
sub2api-usage admin

# 配置 / 新增管理员 profile
sub2api-usage admin setup [name]

# 非交互打印
sub2api-usage admin print --view dashboard
sub2api-usage admin print --view accounts --json
sub2api-usage admin print --view users
sub2api-usage admin print --view users --sort-by week
sub2api-usage admin print --view subscriptions --json
sub2api-usage admin print --view subscriptions --status all --sort-by monthly_usage

# 管理 admin profile
sub2api-usage admin profiles list
sub2api-usage admin profiles use <name>
sub2api-usage admin profiles remove <name>

管理员面板键位

通用:

功能
d / a / u / s 切到 Dashboard / 上游账户 / 用户排行 / 订阅管理
r 刷新
q 退出

Dashboard / Accounts 视图:

功能
1 / 2 / 3 / 4 / 5 切换时段:今天 / 昨天 / 7 天 / 30 天 / 全部

Users 视图(多时段并排展示,按当前列倒序):

功能
1 / 2 / 3 / 4 / 5 按今天 / 昨天 / 7 天 / 30 天 / 全部 倒序
e 按邮箱升序
o 排序键循环
/ 搜索当前表格,状态栏显示输入并高亮匹配数据;Enter 收起输入,Esc 清除

Subscriptions 视图:

功能
1 / 3 / 4 按日 / 周 / 月用量倒序
e / i / x 按邮箱 / ID / 到期升序
S 状态过滤循环:active → expired → paused → all
o 排序键循环
/ 搜索当前表格,状态栏显示输入并高亮匹配数据;Enter 收起输入,Esc 清除

数据拉取时当前视图会显示加载指示器,避免误以为卡死。

视图

  • Dashboard:今日 / 累计请求与成本、用户数、上游账户分类计数 (正常/异常/限流/过载)、RPM/TPM、平均耗时、运行时长,以及当前时段模型 Top。
  • Accounts:所有上游账户列表,含 5h 窗口 (current_window_cost / window_cost_limit) 与 7d 窗口用量、窗口截止时间、今日请求 / Token / 成本、当前并发、活跃会话/RPM、最后使用时间。
  • Users:用户消费排行,今天 / 昨天 / 7 天 / 30 天 / 全部 五列实际成本并排展示,默认按今日倒序。当前排序列在表头标注 ,方括号里是该列的快捷键。
  • Subscriptions:管理员订阅列表,默认只显示 active,可用 S 切换状态、o 或快捷键切换排序。含用户、分组、状态、日/周/月用量与对应分组限额、到期时间与剩余天数。

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sub2api_usage-0.3.6.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sub2api_usage-0.3.6-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file sub2api_usage-0.3.6.tar.gz.

File metadata

  • Download URL: sub2api_usage-0.3.6.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sub2api_usage-0.3.6.tar.gz
Algorithm Hash digest
SHA256 4a24d6cbbe46c794c914678098ca253565aa909f46af99fbd60f13706a1360e4
MD5 6a6d8f1cc3355609c08b009982eff181
BLAKE2b-256 7d8c148107f808bf4753c27c2c5acd2b7734db8fc4faa6eae8d023eac60aab9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for sub2api_usage-0.3.6.tar.gz:

Publisher: publish.yml on kadaliao/sub2api-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sub2api_usage-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: sub2api_usage-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for sub2api_usage-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6635f35bba4d2b2bcbb68b756d9a16cfa57b95512f2f71fe334a21556a261c
MD5 5a1b60bf4d5175c7ef7f7c394eac3b8b
BLAKE2b-256 8c251509d4214f38855e2a034662ec6657994659352cd5543dd6814696a74814

See more details on using hashes here.

Provenance

The following attestation bundles were made for sub2api_usage-0.3.6-py3-none-any.whl:

Publisher: publish.yml on kadaliao/sub2api-usage

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page