Skip to content

feat(codex): account for fast mode pricing - #996

Merged
ryoppippi merged 1 commit into
mainfrom
feat/codex-fast-pricing
May 15, 2026
Merged

feat(codex): account for fast mode pricing#996
ryoppippi merged 1 commit into
mainfrom
feat/codex-fast-pricing

Conversation

@ryoppippi

@ryoppippi ryoppippi commented May 15, 2026

Copy link
Copy Markdown
Member

Summary:

  • Adds --speed auto|standard|fast to Codex daily, monthly, and session reports.
  • Defaults auto mode to reading CODEX_HOME config.toml and treating service_tier priority or legacy fast as fast pricing.
  • Applies LiteLLM fast multipliers when present, with a Codex 2x fallback when pricing data lacks one.
  • Documents the new speed pricing behavior in the Codex README and guide pages.

Testing:

  • pnpm run format
  • pnpm typecheck
  • pnpm run test
  • Manual fixture: CODEX_HOME config.toml service_tier=priority produced auto cost 31.5 vs standard cost 15.75

Summary by CodeRabbit

  • New Features

    • Added --speed CLI option (auto|standard|fast) to daily, monthly, and session commands for pricing tier control
    • Implemented speed pricing that automatically applies fast pricing based on configuration when --speed auto is used
  • Documentation

    • Updated command documentation with new --speed option details and behavior
    • Added speed pricing guide explaining auto/fast/standard tier configuration

Review Change Stack

Add a Codex speed option that defaults to reading CODEX_HOME config.toml and treats service_tier priority or legacy fast as fast mode. This lets reports estimate costs correctly even though Codex token_count logs do not include the active service tier.

Thread the resolved speed into Codex pricing, using model-specific LiteLLM fast multipliers when present and a Codex 2x fallback when pricing data has not caught up. Document the auto, fast, and standard options in the package README and Codex guides.
@ryoppippi
ryoppippi merged commit 14db99a into main May 15, 2026
14 of 16 checks passed
@ryoppippi
ryoppippi deleted the feat/codex-fast-pricing branch May 15, 2026 10:39
@github-actions

Copy link
Copy Markdown
Contributor

ccusage performance comparison

This compares the PR build against the base branch build on the same CI runner.

Committed fixture performance

Committed small fixture for stable PR-to-PR feedback and output-shape regressions.

Fixture: apps/ccusage/test/fixtures/claude
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Base median PR median PR vs base
daily --offline --json 74.7ms 75.3ms 0.99x
session --offline --json 74.4ms 73.3ms 1.01x
blocks --offline --json 73.9ms 74.2ms 1.00x

Large real-world-shaped fixture performance

Generated fixture around 1 GiB shaped from aggregate local Claude-log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixture.

Fixture: /home/runner/work/_temp/ccusage-large-fixture
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Base median PR median PR vs base
daily --offline --json 1.341s 1.347s 1.00x

Package size

Package artifact Base PR Delta Ratio
packed ccusage-*.tgz 43.29 KiB 43.29 KiB +0.00 KiB 1.00x

Lower medians and smaller packed package sizes are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d782ecb-a34f-4fd0-9da4-bd9844374dc6

📥 Commits

Reviewing files that changed from the base of the PR and between b5ec88b and 6a1af2e.

📒 Files selected for processing (11)
  • apps/codex/README.md
  • apps/codex/src/_shared-args.ts
  • apps/codex/src/codex-config.ts
  • apps/codex/src/commands/daily.ts
  • apps/codex/src/commands/monthly.ts
  • apps/codex/src/commands/session.ts
  • apps/codex/src/pricing.ts
  • docs/guide/codex/daily.md
  • docs/guide/codex/index.md
  • docs/guide/codex/monthly.md
  • docs/guide/codex/session.md

📝 Walkthrough

Walkthrough

This PR introduces a configurable speed-based pricing feature to the Codex CLI. Users can now pass --speed auto|standard|fast to daily, monthly, and session commands. The auto mode reads ${CODEX_HOME:-~/.codex}/config.toml to detect the service tier and apply fast pricing multipliers, falling back to standard when config is unavailable or unreadable.

Changes

Speed-based pricing for Codex CLI

Layer / File(s) Summary
Speed config types and resolution
apps/codex/src/codex-config.ts
Introduces CodexSpeed ('standard' | 'fast') and CodexSpeedOption ('auto' | CodexSpeed) types; implements TOML-like config parsing to extract service_tier values, normalizes CLI speed inputs, and provides async resolution of 'auto' mode by reading config.toml with fallback to 'standard'. Includes unit tests covering tier detection, profile overrides, and validation.
CLI argument definition
apps/codex/src/_shared-args.ts
Adds --speed argument to shared CLI args with type string, default 'auto', and help text describing how auto reads config.toml and how standard/fast values override.
Pricing source speed support
apps/codex/src/pricing.ts
Extends CodexPricingSourceOptions with optional speed field and applies a speedMultiplier when speed is 'fast': uses provider-specific LiteLLM fast multiplier or falls back to 2x. Multiplier applies to input, cached input, and output per-million costs. Includes unit tests verifying fast multiplier and fallback behavior.
Command integration with speed
apps/codex/src/commands/daily.ts, apps/codex/src/commands/monthly.ts, apps/codex/src/commands/session.ts
Each command normalizes ctx.values.speed, handles validation errors with exit(1), resolves the final speed asynchronously, and passes resolved speed to CodexPricingSource for cost computation.
User-facing documentation
apps/codex/README.md, docs/guide/codex/index.md, docs/guide/codex/daily.md, docs/guide/codex/monthly.md, docs/guide/codex/session.md
Documents the new --speed flag across CLI guide and command docs; explains how --speed auto detects fast pricing from config.toml when service_tier is 'priority' or legacy 'fast'; describes fast mode multiplier behavior (LiteLLM-specific or 2x fallback). Adds session command example to README.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • ryoppippi/ccusage#905: Documents the correct npx @ccusage/codex@latest session command example and overlaps with README.md updates in this PR.

Poem

🐰 A rabbit hops to mark the speed,
Config tiers now plant the seed,
Fast or standard, auto's best,
Let the config pass the test!
Price adjusts with multiplied glee, 🚀

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/codex-fast-pricing

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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