Skip to main content

Codex CLI Token Cost: Estimate Daily API Spend Before a Long Run

For API-billed Codex CLI work, price ordinary input, cache reads, cache writes, and output separately. A planned day can then be compared with your budget before the next long task starts.

LaoZhang AI TeamPublishedUpdated 15 min read
On this page
Conceptual Codex API spending plan using four token categories, the applicable quote, expected work blocks and a pause decision

For API-billed Codex CLI work, estimate each request's token cost, then add the requests and work blocks you expect in a day. Ordinary input, cache reads, cache writes, and output can have different prices. ChatGPT sign-in uses a separate plan or workspace meter, so an API dollar estimate does not tell you how much subscription capacity remains.

At the October 7, 2026 Standard, global, short-context price for gpt-6.1-sol, an illustrative day with 1.2 million ordinary input tokens, 2.4 million cache-read tokens, 0.4 million cache-write tokens, and 0.35 million output tokens costs $7.14 in model tokens. Those input categories are separate and add up to 4 million total input tokens. The example assumes every request stays within the short-context threshold; it excludes tools and other charges. Rates come from OpenAI's API pricing, not a measured Codex day.

Use the calculation below to make a spending decision: identify who bills the run, record the applicable quote, estimate the remaining work, and pause while there is still room to revise the task.

Start With The Two-Minute Estimator

Before a repository-wide refactor or a long debugging session, write down five things:

  1. Billing route: ChatGPT/workspace usage, OpenAI Platform API billing, or another provider's billing.
  2. Quote: actual model, service tier, processing region, and per-request context band.
  3. Token mix: ordinary input, cache reads, cache writes, and output, with no overlap.
  4. Work remaining: expected blocks of similar work, including helpers, retries, and fallback models.
  5. Pause point: how much you are willing to spend before reviewing progress.

For one request, the calculation is:

U = total input tokens - cache-read tokens - cache-write tokens

model token cost =
  (U × ordinary-input price
   + cache-read tokens × cache-read price
   + cache-write tokens × cache-write price
   + output tokens × output price) / 1,000,000

Prices here are dollars per million tokens. Add each request once, using its applicable prices. Then add any separately billed tools or provider fees that apply to the work. A daily forecast is useful even when it is a range; calling it an exact invoice or a guaranteed spending ceiling would require more information.

Which Codex Meter Is Active?

Identify the billing route before attaching dollar prices to a token counter. Local CLI work can use either ChatGPT sign-in or an API key. The same terminal interface does not make their billing equivalent. OpenAI's authentication documentation distinguishes the routes.

Conceptual Codex billing routes separating ChatGPT or workspace usage, OpenAI Platform API costs, managed automation and other provider records

Route used by the runWhat pays for itAppropriate cost check
ChatGPT sign-inIncluded plan/workspace usage and eligible creditsCodex/ChatGPT usage settings and the applicable workspace terms
OpenAI API keyOpenAI Platform API usageThe API quote, usage records, and Platform costs for the relevant organization/project
ChatGPT-managed enterprise automationThe applicable workspace arrangementWorkspace usage and contract; automation alone does not establish API billing
Another model provider or gatewayThat provider's pricing and meteringIts resolved model, quote, and cost records

The CLI's documented authentication-status check is codex login status. For automation, also identify the credentials intentionally selected by the invocation: codex exec normally reuses saved authentication, while an invocation can use a different API key. Current documentation also describes ChatGPT-managed authentication for trusted automation. You do not need to change your login merely to forecast a run.

Codex cloud requires ChatGPT sign-in. Speed settings also need the correct meter: subscription usage multipliers and purchased-credit rates are not API dollar multipliers. Use Codex pricing for that route. An OpenAI-compatible endpoint supplied by a gateway does not establish that OpenAI's listed prices are the amounts you pay.

If you need to locate a counter before calculating, how to check Codex token usage explains the distinction between CLI session/context views, account usage, and API per-call tokens.

Current Price Anchors To Use

Record the quote that applies to your actual run. These API text-token prices were checked on October 7, 2026 and cover Standard service, global processing, and short input requests. For gpt-6.1-sol, the short band includes requests with up to 272,000 input tokens. All amounts are USD per million tokens; taxes, gateway markups, paid tools, and other line items are outside this table. Source: OpenAI API pricing.

