You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support cost and budget metrics in TUI status_line #38721
CLIIssues related to the Codex CLITUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displayenhancementNew feature or requestrate-limitsIssues related to rate limits, quotas, and token usage reporting
Codex TUI currently supports token/context/rate-limit status line items such as context-used, used-tokens, total-input-tokens, total-output-tokens, five-hour-limit, and weekly-limit.
Please add native cost and budget status line items so users can monitor estimated spending directly in the bottom status bar.
Cost should be calculated using the active model provider's actual pricing when available.
If exact billing data is unavailable, Codex should clearly mark values as estimated.
Cached input, cache write, output, and long-context multipliers should be handled separately.
For custom providers, allow users to configure per-model rates in config.toml.
Status line should expose both compact and detailed forms.
Values should not leak API keys, organization IDs, or account-sensitive billing metadata.
Why:
Users already see token and context usage in the TUI, but cannot quickly understand cost impact. For long-context coding sessions, cost awareness is important for budget control and model selection.
Partial status update from a user's side, in case it helps triage (checked against rust-v0.153.4, 2026-09-09):
Already shipped (before this issue was filed):#38282 (merged 2026-08-13) added two status-line / terminal-title items, thread-credits and estimated-thread-cost.
The UI descriptions label these items as "Enterprise workspaces only". In rust-v0.153.4, however, thread_usage_is_available() also includes PlanType::Business alongside EnterpriseCbpUsageBased and EnterpriseCbpAutomation, subject to Codex backend authentication and feature availability. I have not verified availability across every commercial plan.
These items cover the "estimated cost of the current thread" part of this request for eligible workspace plans, and unavailable values are omitted.
Not covered yet, as far as I can see in the current source:
Availability outside the eligible workspace-plan path above. The current availability check is limited to specific plan types and Codex backend authentication; I have not verified every API-key or ChatGPT plan configuration.
Period aggregates: estimated-cost-today / estimated-cost-month.
Per-model rates for custom providers in config.toml.
A visible per-component breakdown for cached input / cache write / output / long-context effects. The current status items expose aggregate credits / USD; I have not verified the backend's internal pricing decomposition.
rate-limit-reset-time and percent variants of the 5h / weekly limits (five-hour-limit / weekly-limit exist, but not the proposed -percent / reset-time keys).
Two things that might be worth making explicit in the design, based on experience building local cost measurement tooling:
Keep four quantities distinct and never convert one into another: context usage (% of window), rate/quota (5h / weekly remaining), usage/cost (tokens, credits, estimated USD, billed USD), and a user-defined task budget. For example, 30% context used is not 30% of anything billable; /usage daily token activity is not the day's invoice.
Show provenance and completeness, not just a number: provider estimate vs. local price-table estimate vs. settled billing; whether child threads are included; and null/omitted rather than 0 when a price is unknown (unpriced) so downstream tooling does not read "no data" as "free". The current "omit when unavailable" behavior in Add thread usage to TUI status surfaces #38282 is a good default to preserve for the remaining items.
If it helps, I can put together a small table of which requested keys map to existing items vs. which are new, or a fixture set for the unpriced / partial / stale-estimate cases.
Following up on the mapping above with field data from a custom-provider setup, since item 4 (per-model rates for custom providers in config.toml) is the one that blocks the most users in practice.
What actually happens with a non-OpenAI provider
Running against DeepSeek through a custom model_provider, the cost items are simply absent: estimated-thread-cost / thread-credits are derived from the Codex backend's thread-estimates endpoint and gated on plan type, so there is no local path to a number. Checked the source: ModelInfo carries no price fields anywhere in codex-rs, and there is no local price table, so a client-side fallback would have to invent rates. That is worse than omitting the value, because a plausible wrong number is harder to notice than a blank one.
The tokens needed are already local. Rollout logs ($CODEX_HOME/sessions/**/rollout-*.jsonl) carry token_count events whose last_token_usage has input_tokens, cached_input_tokens, and output_tokens, so a per-thread estimate is computable client-side with no new plumbing.
Measured example
One real session on DeepSeek's Flash model (~7M cached input, ~67k uncached input, ~71k output) comes to roughly $0.18 at that provider's published peak rates (cached input $0.006 / uncached input $0.30 / output $1.20 per 1M tokens). The same rate card prices the Pro model at $0.044 / $1.32 / $3.96, so keying rates by model slug matters even within a single provider.
Proposed config shape
# USD per 1M tokens; omit a model to leave the item blank.
[model_prices."deepseek-flash"]
input_cached_per_million = 0.006input_uncached_per_million = 0.30output_per_million = 1.20# cache_write_per_million = 0.0 # optional, separate from cached input
Keyed by model slug, matching how model and model_provider are configured today. A thread-cost status-line and terminal-title item renders it, and stays omitted for models with no entry, consistent with the existing "omit when unavailable" behavior. Keeping it a distinct item from estimated-thread-cost keeps provenance obvious: backend estimate vs. local rate table.
Two correctness details worth pinning down in the design:
Keep cached input, cache write, and uncached input as separate buckets. Charging everything at the uncached rate, or folding cache hits into uncached input, misprices the part of the bill that dominates long sessions, where cached input is most of the volume.
Some providers have peak/off-peak rates. In the example above, peak is 01:00-04:00 and 06:00-10:00 UTC Monday-Friday and everything else is half price. A flat table cannot express that, so either allow an optional second rate set or document the value as a fixed-rate estimate.
Implementation sketch
Contained, and it does not require ModelInfo to gain pricing (it has none today), because for non-OpenAI models the client cannot derive rates at all:
codex-config: a ModelPrice struct plus a model_prices map on ConfigToml
codex-core: surface it on Config
codex-tui: a cost item for the status line and terminal title, valued from the session's TokenUsage (cached_input(), non_cached_input(), output_tokens), with unit tests for the cached/uncached split, negative-usage clamping, and the unpriced/omitted case
I have this working as a local patch in a fork (~100 LoC plus tests) and it has matched the provider's billing for our sessions. Happy to share the diff or a fixture set (unpriced / partial / hand-checked values). Posting as design input rather than a PR, per docs/contributing.md.
Budget visibility and budget enforcement should stay separate. A status line can show estimated or settled cost with provenance. A task budget should stop the run even when provider billing is delayed or unavailable. Unknown prices should render as unknown, never as zero.
I built MartinLoop. It is open source. For the enforcement layer I use
martin run "finish the scoped change" --verify "npm test" --budget-usd 3 --max-iterations 6
martin dossier --latest then records why the run stopped. I would not present that as authoritative Codex billing. It is a run boundary.
CLIIssues related to the Codex CLITUIIssues related to the terminal user interface: text input, menus and dialogs, and terminal displayenhancementNew feature or requestrate-limitsIssues related to rate limits, quotas, and token usage reporting
Activity
shiki-yusuke commentedon Sep 9, 2026
Partial status update from a user's side, in case it helps triage (checked against
rust-v0.153.4, 2026-09-09):Already shipped (before this issue was filed): #38282 (merged 2026-08-13) added two status-line / terminal-title items,
thread-creditsandestimated-thread-cost.The UI descriptions label these items as "Enterprise workspaces only". In
rust-v0.153.4, however,thread_usage_is_available()also includesPlanType::BusinessalongsideEnterpriseCbpUsageBasedandEnterpriseCbpAutomation, subject to Codex backend authentication and feature availability. I have not verified availability across every commercial plan.These items cover the "estimated cost of the current thread" part of this request for eligible workspace plans, and unavailable values are omitted.
Not covered yet, as far as I can see in the current source:
estimated-cost-today/estimated-cost-month.billing-budget-limit/-used/-remaining/-percent.config.toml.rate-limit-reset-timeand percent variants of the 5h / weekly limits (five-hour-limit/weekly-limitexist, but not the proposed-percent/ reset-time keys).Two things that might be worth making explicit in the design, based on experience building local cost measurement tooling:
/usage dailytoken activity is not the day's invoice.null/omitted rather than0when a price is unknown (unpriced) so downstream tooling does not read "no data" as "free". The current "omit when unavailable" behavior in Add thread usage to TUI status surfaces #38282 is a good default to preserve for the remaining items.If it helps, I can put together a small table of which requested keys map to existing items vs. which are new, or a fixture set for the
unpriced/ partial / stale-estimate cases.aiyer-commits commentedon Sep 29, 2026
Following up on the mapping above with field data from a custom-provider setup, since item 4 (per-model rates for custom providers in
config.toml) is the one that blocks the most users in practice.What actually happens with a non-OpenAI provider
Running against DeepSeek through a custom
model_provider, the cost items are simply absent:estimated-thread-cost/thread-creditsare derived from the Codex backend's thread-estimates endpoint and gated on plan type, so there is no local path to a number. Checked the source:ModelInfocarries no price fields anywhere incodex-rs, and there is no local price table, so a client-side fallback would have to invent rates. That is worse than omitting the value, because a plausible wrong number is harder to notice than a blank one.The tokens needed are already local. Rollout logs (
$CODEX_HOME/sessions/**/rollout-*.jsonl) carrytoken_countevents whoselast_token_usagehasinput_tokens,cached_input_tokens, andoutput_tokens, so a per-thread estimate is computable client-side with no new plumbing.Measured example
One real session on DeepSeek's Flash model (~7M cached input, ~67k uncached input, ~71k output) comes to roughly $0.18 at that provider's published peak rates (cached input $0.006 / uncached input $0.30 / output $1.20 per 1M tokens). The same rate card prices the Pro model at $0.044 / $1.32 / $3.96, so keying rates by model slug matters even within a single provider.
Proposed config shape
Keyed by model slug, matching how
modelandmodel_providerare configured today. Athread-coststatus-line and terminal-title item renders it, and stays omitted for models with no entry, consistent with the existing "omit when unavailable" behavior. Keeping it a distinct item fromestimated-thread-costkeeps provenance obvious: backend estimate vs. local rate table.Two correctness details worth pinning down in the design:
Implementation sketch
Contained, and it does not require
ModelInfoto gain pricing (it has none today), because for non-OpenAI models the client cannot derive rates at all:codex-config: aModelPricestruct plus amodel_pricesmap onConfigTomlcodex-core: surface it onConfigcodex-tui: a cost item for the status line and terminal title, valued from the session'sTokenUsage(cached_input(),non_cached_input(),output_tokens), with unit tests for the cached/uncached split, negative-usage clamping, and the unpriced/omitted caseI have this working as a local patch in a fork (~100 LoC plus tests) and it has matched the provider's billing for our sessions. Happy to share the diff or a fixture set (unpriced / partial / hand-checked values). Posting as design input rather than a PR, per
docs/contributing.md.Keesan12 commentedon Sep 30, 2026
Budget visibility and budget enforcement should stay separate. A status line can show estimated or settled cost with provenance. A task budget should stop the run even when provider billing is delayed or unavailable. Unknown prices should render as unknown, never as zero.
I built MartinLoop. It is open source. For the enforcement layer I use
martin run "finish the scoped change" --verify "npm test" --budget-usd 3 --max-iterations 6
martin dossier --latest then records why the run stopped. I would not present that as authoritative Codex billing. It is a run boundary.