[BUG] Grossly underreported input tokens count when running through Google Vertex AI, leading to actual cost 16x higher than reported in CLI
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [x] Google Vertex AI
- [ ] Other: <!-- specify -->
- Claude CLI version: v0.2.105
- Operating System: Debian
- Terminal: VS Code Terminal
Bug Description
When using Claude Code thru Vertex AI, the reported usage is very much underreported.
Steps to Reproduce
- Set up Claude Code to use Vertex AI
- Use it
- After using it for a good amount, run
/cost
Expected Behavior
The /cost command should report the accurate cost.
Example from a session using Claude Code through Anthropic API directly:
> /cost
⎿ Total cost: $0.1556
Total duration (API): 2m 0.3s
Total duration (wall): 2m 19.0s
Total code changes: 36 lines added, 2 lines removed
Tokens: 11.7k base input, 33.2k cache write, 178.9k cache read, 1.9k base output
Notice how:
- base input has much bigger number than base output
- cache write and cache read shows an even bigger number
Actual Behavior
> /cost
⎿ Total cost: $0.4740
Total duration (API): 16m 52.8s
Total duration (wall): 1h 15m 51.7s
Total code changes: 258 lines added, 120 lines removed
Tokens: 356 base input, 0 cache write, 0 cache read, 31.5k base output
Notice how:
- base input is impossibly small
- cache write and cache read shows 0
This led to a wrong cost calculation, depicted in the below table:
| | |
| --- | --- |
| Cost reported by Claude Code | $0.47 |
| Cost billed to Google Cloud | $7.70 |
From the above comparison, Claude Code CLI underreported the actual cost by 16 times.
<img width="746" alt="Image" src="https://github.com/user-attachments/assets/d6e0d184-b1fa-401c-809f-042e50e8251d" />
The above image shows that Claude Code CLI correctly counts the base input / output tokens, but anything related to cache is not factored into cost.
Additional Context
N/A
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