On November 25, I ran my Codex logs through agent-cost, a CLI I maintain that estimates costs from local usage records. It counted 13.07 million tokens from Fast mode and marked all of them unpriced.
The token counts were there. So was service_tier = priority, the setting for Fast. The clue was where that setting appeared in the log.
The setting came one line later
Here are the events that mattered, in the order Codex wrote them:
task_started Turn A begins turn_context Codex records the turn ID and model thread_settings_applied Codex records service_tier = priority for the thread token_count Codex records token usage Codex wrote the third line while it was still setting up the turn. It hadn't recorded any usage yet. My parser, though, saw a turn that had already started. It had read the opening records as normal mode, so it treated the next line as a switch to Fast during the turn. With two possible rates for the same usage, it left the cost unknown.
Taking the last setting in the file would have fixed this particular log. It would also have priced earlier tokens at the Fast rate whenever someone genuinely switched modes halfway through a turn. Investigation and fix (PR #37)
One millisecond changes the result
In v0.5.9, the parser can use the setting immediately after the first turn_context as the turn's initial setting. No usage can have been recorded yet. The parser also checks that the setting belongs to the same thread, the model matches, and no other turn overlaps. I set the cutoff at one second after turn_context. v0.5.9 changelog
To test that boundary, I built a synthetic log for gpt-6.2-sol with one million input tokens, zero cached tokens, and zero output tokens. Each case started with the same records pointing to normal mode. I changed only the setting and its timestamp.
Time after turn_context | Setting | v0.5.8 estimate | v0.5.9 estimate |
|---|---|---|---|
| 0.001 s | priority | Unpriced | Fast, $4 |
| 0.001 s | default | Normal, $2 | Normal, $2 |
| 1.000 s | priority | Unpriced | Fast, $4 |
| 1.001 s | priority | Unpriced | Unpriced |
The $4 and $2 figures come from the rate table bundled with each version, applied to the synthetic million-token input. The calculation excludes promotions and contract discounts. The usage log alone can't tell me what I was billed.
At exactly one second, v0.5.9 accepts priority. Move the timestamp forward one millisecond and the cost stays unknown. That one-second window belongs to my parser. It tells the parser when it can still treat the setting as part of turn setup. Regression test for the one-second boundary
When I reran the November 25 logs, the parser priced the priority turns as Fast. Some older Astra logs still had no service_tier at all. Those tokens stayed in the usage count with no dollar estimate. Results on the original logs
Reproduce it without a Codex account
You'll need Python 3.9 or later. Unzip the v0.5.9 source and run the following from the directory containing agent_cost/ on macOS or Linux. It writes four short logs in a temporary directory. To see the old behavior, run it unchanged from the v0.5.8 source.
python3 - <<'PY' from datetime import datetime, timedelta, timezone import json from pathlib import Path from tempfile import TemporaryDirectory from agent_cost.aggregate import price_fact from agent_cost.rates import load_rates from agent_cost.readers.codex import parse_rollout_facts def record(ms, kind, **payload): t = datetime(2026, 11, 20, 3, tzinfo=timezone.utc) + timedelta(milliseconds=ms) return {"type": kind, "timestamp": t.isoformat(timespec="milliseconds"), "payload": payload} def event(ms, name, **payload): return record(ms, "event_msg", type=name, **payload) model = "gpt-6.2-sol" rates = load_rates() with TemporaryDirectory() as tmp: path = Path(tmp) / "synthetic.jsonl" for tier, delay in [("priority", 1), ("default", 1), ("priority", 1000), ("priority", 1001)]: rows = [ event(-2000, "task_started", turn_id="A", collaboration_mode_kind="default"), record(0, "turn_context", turn_id="A", model=model), event(delay, "thread_settings_applied", thread_id="t1", thread_settings={"model": model, "model_provider_id": "openai", "service_tier": tier}), event(2000, "token_count", info={"total_token_usage": {"input_tokens": 1000000, "cached_input_tokens": 0, "output_tokens": 0}}), ] path.write_text("".join(json.dumps(r) + "\n" for r in rows)) (fact,), _, _ = parse_rollout_facts(path, model_raw=model, session_id="t1") usd, status, _ = price_fact(rates, fact) print(tier, delay, fact.tokens, fact.mode, status, usd) PY Here's the v0.5.9 output. The columns are the setting, delay in milliseconds, input tokens, detected mode, pricing status, and estimated USD:
priority 1 1000000 fast priced 4.000 default 1 1000000 normal priced 2.000 priority 1000 1000000 fast priced 4.000 priority 1001 1000000 unknown unpriced None Look at the last line: one million tokens, and None for the cost. Reporting $0 there would make the total look complete even though a million tokens had never been priced.
To run a report on your own Claude Code or Codex logs, use uvx --from coding-agent-cost agent-cost report. agent-cost quick start