[BUG] Cost not calculated for LLM Gateway interactions
Resolved 💬 5 comments Opened Jun 7, 2025 by MadsRC Closed Jan 15, 2026
Environment
- Platform (select one):
- [ ] Anthropic API
- [ ] AWS Bedrock
- [ ] Google Vertex AI
- [x] Other: LiteLLM Proxy 1.71.1
- Claude CLI version: 1.0.17 (Claude Code) <!-- output of
claude --version--> - Operating System: MacOS - Apple Silicon<!-- e.g. macOS 14.3, Windows 11, Ubuntu 22.04 -->
- Terminal: Warp.dev<!-- e.g. iTerm2, Terminal App -->
Bug Description
When using Claude Code with LiteLLM as the backend, token count, and costs, are not tracked.
Steps to Reproduce
- Set up LiteLLM Proxy
- Point Claude Code at LiteLLM Proxy (ANTHROPIC_BASE_URL)
- Prompt Claude Code
- Exit Claude Code <- Notice total tokens and pricing is 0
Expected Behavior
<!-- What you expected to happen -->
Spent tokens should be tracked and pricing info be updated.
Actual Behavior
<!-- What actually happened -->
Tokens: 0 input, 0 output, 0 cache read, 0 cache write
Additional Context
<!-- Add any other context about the problem here, such as screenshots, logs, etc. -->
Curl command to LiteLLM endpoint to verify token usage is included in the response:
curl "http://localhost:4000/v1/messages?beta=true" \
--header "x-api-key: someKey" \
--header 'anthropic-beta: claude-code-20250219,interleaved-thinking-2025-05-14' \
--header 'anthropic-dangerous-direct-browser-access: true' \
--header 'anthropic-version 2023-06-01' \
--header "content-type: application/json" \
--data \
'{
"model": "claude-sonnet-4-20250514",
"max_tokens": 100,
"messages": [
{"role": "user", "content": "Hello, world"}
]
}'
{"id":"msg_bdrk_014URjyq2jZ7Mrjfm1CpAtnp","type":"message","role":"assistant","model":"claude-sonnet-4-20250514","content":[{"type":"text","text":"Hello! Nice to meet you. How are you doing today? Is there anything I can help you with?"}],"stop_reason":"end_turn","stop_sequence":null,"usage":{"input_tokens":10,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":25}}This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