ModelOrdinary inputCache readCache writeOutput
gpt-6.1-sol$2.00$0.10$2.50$10.00
gpt-6-sol$2.00$0.20$2.50$10.00
gpt-6-luna$0.10$0.01$0.125$0.50
gpt-5.4-mini$0.75$0.075No separate write rate$4.50
gpt-5.4$2.50$0.25No separate write rate$15.00

The older-model rows remain useful for workloads that actually use those models. They do not prove availability for a particular key, and the cheaper row does not prove that a model can finish your task with the same number of attempts. Choose a supported model that meets the task's acceptance criteria, then price its expected workload.

A quote changes when the request changes. For gpt-6.1-sol, the model's pricing notes specify:

  • More than 272,000 input tokens: the entire request uses twice the short-context input/cache rates and 1.5 times the output rate.
  • Fast: twice the Standard prices.
  • Batch or Flex: half the Standard prices, when the workflow and model support that service.
  • Regional processing: a 10% premium where available.

These are API pricing conditions. A Batch or Flex quote does not mean that an ordinary interactive CLI run automatically uses the discounted service. Availability and restrictions still apply to the chosen configuration.

Long context changes the whole request's price

For a fictional gpt-6.1-sol Standard/global request with 300,000 total input tokens, suppose 120,000 are cache reads, 60,000 are writes, and 120,000 are ordinary input. With 15,000 output tokens, the applicable calculation is:

(120,000 × $4 + 120,000 × $0.20 + 60,000 × $5
 + 15,000 × $15) / 1,000,000 = $1.029

Charging only the input tokens above 272,000 at the higher rate would understate the cost. Conversely, a day totaling millions of input tokens can still consist entirely of short requests. Daily totals alone cannot determine which context band applied. Keep short and long requests separate when building the forecast.

Calculate Cache Costs Without Double Counting

Total input already contains the cached categories. In the Responses API, usage.input_tokens includes both input_tokens_details.cached_tokens and input_tokens_details.cache_write_tokens. Subtract those two categories to find ordinary input. A cache write replaces ordinary-input pricing for those tokens; it is not an extra fee added after charging the same tokens as ordinary input. Source: prompt-caching guide.

For example, a fictional short gpt-6.1-sol request has 200,000 total input tokens, 80,000 cache reads, 40,000 writes, and 10,000 output tokens:

Ordinary input = 200,000 - 80,000 - 40,000 = 80,000

Cost = (80,000 × $2 + 80,000 × $0.10
        + 40,000 × $2.50 + 10,000 × $10) / 1,000,000
     = $0.368

If your planning sheet already gives ordinary input separately, use that number directly. Do not subtract cache reads or writes from it again. In every complete record, the nonnegative input buckets should add up to total input.

For API Responses usage, output already includes reasoning tokens. The reasoning detail is useful for explaining consumption, but adding it again would double count output. OpenAI's metrics example makes this explicit. A terminal command's printed test log is different: if the model reads it, it contributes to input context; it is not automatically model-generated output.

When cache writes are missing, calculate a conditional range

The documented CLI JSONL example shows input_tokens, cached_input_tokens, output_tokens, and reasoning_output_tokens on turn.completed. It does not show a cache-write counter. Do not silently set missing writes to zero on a write-billed model or treat the example as a complete invoice schema.

If you have a trustworthy total input of 200,000, a cache-read count of 80,000, and API output of 10,000, but no write count, the same short gpt-6.1-sol quote gives a $0.348–$0.408 token-cost range:

  • Lower end: all 120,000 non-read input tokens use the $2 ordinary rate.
  • Upper end: all 120,000 non-read input tokens use the $2.50 write rate.
  • Both ends add the known cache reads and output once.

That range assumes the input is entirely covered by those categories, the counters have the stated meaning, and the request uses the quoted model/tier/region/context band. It excludes missing requests and separate fees. If the export has an unpriced category or uncertain output semantics, obtain the appropriate records or quote before presenting a complete total.

Daily API Cost Scenarios

