feat(codex): compute Codex credit usage (#408, #495)#510
Merged
Conversation
Codex/ChatGPT subscription users consume credits, a unit separate from API dollars: usage is billed as credits-per-million-tokens at per-model rates that differ from the API USD pricing CodeBurn uses for cost. So the reported dollar cost does not match what credits actually consume. Add a credit engine sourced from the official Codex credit rates (developers.openai.com/codex/pricing): GPT-5.5 125/12.5/750, GPT-5.4 62.5/6.25/375, GPT-5.4 mini 18.75/1.875/113 credits per 1M input/cached/output tokens. Surface per-model credit usage in `codeburn models` JSON output (credits field; null for non-Codex or unknown models). models-report already folds reasoning into output and keeps non-cached input + cached-read separately, which is exactly what the credit rates expect, so the figure is exact. Engine + computation are unit-tested. UI display surfaces (the models table, the TUI dashboard, the menubar "credits" view) are intentionally left for a follow-up so the display choice can be decided.
Surface Codex credit usage in the menubar as a selectable metric, without changing the default. Cost ($) stays the default in both the menubar and the CLI; credits only appear when explicitly chosen. - TS: buildMenubarPayloadForRange computes the period's Codex credits (via the tested aggregateModels, so reasoning/cached are handled) and exposes current.codexCredits in the menubar JSON. - Swift: new DisplayMetric.credits, a "Credits (Codex)" option in the metric picker, decodes codexCredits, and renders it in the menu-bar title. Default metric remains .cost.
This was referenced Jun 18, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses #495 (Codex pricing ≠ credit pricing) and lays the groundwork for #408 (credits as a usage currency). Do not merge yet — opening for review; UI display surface still to be decided.
Problem
CodeBurn prices Codex sessions at OpenAI API token rates (LiteLLM). ChatGPT/Codex subscription users actually consume credits, billed as credits-per-million-tokens at per-model rates that differ from API USD — so the reported dollar cost doesn't reflect credit consumption.
What this adds
src/codex-credits.ts: credit engine from the official rates (developers.openai.com/codex/pricing): GPT-5.5125 / 12.5 / 750, GPT-5.462.5 / 6.25 / 375, GPT-5.4 mini18.75 / 1.875 / 113credits per 1M input / cached / output tokens. Tolerates-codexsuffixes; returns null for unknown models.codeburn modelsJSON (creditsfield; null for non-Codex/unknown).models-reportalready folds reasoning into output and tracks non-cached input + cached-read separately — exactly what the credit rates expect, so the figure is exact.Verified on real data
The $/credit ratio (~$0.04) ≠ a naive conversion, confirming #495's point that the two pricings genuinely differ.
Tests
tests/codex-credits.test.ts(10): documented rates, suffix variants, reasoning-as-output, cached rate, clamping, unknown→null.tests/models-report.test.ts: per-model credits + null for non-Codex/unknown + credits in JSON output.Intentionally NOT in this PR (follow-up, your call on display)
modelstable, the TUI dashboard, and a menubar "credits used" view (alongside the existing "credits remaining"). Feature Request: Add Credits as Currency #408 is really a display-unit decision, so I left the rendering for you to direct.