Skip to main content

Query Codex CLI token usage from local session JSONL logs.

Project description

codex-stat

一个可以读取本地 ~/.codex/sessions 日志、统计 Codex token 用量并估算价格的命令行工具。

发布到 PyPI 后,可以通过 uvx codex-stat 直接调用。

功能

  • 默认使用 Asia/Shanghai 时区展示和计算时间范围
  • 可以通过 --timezone 手动指定其他时区,如 UTCAmerica/Los_Angeles
  • 展示口径为 InputOutputCacheTotal
  • 其中 Input 代表非缓存输入,即 input_tokens - cached_input_tokens
  • 输出人类可读报表或 JSON
  • 按每 1M token 单价估算成本

本地开发

uv run codex-stat --range today
uv run codex-stat --range 7d --limit 5
uv run codex-stat --range today --timezone UTC
uv run codex-stat --from-date 2026-03-01 --to-date 2026-03-06
uv run codex-stat --range today --json

成本估算

uv run codex-stat \
  --range today \
  --input-price-per-m 0.625 \
  --cached-input-price-per-m 0.0625 \
  --output-price-per-m 5

估价公式:

  • Input = input_tokens - cached_input_tokens
  • 总费用 = 非缓存输入费用 + 缓存输入费用 + 输出费用
  • Cache = cached_input_tokens
  • Total 使用日志里的 total_tokens

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

codex_stat-0.1.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

codex_stat-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file codex_stat-0.1.1.tar.gz.

File metadata

  • Download URL: codex_stat-0.1.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for codex_stat-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a151d14898ba54a6c6cb40e7830837dfe011cee5269b4462357a98a5f2f51f07
MD5 1ac93a6ed6f18263e4355bda90012d53
BLAKE2b-256 40c4311ec72aa3eaa4b3c5cc35e701a67ed024cf4a42f8979f8d389d7af9ed1d

See more details on using hashes here.

File details

Details for the file codex_stat-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for codex_stat-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8027a0cf0758933c493645720a52c39cf71e79c661f96a24ca0baef88920d4b0
MD5 430d00564b3305ce2ec1c35e9dd51e0b
BLAKE2b-256 ba87628df2f74d5b6b360f2388918acf791d33240c24732a9dcea14319dfd74c

See more details on using hashes here.

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