Use a scenario to rehearse the day's work, then replace its assumptions with your own. The following fictional workloads use disjoint input buckets and assume every request qualifies for the October 7 gpt-6.1-sol Standard/global short-context rates above. They are calculated model-token costs, not observed user bills or upper bounds on future runs.

Planned dayOrdinary inputCache readsCache writesOutputEstimated token cost
A few targeted fixes0.5M0.2M0.1M0.08M$2.07
Several coding/debugging blocks1.2M2.4M0.4M0.35M$7.14
Sustained refactor with many iterations4M6M2M1.2M$25.60

The middle row is 1.2 × $2 + 2.4 × $0.10 + 0.4 × $2.50 + 0.35 × $10 = $7.14. Output contributes $3.50, but it does not always dominate: ordinary input alone contributes $8 to the last row. Reading more files, changing cache behavior, and needing more attempts can all change the estimate.

Earlier-model illustration of light, normal, and heavy daily API token scenarios

The retained May 23 illustration shows earlier-model scenarios. Its separate “input” column means ordinary input, so its normal-day example has 5M total input: 3M ordinary plus 2M cached. With 0.4M output, the documented short-request Standard rates still calculate to $4.20 for gpt-5.4-mini and $14 for gpt-5.4. Use the four-bucket calculation for models that bill writes separately, and the current table for your actual quote. Source: API pricing.

An offline calculator for your own work blocks

This complete Python example calculates the $7.14 scenario using only the standard library. It makes no API calls and reads no account or session data. Each tuple gives ordinary input, cache reads, cache writes, and output. count repeats a planned block; it does not infer activity from elapsed time.

Enter separate blocks and fully resolved rates for different models or context bands. Do not enter total input in the ordinary-input position. Dollar rates are strings so Decimal preserves the arithmetic.

python
from decimal import Decimal

MILLION = Decimal(1_000_000)

# USD per million: ordinary input, cache read, cache write, output.
short_standard = ("2", "0.10", "2.50", "10")
blocks = [
    {
        "name": "coding and debugging",
        "count": 5,
        "tokens": (240_000, 480_000, 80_000, 70_000),
        "rates": short_standard,
    }
]
# Each block aggregates many short requests, not one 800K-input request.

def block_cost(block):
    count = block["count"]
    tokens = block["tokens"]
    rates = tuple(Decimal(value) for value in block["rates"])
    if type(count) is not int or count < 0:
        raise ValueError("count must be a nonnegative integer")
    if len(tokens) != 4 or len(rates) != 4:
        raise ValueError("provide four disjoint token buckets and four rates")
    if any(type(value) is not int or value < 0 for value in tokens):
        raise ValueError("token counts must be nonnegative integers")
    if any(not rate.is_finite() or rate < 0 for rate in rates):
        raise ValueError("rates must be finite and nonnegative")
    return sum(Decimal(n) * rate for n, rate in zip(tokens, rates)) * count / MILLION

total = Decimal(0)
for block in blocks:
    cost = block_cost(block)
    total += cost
    print(f'{block["name"]}: ${cost:.4f}')
print(f"Planned model-token cost: ${total:.4f}")

Expected final line: Planned model-token cost: $7.1400. If you do not know the write count, calculate the two conditional endpoints described above instead of submitting a falsely complete four-bucket record. Add priced tools and other charges outside this model-token subtotal.

How To Measure Your Own Codex Day

Use a representative work block and a matching billing window. If you already have authorized API usage records, start there. Otherwise, a representative task you choose to run can supply better assumptions than a generic “tokens per day” figure. A 30–60 minute sample is a planning option, not a requirement or a test performed for this article.

  1. Record the route, actual model, tier, region, work completed, and context bands.
  2. Collect the available token categories and cost records for that work. Mark unknown categories rather than replacing them with zero.
  3. Include helpers, retries, fallback models, and paid tools that belong to the same task.
  4. Divide the work into comparable blocks: investigation, editing, testing, or recovery from failures. Estimate how many similar blocks remain.
  5. Price the blocks, then reserve room for the uncertainty you actually have.

