Skip to content

Estimate Codex API cost via ccusage in API-key mode - #1290

Closed
mistercrunch wants to merge 3 commits into
mainfrom
investigate-codex-cost-estimates
Closed

mistercrunch wants to merge 3 commits into
mainfrom
investigate-codex-cost-estimates

Conversation

@mistercrunch

@mistercrunch mistercrunch commented May 29, 2026 •

Copy link
Copy Markdown
Member

Summary

  • switch Codex $ estimation from Agor-owned model pricing to a defensive ccusage CLI adapter
  • only derive Codex USD cost when the session is running with an explicit OpenAI API key; native-auth / ChatGPT-plan sessions still show cost as unavailable
  • keep the estimator fail-open: if ccusage is missing, parsing fails, or prior task costs are incomplete, Agor leaves cost unset instead of showing a misleading value
  • add focused tests for ccusage session matching, cumulative-session delta math, and fail-open behavior

Validation

  • pnpm --dir packages/executor test -- src/sdk-handlers/codex/ccusage.test.ts src/sdk-handlers/codex/normalizer.test.ts
  • git diff --check

Notes

  • current ccusage Codex support is exposed through its CLI/native binary, not stable JS internals, so this shells out to ccusage codex session --json --offline
  • Agor computes per-task cost by subtracting already-stored prior task costs from ccusage's cumulative per-session cost
  • if older Codex tasks in the session have token usage but no stored cost yet, new tasks remain N/A until the session has a reliable baseline

@mistercrunch mistercrunch changed the title Estimate Codex API cost when pricing is known Estimate Codex API cost via ccusage in API-key mode May 29, 2026
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.

2 participants