feat(usage): include Grok Build in the usage view #6051
ClosedEliasofIX(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/6051/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/web/src/components/usage/usageProviders.ts line 10OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1,10 +1,10 @@11 import type { UsageProviderKind } from "@t3tools/contracts";223-import { ClaudeAI, type Icon, OpenAI } from "../Icons";3+import { ClaudeAI, GrokIcon, type Icon, OpenAI } from "../Icons";4455 /**6- * Series and table order. The chart layers both providers from a shared zero6+ * Series and table order. The chart layers providers from a shared zero77 * baseline, so this only fixes the reading order of legends, tables and hover88 * rows; it does not decide which series sits above the other.99 */10-export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];10+export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "grok"];apps/web/src/components/usage/usageProviders.ts line 10OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1,10 +1,10 @@11 import type { UsageProviderKind } from "@t3tools/contracts";223-import { ClaudeAI, type Icon, OpenAI } from "../Icons";3+import { ClaudeAI, GrokIcon, type Icon, OpenAI } from "../Icons";4455 /**6- * Series and table order. The chart layers both providers from a shared zero6+ * Series and table order. The chart layers providers from a shared zero77 * baseline, so this only fixes the reading order of legends, tables and hover88 * rows; it does not decide which series sits above the other.99 */10-export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];10+export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "grok"];
- apps/web/src/components/usage/usageProviders.ts line 10OutdatedResolvedby EliasofIX(GitHub profile, opens in a new tab)@@ -1,10 +1,10 @@11 import type { UsageProviderKind } from "@t3tools/contracts";223-import { ClaudeAI, type Icon, OpenAI } from "../Icons";3+import { ClaudeAI, GrokIcon, type Icon, OpenAI } from "../Icons";4455 /**6- * Series and table order. The chart layers both providers from a shared zero6+ * Series and table order. The chart layers providers from a shared zero77 * baseline, so this only fixes the reading order of legends, tables and hover88 * rows; it does not decide which series sits above the other.99 */10-export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];10+export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "grok"];apps/server/src/usage/usageTranscripts.ts line 455OutdatedResolvedby EliasofIX(GitHub profile, opens in a new tab)@@ -299,0 +435,21 @@435+ provider: "grok",436+ timestampMs,437+ model: "grok",438+ sessionId,439+ totals: grokTotalsToUsage(topLevel),440+ reportedCostUsd: grokCostTicksToUsd(topLevel.costUsdTicks),441+ dedupeKey: promptId === null ? null : `${sessionId}:${promptId}:grok`,442+ },443+ ];444+ }445+446+ const results: UsageRecord[] = [];447+ for (const entry of modelEntries) {448+ const totals = grokTotalsToUsage(entry.totals);449+ if (totalTokens(totals) === 0) continue;450+451+ // Per-model ticks when present; otherwise a single-model turn may inherit452+ // the aggregate. Multi-model turns without per-model ticks stay unpriced453+ // at the provider-reported layer and fall through to the rate table.454+ let reportedCostUsd = grokCostTicksToUsd(entry.totals.costUsdTicks);455+ if (reportedCostUsd === null && modelEntries.length === 1) {apps/web/src/components/usage/usageProviders.ts line 22OutdatedResolvedby EliasofIX(GitHub profile, opens in a new tab)@@ -5,16 +5,18 @@55 /**6- * Series and table order. The chart layers both providers from a shared zero6+ * Series and table order. The chart layers providers from a shared zero77 * baseline, so this only fixes the reading order of legends, tables and hover88 * rows; it does not decide which series sits above the other.99 */10-export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude"];10+export const PROVIDER_ORDER: readonly UsageProviderKind[] = ["codex", "claude", "grok"];11111212 export const PROVIDER_LABEL: Record<UsageProviderKind, string> = {1313 claude: "Claude Code",1414 codex: "Codex",15+ grok: "Grok Build",1516 };161717-/** Claude's brand orange against a neutral white for Codex. */18+/** Claude's brand orange, neutral white for Codex, slate for Grok. */1819 export const PROVIDER_COLOR: Record<UsageProviderKind, string> = {1920 claude: "#d97757",2021 codex: "#e6e6e6",22+ grok: "#a1a1aa",apps/server/src/usage/usageTranscripts.ts line 435Resolvedby EliasofIX(GitHub profile, opens in a new tab)@@ -299,0 +417,21 @@417+ if (topLevel === null) return [];418+419+ const modelUsage = usageRecord["modelUsage"];420+ const modelEntries: Array<{ model: string; totals: GrokUsageTotals }> = [];421+ if (typeof modelUsage === "object" && modelUsage !== null) {422+ for (const [model, raw] of Object.entries(modelUsage as Record<string, unknown>)) {423+ if (model.length === 0) continue;424+ const totals = readGrokUsageTotals(raw);425+ if (totals === null) continue;426+ modelEntries.push({ model, totals });427+ }428+ }429+430+ // Older turns (or incomplete writes) may only carry the aggregate usage blob.431+ if (modelEntries.length === 0) {432+ if (totalTokens(grokTotalsToUsage(topLevel)) === 0) return [];433+ return [434+ {435+ provider: "grok",436+ timestampMs,437+ model: "grok",
- apps/server/src/usage/usageTranscripts.ts line 467Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -299,0 +436,21 @@436+ sessionId,437+ totals: grokTotalsToUsage(topLevel),438+ reportedCostUsd: grokCostTicksToUsd(topLevel.costUsdTicks),439+ dedupeKey: promptId === null ? null : `${sessionId}:${promptId}:grok`,440+ },441+ ];442+ }443+444+ // When every per-model entry lacks ticks but the aggregate reports them,445+ // pro-rate the top-level ticks by each model's token share so provider cost446+ // is not discarded on multi-model turns (rate-table fallback can still miss447+ // slugs). Single-model turns simply inherit the aggregate below.448+ const anyPerModelTicks = modelEntries.some((entry) => entry.totals.costUsdTicks !== null);449+ const topLevelCostUsd = grokCostTicksToUsd(topLevel.costUsdTicks);450+ let sharedTokenDenominator = 0;451+ if (!anyPerModelTicks && topLevelCostUsd !== null && modelEntries.length > 1) {452+ for (const entry of modelEntries) {453+ sharedTokenDenominator += totalTokens(grokTotalsToUsage(entry.totals));454+ }455+ }456+
- apps/server/src/usage/usageTranscripts.ts line 451OutdatedResolvedby EliasofIX(GitHub profile, opens in a new tab)@@ -299,0 +431,21 @@431+ return [432+ {433+ provider: "grok",434+ timestampMs,435+ model: "grok",436+ sessionId,437+ totals: grokTotalsToUsage(topLevel),438+ reportedCostUsd: grokCostTicksToUsd(topLevel.costUsdTicks),439+ dedupeKey: promptId === null ? null : `${sessionId}:${promptId}:grok`,440+ },441+ ];442+ }443+444+ // When every per-model entry lacks ticks but the aggregate reports them,445+ // pro-rate the top-level ticks by each model's token share so provider cost446+ // is not discarded on multi-model turns (rate-table fallback can still miss447+ // slugs). Single-model turns simply inherit the aggregate below.448+ // Only count ticks on entries the emit loop would keep: zero-token siblings449+ // (often costUsdTicks: 0) must not suppress aggregate pro-rating for450+ // billable models that omit per-model ticks.451+ const anyPerModelTicks = modelEntries.some(
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
768538bd-fb54-4ea7-ae9f-9a73bed604b0You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share