For example, five blocks at $1.428 each give the $7.14 plan. If you choose a 30% planning reserve, budget $9.282, or about $9.28. That reserve is your engineering choice; it is not an official confidence interval. A task with unpredictable loops needs a tighter scope and a pause decision, not just a larger percentage.

Match token records to the right time and scope

The organization Usage reference distinguishes total input, cache reads, cache writes, and uncached input. It can aggregate and group by model, service tier, project, key, and batch status. A daily aggregate mixing tiers or short and long requests is insufficient to reconstruct the correct per-request prices.

The schema also distinguishes 30-minute writes from a separate 12-hour write category. If that category appears in your data, obtain the applicable quote rather than discarding it or assuming the normal write rate applies. Modality detail fields are subdivisions, not extra tokens to add to a total.

For JSONL or other exported event data, establish whether a counter describes a turn, a request, or a cumulative session total. Do not add both cumulative snapshots and their terminal total. Do not remove two distinct requests just because their token counts happen to match. A failed or interrupted turn with no final usage record remains unaccounted for until reconciled; absence of a record does not establish that no cost occurred.

Reconcile The Forecast With Actual API Costs

Use the Usage Dashboard or the Costs reference for the relevant API organization and project. Dashboard access requires the appropriate permission. Its reporting uses UTC, and its project selector has its own scope, so a local calendar day or a different project selection can produce a misleading comparison.

Compare the same interval with an inclusive start and exclusive end, and the same project/key/model/tier scope where available. Consume all pages of an export or API result. Costs records provide an amount and currency; line-item quantities may use tokens, time, storage, images, or other units. Do not price every quantity as tokens.

If you only have an aggregate dollar amount, use it as the spend for that record's scope. You cannot uniquely recover ordinary input, cache reads, writes, and output from one total. Likewise, a vendor's allocated daily estimate is useful for attribution within its methodology, but it does not automatically establish a Platform invoice.

Scale Tier adds another distinction: a project can show positive token usage and zero additional project spend while its bundle is billed at the organization level. Reconcile bundles, discounts, credits, taxes, and other line items with the records that actually contain them. An estimate-to-record mismatch is a reason to inspect scope and rates before launching the next long task.

What Makes Codex CLI Burn More Tokens?

Control the work that generates repeated input and output, while retaining the context needed to finish correctly.

Cost driverWhat changesUseful first adjustment
Broad repository inspectionMore files and tool results enter inputName relevant paths and the question each inspection should answer
Repeated failed attemptsMore paid calls and repeated contextRequire a new diagnosis before another identical retry
Long responses and extensive reasoningMore API output tokensRequest concise explanations where sufficient; preserve needed reasoning for difficult work
Changing shared contextMore cache misses or writesKeep useful stable context; compare the actual token mix after changes
Helpers and fallback modelsMore calls, possibly different ratesInclude them in the work plan and the shared budget
Long requests or a faster tierDifferent prices for the workloadRequote those requests before extending the task

Caching requires a matching eligible prefix and an available retained entry. A session is not free memory, and shortening or restarting it is not universally cheaper: a changed prefix can lose cache reuse. OpenAI's caching guide explains the conditions. Remove irrelevant material, but keep the instructions, context, and tests needed for a correct result.

Budget Stop Rules For Long Runs

Decide whether the next block fits before allowing the task to expand. A practical plan combines a daily review threshold, a reserve for outstanding work, and clear task boundaries.

Suppose your chosen daily budget is $15. You choose to pause at 70%, or $10.50. If known spend is $8.40 and the next block plus reserve is forecast at $3, pause now: the resulting $11.40 would already exceed the review threshold. These percentages are illustrative decisions, not OpenAI defaults.

At the pause, ask whether the task has produced useful progress, whether another block has a clear purpose, and whether its cost fits. Narrow the files, reduce unnecessary output, revise the diagnosis, or stop when the acceptance criteria are met. Escalate the model only for a defined need and reprice the remaining work.

Once you decide that the remaining work is worth continuing, the Codex /goal guide explains how to keep one verifiable objective active and pause or resume it at checkpoints. Keep your spending decision separate from the task's completion condition.

