(_ string)
| 59 | } |
| 60 | |
| 61 | func cmdTokens(_ string) { |
| 62 | stats, ok := rootAgent.Provider.(tokenReporter) |
| 63 | if !ok { |
| 64 | fmt.Println(ui.Dimmed("this provider doesn't report token usage")) |
| 65 | return |
| 66 | } |
| 67 | u := stats.TotalUsage() |
| 68 | cost := stats.EstimatedCostUSD() |
| 69 | fmt.Println(ui.Dimmed("session usage:")) |
| 70 | fmt.Printf(" input %s\n", ui.Cyan(formatThousands(u.InputTokens))) |
| 71 | fmt.Printf(" output %s\n", ui.Cyan(formatThousands(u.OutputTokens))) |
| 72 | if u.CacheCreationTokens > 0 || u.CacheReadTokens > 0 { |
| 73 | fmt.Printf(" cache write %s\n", ui.Cyan(formatThousands(u.CacheCreationTokens))) |
| 74 | fmt.Printf(" cache read %s\n", ui.Cyan(formatThousands(u.CacheReadTokens))) |
| 75 | } |
| 76 | if cost >= 0 { |
| 77 | fmt.Printf(" est. cost %s\n", ui.Cyan(fmt.Sprintf("$%.4f", cost))) |
| 78 | } else { |
| 79 | fmt.Printf(" est. cost %s\n", ui.Dimmed("(unknown model — no rate)")) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // formatThousands inserts thousands separators into a non-negative int. |
| 84 | func formatThousands(n int) string { |
nothing calls this directly
no test coverage detected