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
Commit e77dc73
Browse filesBrowse the repository at this point in the historyBrowse files
refactor(cli): remove --mode credits in favor of era-aware auto
Piece D made `--mode auto` era-aware: it prefers AI Credits
(`totalNanoAiu × $0.01`) whenever the source ships them, falling
back to premium-request × $0.04 for pre-cutover Copilot data. That
left `--mode credits` (added earlier in Piece B) doing almost
exactly what `auto` already does for post-cutover sessions, with
only one meaningful difference: `credits` strictly returned $0 for
any row without AIU, where `auto` would attempt a more accurate
fallback.
Dropping `credits` collapses the user-facing mode surface to the
minimum needed for the post-cutover billing world we're moving into
(`auto` / `display` / `calculate`+`api-equiv`) without losing
any actually useful behavior:
- The raw AI Credit count is still exposed on every Copilot JSON
row as the `credits` field, so callers who want it can read it
directly regardless of `--mode`.
- `auto` already produces the same numbers as the old `credits`
mode for every post-cutover session.
- For users who want strict source-precomputed billing, `display`
walks the same AIU → premium-requests ladder.
Changes:
- `ccusage-cli/src/types.rs`: drop `CostMode::Credits` variant.
- `ccusage-cli/src/parser.rs`: drop `"credits"` arm and its test.
- `ccusage-cli/src/cli-help.json` and `help_codegen.rs`: remove
"credits" from the `--mode` choices list.
- `config_schema.rs`: drop `ConfigCostMode::Credits` so the
generated JSON schemas no longer expose the value.
- `config.rs`: drop the corresponding `From` arm.
- `cost.rs`, `adapter/gemini/parser.rs`, `adapter/kilo/parser.rs`,
`adapter/kimi/parser.rs`: remove their `CostMode::Credits` match
arms now that the variant is gone.
- `adapter/copilot/loader.rs`: drop the Credits dispatch branch and
delete one redundant test (`credits_mode_bills_from_nano_aiu_…`
was a strict subset of `auto_mode_prefers_credits_when_aiu_is_…`).
Convert the three remaining `credits_mode_*` tests to exercise
the same regressions under `--mode auto`:
zero-token-credit-only rows still bill from AIU, identical
credit-only snapshots still collapse via content-based dedup, and
the synthetic aggregate-AIU row still bills.
- Regenerated schema files and accepted the schema snapshot diff
(only the "credits" enum value disappears).
- Docs: removed the `credits` mode from
`docs/guide/cost-modes.md`, `docs/guide/cli-options.md`,
`docs/guide/copilot/index.md`, and the adapter README.
Verified: 327 workspace tests pass. Smoke against
`~/.copilot/session-state/` still reports 74 days / $6,473.65 in
`--mode auto --offline` — identical to the pre-removal baseline.
`--mode credits` is now rejected with "Invalid cost mode 'credits'".
Refs ccusage#1174
Co-authored-by: Copilot <[email protected]>
Copy file name to clipboardExpand all lines: docs/guide/copilot/index.md
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,13 +51,12 @@ These views support `--json` for structured output, `--compact` for narrow termi
51
51
52
52
## Pricing modes
53
53
54
-
`ccusage copilot` supports the standard cost modes plus a Copilot-specific `credits` mode and an `api-equiv` discoverability alias. For Copilot, the modes map to billing realities as follows:
54
+
`ccusage copilot` supports the standard cost modes plus an `api-equiv` discoverability alias. For Copilot, the modes map to billing realities as follows:
55
55
56
56
| Mode | What it shows for Copilot |
57
57
|---|---|
58
58
|`auto` (default) |**True bill, era-aware**: AI Credits for post-cutover sessions (CLI ≥ 1.0.40), premium-request × $0.04 for pre-cutover sessions, token-priced for sessions with neither billing field |
59
59
|`display`| Source-precomputed only: AI Credits → premium-requests → `$0.00`. No token-priced fallback |
60
-
|`credits`| Always AI Credits (`$0.00` when source has no `totalNanoAiu`) |
61
60
|`calculate` / `api-equiv`| Always LiteLLM token pricing — what the same usage would have cost via the underlying provider's API |
62
61
63
62
Why era-aware? GitHub Copilot switched billing models on June 1, 2026: pre-cutover sessions were billed as "premium requests" with per-model multipliers at $0.04 per overage request; post-cutover sessions bill as AI Credits at $0.01 per credit. The Copilot CLI records each session's own billing data, so `auto` reports what GitHub actually charged you for that session — whichever era it belongs to.
@@ -66,9 +65,6 @@ Why era-aware? GitHub Copilot switched billing models on June 1, 2026: pre-cutov
66
65
# Default: era-aware true bill (AI Credits for new days, premium-requests for old).
67
66
ccusage copilot daily
68
67
69
-
# Always-credits: only counts AI Credits, returns $0 for pre-cutover days.
70
-
ccusage copilot daily --mode credits
71
-
72
68
# API-equivalent: what direct Anthropic/OpenAI/Google calls would have cost.
ccusage reads `totalNanoAiu` from each `session.shutdown` event and converts directly to USD (`credits × $0.01`). For pre-cutover sessions without AIU, it falls back to `requests.cost × $0.04`. No LiteLLM pricing lookup happens in `credits`/`display` mode, so newer Copilot model variants that aren't yet in the LiteLLM dataset still report correct cost. The `credits` field is exposed in `--json` output regardless of the selected mode, so you can run with the default and still see the raw credit count.
76
+
ccusage reads `totalNanoAiu` from each `session.shutdown` event and converts directly to USD (`credits × $0.01`). For pre-cutover sessions without AIU, it falls back to `requests.cost × $0.04`. No LiteLLM pricing lookup happens in `display` mode, so newer Copilot model variants that aren't yet in the LiteLLM dataset still report correct cost. The `credits` field is exposed in `--json` output regardless of the selected mode, so you can always see the raw credit count.
81
77
82
78
Credit-only `session.shutdown` rows (zero tokens, zero requests, non-null `totalNanoAiu`) are kept even when the default skip rule would otherwise discard them. Identical duplicate credit-only snapshots within the same session are collapsed via content-based deduplication. Pre-cutover free-tier models (sonnet, haiku with `requests.cost == 0`) genuinely cost $0 under the premium-request plan and are billed as such — not as their token-priced equivalent.
83
79
@@ -88,8 +84,8 @@ See [Cost Modes](/guide/cost-modes) for the full mode reference.
88
84
-**Token usage** — `inputTokens` in the session-state source schema already includes both cache reads and cache writes, so ccusage subtracts both to recover the "fresh" input bucket.
89
85
-**Cache tokens** — cache read and cache creation tokens are counted from the source's `cacheReadTokens` / `cacheWriteTokens` fields.
90
86
-**Reasoning tokens** — provider-dependent. For OpenAI (`gpt-*`) and Anthropic (`claude-*`) models reasoning is already inside `outputTokens` and is not double-counted. For Google (`gemini-*`) models reasoning is reported separately and is summed into the output cost bucket.
91
-
-**Credits** — when present, `totalNanoAiu` is divided by 10⁹ to get the AI Credit count (`1 credit = $0.01`). Always surfaced in JSON; becomes the primary cost basis under `--mode credits`.
92
-
-**Pricing** — for non-credits modes, costs are calculated from LiteLLM pricing data using a normalized form of the model name. The raw name (e.g. `claude-opus-4.7-1m-internal`) is preserved in JSON, the table's `Models` column, and `modelsUsed`.
87
+
-**Credits** — when present, `totalNanoAiu` is divided by 10⁹ to get the AI Credit count (`1 credit = $0.01`). Always surfaced in JSON. Drives the cost figure under `auto` / `display` when present.
88
+
-**Pricing** — for `calculate` / `api-equiv` mode, costs are computed from LiteLLM pricing data using a normalized form of the model name. The raw name (e.g. `claude-opus-4.7-1m-internal`) is preserved in JSON, the table's `Models` column, and `modelsUsed`.
Copy file name to clipboardExpand all lines: docs/guide/cost-modes.md
+4-57Lines changed: 4 additions & 57 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Cost Modes
2
2
3
-
ccusage supports four cost calculation modes to handle various scenarios and data sources. Understanding these modes helps you get the most accurate cost estimates for your usage analysis.
3
+
ccusage supports three cost calculation modes to handle various scenarios and data sources. Understanding these modes helps you get the most accurate cost estimates for your usage analysis.
4
4
5
5
## Overview
6
6
@@ -9,7 +9,6 @@ Claude Code stores usage data in JSONL files with both token counts and pre-calc
9
9
-**`auto`** - Smart mode using the best available data
10
10
-**`calculate`** (also aliased as **`api-equiv`**) - Always calculate from token counts (LiteLLM pricing)
11
11
-**`display`** - Only show pre-calculated costs
12
-
-**`credits`** - Bill from GitHub Copilot's AI Credit counts at `1 credit = $0.01` (Copilot-specific; other adapters fall back to `auto`)
13
12
14
13
## Mode Details
15
14
@@ -63,9 +62,9 @@ ccusage daily --mode calculate
63
62
ccusage monthly --mode calculate --breakdown
64
63
65
64
# `api-equiv` is an alias for `calculate` (same behavior — bills from
66
-
# LiteLLM token pricing). Use it for parity in CLIs that already accept
67
-
#`--mode credits`, where naming the api-equivalent intent explicitly
68
-
#improves discoverability.
65
+
# LiteLLM token pricing). The shorter, intent-revealing name is useful
66
+
#for Copilot reports where you want to contrast the "API-equivalent"
67
+
#cost against `auto`'s "what Copilot actually billed" figure.
|`auto`| True bill, era-aware: AIU when present (post-cutover) → premium-requests × $0.04 when present (pre-cutover) → token-priced via LiteLLM (no billing fields). The default. Free-tier pre-cutover rows (`requests.cost == 0`) bill as $0. |
|`credits`| Always AIU: `totalNanoAiu × $0.01` or $0.00 if absent. |
97
96
|`calculate` / `api-equiv`| Always token-priced via LiteLLM (`normalize_copilot_model()` applied at both `calculate_cost_for_usage` and `missing_pricing_model_for_usage` call sites). |
98
97
99
98
The era-aware default reflects that GitHub Copilot switched billing models on
@@ -107,11 +106,12 @@ session.
107
106
source carried `totalNanoAiu`, so JSON consumers see the raw credit count
108
107
regardless of mode selection.
109
108
110
-
The `missing_pricing_model` warning is Copilot-locally suppressed under
111
-
`Credits` and `Display` modes (no LiteLLM lookup happens) — the shared
112
-
`cost.rs::missing_pricing_model_for_usage` early-return is untouched so other
113
-
adapters that fall back to `Auto` under `--mode credits` still see their
114
-
legitimate missing-pricing warnings.
109
+
The `missing_pricing_model` warning never fires for the AIU and premium-request
110
+
branches of `auto`/`display` because they don't consult LiteLLM — those
111
+
branches return `None` directly. The shared
112
+
`cost.rs::missing_pricing_model_for_usage` early-return remains intact so other
113
+
adapters still see legitimate missing-pricing warnings when their token-pricing
0 commit comments