Skip to content

Commit e77dc73

Browse files
jay-tauCopilot
andcommitted
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]>
1 parent 7312ac0 commit e77dc73

17 files changed

Lines changed: 58 additions & 265 deletions

File tree

‎apps/ccusage/config-schema.json‎

Lines changed: 0 additions & 69 deletions
Large diffs are not rendered by default.

‎docs/guide/cli-options.md‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ ccusage daily --mode api-equiv
5454

5555
# Display mode - only show pre-calculated costUSD
5656
ccusage daily --mode display
57-
58-
# Credits mode (Copilot-specific) - bill from GitHub Copilot AI Credits
59-
ccusage copilot daily --mode credits
6057
```
6158

6259
See [Cost Modes](/guide/cost-modes) for a full breakdown of each mode.

‎docs/guide/copilot/index.md‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,12 @@ These views support `--json` for structured output, `--compact` for narrow termi
5151

5252
## Pricing modes
5353

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:
5555

5656
| Mode | What it shows for Copilot |
5757
|---|---|
5858
| `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 |
5959
| `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`) |
6160
| `calculate` / `api-equiv` | Always LiteLLM token pricing — what the same usage would have cost via the underlying provider's API |
6261

6362
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
6665
# Default: era-aware true bill (AI Credits for new days, premium-requests for old).
6766
ccusage copilot daily
6867

69-
# Always-credits: only counts AI Credits, returns $0 for pre-cutover days.
70-
ccusage copilot daily --mode credits
71-
7268
# API-equivalent: what direct Anthropic/OpenAI/Google calls would have cost.
7369
# Useful for justifying the Copilot subscription.
7470
ccusage copilot daily --mode api-equiv
@@ -77,7 +73,7 @@ ccusage copilot daily --mode api-equiv
7773
ccusage copilot daily --mode display
7874
```
7975

80-
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.
8177

8278
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.
8379

@@ -88,8 +84,8 @@ See [Cost Modes](/guide/cost-modes) for the full mode reference.
8884
- **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.
8985
- **Cache tokens** — cache read and cache creation tokens are counted from the source's `cacheReadTokens` / `cacheWriteTokens` fields.
9086
- **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`.
9389

9490
## Environment Variables
9591

‎docs/guide/cost-modes.md‎

Lines changed: 4 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Cost Modes
22

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

55
## Overview
66

@@ -9,7 +9,6 @@ Claude Code stores usage data in JSONL files with both token counts and pre-calc
99
- **`auto`** - Smart mode using the best available data
1010
- **`calculate`** (also aliased as **`api-equiv`**) - Always calculate from token counts (LiteLLM pricing)
1111
- **`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`)
1312

1413
## Mode Details
1514

@@ -63,9 +62,9 @@ ccusage daily --mode calculate
6362
ccusage monthly --mode calculate --breakdown
6463

6564
# `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.
6968
ccusage copilot daily --mode api-equiv
7069
```
7170

@@ -130,58 +129,6 @@ ccusage session --mode display --json
130129
└──────────────┴─────────────┴────────┴─────────┴────────────┘
131130
```
132131

133-
### credits (Copilot-specific)
134-
135-
The `credits` mode bills usage from GitHub Copilot's AI Credit counts at the
136-
official `1 credit = $0.01` rate, instead of computing from LiteLLM token
137-
pricing:
138-
139-
```bash
140-
ccusage copilot daily --mode credits
141-
ccusage copilot monthly --mode credits --json
142-
```
143-
144-
#### How it works:
145-
146-
1. **Reads `totalNanoAiu`** from each `session.shutdown` event in
147-
`~/.copilot/session-state/<sessionId>/events.jsonl`.
148-
2. **Converts to USD** using `credits × $0.01` (Copilot's published rate).
149-
3. **No token-based pricing lookup** — the cost is taken directly from the
150-
credit count the CLI itself reported.
151-
4. **Skips the "Missing embedded pricing" warning** even for newer model
152-
variants that aren't yet in LiteLLM, since pricing isn't consulted.
153-
154-
#### Best for:
155-
156-
- ✅ **Copilot CLI billing** — matches what GitHub charges against your AI
157-
Credit allotment.
158-
- ✅ **Newer model variants** — works correctly even when LiteLLM doesn't yet
159-
have an entry for the model.
160-
- ✅ **Aggregate visibility** — the JSON `credits` field reports the raw
161-
credit count alongside `totalCost`.
162-
163-
#### Non-Copilot adapters
164-
165-
`--mode credits` is Copilot-specific. Other adapters (Claude, Codex, Amp, etc.)
166-
do not carry credit counts. When you set `--mode credits` on a non-Copilot
167-
report they fall back to `Auto` semantics — i.e. they continue to compute from
168-
token pricing as if no mode override was set. Cross-source `ccusage all
169-
--mode credits` will use credits for the Copilot rows and tokens for everything
170-
else.
171-
172-
#### Example output:
173-
174-
```
175-
┌──────────────┬──────────────────────────────┬────────┬─────────┬────────────┐
176-
│ Date │ Models │ Input │ Output │ Cost (USD) │
177-
├──────────────┼──────────────────────────────┼────────┼─────────┼────────────┤
178-
│ 2026-05-19 │ • opus-4.7-1m-internal │ 2,944 │ 225,556 │ $10.55 │
179-
└──────────────┴──────────────────────────────┴────────┴─────────┴────────────┘
180-
```
181-
182-
The corresponding JSON row carries `"credits": 1055.18` alongside
183-
`"totalCost": 10.55` so callers can recover the raw credit count.
184-
185132
## Practical Examples
186133

187134
### Scenario 1: Mixed Data Analysis

‎rust/crates/ccusage-cli/src/cli-help.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@
250250
"flags": "-m, --mode [mode]",
251251
"description": "Cost calculation mode",
252252
"default": "auto",
253-
"choices": ["auto", "calculate", "display", "credits", "api-equiv"]
253+
"choices": ["auto", "calculate", "display", "api-equiv"]
254254
},
255255
{
256256
"flags": "-d, --debug",

‎rust/crates/ccusage-cli/src/help_codegen.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,13 @@ mod tests {
366366
"flags": "--mode <MODE>",
367367
"description": "Cost calculation mode",
368368
"default": "auto",
369-
"choices": ["auto", "calculate", "display", "credits", "api-equiv"]
369+
"choices": ["auto", "calculate", "display", "api-equiv"]
370370
}
371371
]);
372372

373373
let output = render_options(&options);
374374

375375
assert!(output.contains("default: auto"));
376-
assert!(output.contains("choices: auto | calculate | display | credits | api-equiv"));
376+
assert!(output.contains("choices: auto | calculate | display | api-equiv"));
377377
}
378378
}

‎rust/crates/ccusage-cli/src/parser.rs‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -863,12 +863,11 @@ fn parse_cost_mode(value: &str) -> Result<CostMode, String> {
863863
match value {
864864
"auto" => Ok(CostMode::Auto),
865865
// `api-equiv` is a discoverability alias for `calculate` — both
866-
// bill from LiteLLM token pricing. The alias makes the
867-
// api-equivalent intent explicit in `--help` output alongside the
868-
// new `credits` mode, without expanding the `CostMode` enum.
866+
// bill from LiteLLM token pricing. The alias names the
867+
// api-equivalent intent explicitly in `--help` without expanding
868+
// the `CostMode` enum.
869869
"calculate" | "api-equiv" => Ok(CostMode::Calculate),
870870
"display" => Ok(CostMode::Display),
871-
"credits" => Ok(CostMode::Credits),
872871
_ => Err(format!("Invalid cost mode '{value}'")),
873872
}
874873
}
@@ -952,16 +951,13 @@ mod tests {
952951
assert_eq!(parse_cost_mode("auto"), Ok(CostMode::Auto));
953952
assert_eq!(parse_cost_mode("calculate"), Ok(CostMode::Calculate));
954953
assert_eq!(parse_cost_mode("display"), Ok(CostMode::Display));
955-
assert_eq!(parse_cost_mode("credits"), Ok(CostMode::Credits));
956954
}
957955

958956
#[test]
959957
fn parse_cost_mode_api_equiv_aliases_calculate() {
960958
// `api-equiv` is a discoverability alias for `calculate` — both
961-
// bill from LiteLLM token pricing. The alias is intentional: users
962-
// should be able to write the api-equivalent intent explicitly
963-
// alongside the new Copilot-specific `credits` mode without needing
964-
// a new enum variant.
959+
// bill from LiteLLM token pricing. Surfaces the api-equivalent
960+
// intent in `--help` without expanding the `CostMode` enum.
965961
assert_eq!(parse_cost_mode("api-equiv"), Ok(CostMode::Calculate));
966962
}
967963

‎rust/crates/ccusage-cli/src/types.rs‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,6 @@ pub enum CostMode {
173173
Auto,
174174
Calculate,
175175
Display,
176-
/// Bill from precomputed credit counts (Copilot CLI's AI-credit tracking).
177-
/// Non-Copilot adapters fall back to `Auto` semantics.
178-
Credits,
179176
}
180177

181178
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]

‎rust/crates/ccusage/src/adapter/copilot/README.md‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ Rules:
9393
| -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
9494
| `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. |
9595
| `display`| Source-precomputed only: AIU → premium-requests → $0. No token-priced fallback. |
96-
| `credits`| Always AIU: `totalNanoAiu × $0.01` or $0.00 if absent. |
9796
| `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). |
9897

9998
The era-aware default reflects that GitHub Copilot switched billing models on
@@ -107,11 +106,12 @@ session.
107106
source carried `totalNanoAiu`, so JSON consumers see the raw credit count
108107
regardless of mode selection.
109108

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
114+
fallback can't resolve a model.
115115

116116
## Dedup
117117

0 commit comments

Comments
 (0)