Skip to content

feat: add exact Fast usage and tier-aware cost tracking#280

Merged
douglasmonsky merged 25 commits into
mainfrom
feature/otel-fast-usage-ingestion
Jul 17, 2026
Merged

feat: add exact Fast usage and tier-aware cost tracking#280
douglasmonsky merged 25 commits into
mainfrom
feature/otel-fast-usage-ingestion

Conversation

@douglasmonsky

@douglasmonsky douglasmonsky commented Jul 16, 2026

Copy link
Copy Markdown
Owner

Summary

  • ingest aggregate-only Codex OTLP response.completed events incrementally and conservatively reconcile their exact service tiers to canonical usage calls
  • preserve exact priority, fast, standard, default, flex, and other observed tiers while deriving the Fast flag separately
  • cache all published OpenAI API service-tier price tables and select the observed tier for API-equivalent cost estimates
  • source-stamp documented Codex Fast credit multipliers, support local overrides, and expose Standard/Fast credit scenarios
  • carry service-tier, pricing-tier, billing-basis, multiplier provenance, and scenario fields through the stable JSON, CSV, dashboard, support, and documentation surfaces
  • harden OTel rotation, reset/rebuild behavior, partial pricing configurations, and malformed multiplier handling
  • preserve incremental cursor continuity across same-inode rewrites with schema-31 bounded resume anchors and a safe one-time legacy reread

Why

Codex session logs do not directly record whether a call used Fast mode. Existing throughput heuristics can identify candidates but cannot support exact historical accounting. Codex OTLP completion events contain the response service tier, so retained OTel evidence can identify exact Fast/Priority usage moving forward and reconstruct history only where those aggregate logs still exist.

Fast/Priority also has two distinct cost interpretations. ChatGPT usage may consume Codex credits with a documented Fast multiplier, while API usage may use the higher Priority processing token rates. This change models both without inferring the account's billing channel from routing evidence alone.

Billing semantics

  • usage_credits remains a ChatGPT-equivalent credit estimate and applies a source-stamped Fast multiplier only to confirmed Fast calls.
  • estimated_cost_usd remains an API-token-equivalent estimate and selects the exact observed API service-tier table when configured.
  • billing_basis is an explicit local setting: unknown, chatgpt_credits, or api_tokens.
  • An observed Fast/Priority tier does not automatically set billing_basis.
  • Missing tier-specific pricing remains unpriced instead of silently falling back to a different tier.

User impact

  • Exact Fast usage is available from retained OTel completion evidence after refresh.
  • Calls and exports show the observed tier, confidence/source, billing interpretation, comparison scenarios, and multiplier provenance.
  • Historical calls without retained OTel evidence remain unknown rather than being promoted from a heuristic.
  • Legacy pricing files continue to use their selected projection; tier-aware pricing files fail closed for missing tiers.

Validation

  • python -m pytest -p no:cacheprovider -q — 1,086 passed
  • python -m pytest -p no:cacheprovider --cov=codex_usage_tracker --cov-report=term -q — 1,086 passed, 88% coverage
  • ruff check --no-cache .
  • python -m mypy --no-incremental
  • codex-task dashboard-verify --json
  • generated dashboard JavaScript syntax checks
  • installed-package smoke test
  • python -m build
  • python -m twine check dist/*
  • python scripts/check_release.py --dist
  • git diff --check

@douglasmonsky
douglasmonsky marked this pull request as ready for review July 17, 2026 02:33
@douglasmonsky
douglasmonsky merged commit ea30bbd into main Jul 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant