Skip to content

Support cost and budget metrics in TUI status_line #38721

Open

Description

@thinker0

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.

Desired status line items:

  • estimated-cost-current-session
  • estimated-cost-today
  • estimated-cost-month
  • billing-budget-limit
  • billing-budget-used
  • billing-budget-remaining
  • billing-budget-percent
  • rate-limit-reset-time
  • five-hour-limit-percent
  • weekly-limit-percent

Example display:

GPT-5.5 | team-brain (main) | $34.7 | today:$34.7 mo:$5108.1 | ctx:23.0% | 5h:3.0% reset:4h43m | 7d:21.0%

Requirements:

  • 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.

Activity

  1. added
    enhancement
    CLI
    TUI
    rate-limits
    on Aug 15, 2026
  2. shiki-yusuke commented on Sep 9, 2026

    @shiki-yusuke

    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:

    1. 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.
    2. Period aggregates: estimated-cost-today / estimated-cost-month.
    3. Budget items: billing-budget-limit / -used / -remaining / -percent.
    4. Per-model rates for custom providers in config.toml.
    5. 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.
    6. 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.

  3. aiyer-commits commented on Sep 29, 2026

    @aiyer-commits

    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.006
    input_uncached_per_million = 0.30
    output_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.

  4. Keesan12 commented on Sep 30, 2026

    @Keesan12

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CLITUIenhancementrate-limits

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions