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 93c7bef
Browse filesBrowse the repository at this point in the historyBrowse files
feat(grok): read cacheCreationTokens and document interrupted turns
Grok started writing `cacheCreationTokens` alongside `cachedReadTokens` around
CLI 0.2.118 and still writes it in 1.0.0. The adapter hardcoded
`cache_creation_input_tokens: 0`, so the field would be dropped the moment it
went non-zero.
Every turn observed so far reports it as zero, so there is no sample proving
whether it sits inside `inputTokens` or beside it. `cachedReadTokens` is
provably inside — session totals match `logs/unified.jsonl`, where
`cached_prompt_tokens` is part of `prompt_tokens` — so the sibling field is
carved out of the same total. That keeps the three parts summing back to
`inputTokens`, which is the invariant the adapter already relies on.
Also documents two limits that surfaced while checking real logs: a session
killed mid-turn never writes `turn_completed`, so its usage cannot be reported
at all, and `logs/unified.jsonl` cannot stand in for it because it records no
per-request model id.
Copy file name to clipboardExpand all lines: docs/guide/grok/index.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ $GROK_HOME/ # or ~/.grok
39
39
└── summary.json # optional metadata
40
40
```
41
41
42
-
Only rows with `sessionUpdate == "turn_completed"` and a usable usage breakdown are counted. In-progress turns are not included until they complete. `logs/unified.jsonl` is not used in this version.
42
+
Only rows with `sessionUpdate == "turn_completed"` and a usable usage breakdown are counted. In-progress turns are not included until they complete, and a session killed mid-turn never records one, so its usage cannot be reported. `logs/unified.jsonl` is not used as a source: it has no per-request model id, so its tokens cannot be priced or attributed to a model.
43
43
44
44
## Report Views
45
45
@@ -53,7 +53,7 @@ These views support `--json`, `--compact`, `--mode`, and `--offline`.
53
53
54
54
## What Gets Calculated
55
55
56
-
-**Token usage** - Grok records OpenAI-style usage where `inputTokens` includes cache. ccusage stores uncached input as `input − cachedRead`, cache as cache read, and full `outputTokens` as output.
56
+
-**Token usage** - Grok records OpenAI-style usage where `inputTokens` includes cache. ccusage splits it into uncached input, cache read (`cachedReadTokens`) and cache write (`cacheCreationTokens`), and stores the full `outputTokens` as output.
57
57
-**Reasoning tokens** - `reasoningTokens` are a subset of `outputTokens`, so they are already counted in the total. They are **not** added on top of output for either tokens or cost.
58
58
-**Precomputed cost** - Grok records `costUsdTicks` on each completed turn, in units of 1e-10 USD. ccusage uses it as the invoice cost, so `display` and the default `auto` report exactly what Grok billed.
59
59
-**Pricing** - `calculate`, and `auto` for turns that recorded no ticks, fall back to LiteLLM estimates. Model ids such as `grok-4.5-build` try candidates with the trailing `-build` stripped and `xai/` / `x-ai/` prefixes. A `turn_completed` row aggregates several API requests, so this fallback cannot reproduce Grok's per-request long-context tiering and only approximates the invoice.
let line = r#"{"timestamp":1750000000,"params":{"sessionId":"sess-1","update":{"sessionUpdate":"turn_completed","usage":{"inputTokens":100,"outputTokens":20,"cachedReadTokens":40,"cacheCreationTokens":25,"reasoningTokens":10,"modelUsage":{"grok-4.5-build":{"inputTokens":100,"outputTokens":20,"cachedReadTokens":40,"cacheCreationTokens":25,"reasoningTokens":10}}}},"_meta":{"eventId":"evt-cc"}}}"#;
0 commit comments