Platform alerts notify while API traffic continues. An optional organization or project Enforce a hard limit setting can stop applicable traffic at a monthly tracked spend limit, but propagation can allow slight overshoot. A budget is not automatically an exact daily cutoff. Source: OpenAI spend limits.

If you need automated daily enforcement, the API spend kill-switch guide explains checking and reserving cost before each paid request, including helpers and retries. A forecast or a periodic dashboard check does not implement that control. Unknown in-flight usage should consume reserve until it is resolved.

Troubleshooting A Surprise High Bill

Pause additional work, then compare the estimate with the billed scope:

  1. Route: did the run use Platform billing when you expected ChatGPT/workspace usage?
  2. Quote: did the model, service tier, region, or context band differ from the plan?
  3. Buckets: did you double count cached input, omit writes, or add reasoning output twice?
  4. Work: did helpers, fallbacks, retries, or a separate automation run create extra calls?
  5. Records: are you comparing the same UTC window and organization/project, with every page included?
  6. Other charges: does the amount include tools, a bundle, or other non-token items?

Fix the mismatch before repeating the workload. A timeout, cancellation, or missing final usage message does not establish a free request or a refund. A lower token quote also does not guarantee lower cost per completed task if it requires more attempts.

FAQ

How many tokens does Codex CLI use per day?

There is no fixed daily number. Estimate your actual work blocks, including repeated context, output, cache reads/writes, retries, and helpers. Price each with its applicable model and request conditions. Subscription capacity is a separate question governed by Codex plan/workspace usage rules.

How do I calculate Codex CLI API cost per 1,000 tokens?

Use the price for the relevant category divided by 1,000. At October 7 Standard/global short-context gpt-6.1-sol rates, 1,000 ordinary input tokens cost $0.002, reads cost $0.0001, writes cost $0.0025, and output costs $0.01. A mixed total has no single price. Source: API pricing.

Can Codex CLI show the exact dollar cost of a session?

The documented JSONL example supplies usage counters, but lacks a cache-write field and does not establish a complete billing record. Use counters for a conditional estimate, and reconcile API spend with the corresponding Platform costs. CLI JSONL documentation, Costs reference.

Do ChatGPT credits pay OpenAI API-key bills?

No. Codex usage through ChatGPT sign-in follows plan/workspace usage and eligible credits. OpenAI API-key work uses Platform API billing. Do not convert a subscription fee into guaranteed API-equivalent tokens. Sources: authentication, Codex pricing.

Does a project budget stop Codex at my daily dollar limit?

An alert does not stop API calls. The optional enforced organization/project hard limit applies monthly and can slightly overshoot during propagation. For a daily automated stop, the runner needs a control before every paid request; a calculator alone does not enforce one. Source: spend limits.

What should I do before leaving a long task running?

Confirm the paying route and quote, calculate the remaining blocks, include helpers and retry allowances, and define a progress checkpoint and stopping condition. If the next block does not fit the remaining budget or has no clear purpose, narrow the task or stop before starting it.

Sources11

External pages this guide links to, in the order they appear. Last updated Oct 8, 2026.

  1. 1.OpenAI's API pricingdevelopers.openai.com/api/docs/pricing
  2. 2.OpenAI's authentication documentationlearn.chatgpt.com/docs/auth
  3. 3.ChatGPT-managed authentication for trusted automationlearn.chatgpt.com/docs/non-interactive-mode
  4. 4.Codex pricinglearn.chatgpt.com/docs/pricing
  5. 5.model's pricing notesdevelopers.openai.com/api/docs/models/gpt-6.1-sol
  6. 6.Source: prompt-caching guidedevelopers.openai.com/api/docs/guides/prompt-caching
  7. 7.OpenAI's metrics exampledevelopers.openai.com/cookbook/examples/agent_optimization/optimizing_agents_for_cost_and_quality
  8. 8.organization Usage referencedevelopers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/completions
  9. 9.Usage Dashboardhelp.openai.com/es-es/articles/10478918-reviewing-api-usage-and-costs
  10. 10.Costs referencedevelopers.openai.com/api/reference/resources/admin/subresources/organization/subresources/usage/methods/costs
  11. 11.Source: OpenAI spend limitsdevelopers.openai.com/api/docs/guides/spend-limits