Repository navigation
ccusage fails when LiteLLM API is unavailable #13
Description
Activity
I see that OpenRouter also provides a public pricing query API endpoint.
API endpoint:https://openrouter.ai/api/v1/models
I'm wondering if this could be helpful for this project.Pricing Data Structure:
Each model returns pricing information including:"pricing": { "prompt": "0.000003", // Per-token prompt price "completion": "0.000015", // Per-token completion price "request": "0", // Fixed price per request "image": "0.0048", // Per-image price "web_search": "0", // Web search price "internal_reasoning": "0", // Internal reasoning price "input_cache_read": "0.0000003", // Input cache read "input_cache_write": "0.00000375" // Input cache write }Finally, by cloning the code locally and having Claude Code analyze it, I discovered the real cause of the problem. It is essentially still a network issue (mainland China network restrictions). Although I configured a proxy, it seems that for some reason the proxy cannot be used. The following is the resolution process organized by AI:
Problem
When running ccusage, encountered network connection error:
ERROR Failed to fetch model pricing: fetch failed
The tool was unable to access the LiteLLM pricing API at:
https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_
context_window.jsonRoot Cause
- Node.js v22.12.0 fetch API had connectivity issues in certain network
environments - Local proxy settings (https_proxy=http://127.0.0.1:8888) interfered
with the request - The issue persisted even when proxy environment variables were
disabled
Solution
Modified the pricing URL to use a GitHub mirror service:
Original URL:
https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.jsonCode Change:
In src/pricing-fetcher.ts, line 14:
const LITELLM_PRICING_URL =
"https://ghfast.top/https://raw.githubusercontent.com/BerriAI/litellm/
main/model_prices_and_context_window.json";Result
- ✅ Successfully loads 1053+ model pricing entries
- ✅ All ccusage functionality works normally
- ✅ No changes needed to the core logic
Alternative Workarounds
For users experiencing similar issues:
- Use --mode display to bypass network requests entirely
- Use --mode calculate only when network access is available
- Consider adding configurable mirror URL support for different regions
- Node.js v22.12.0 fetch API had connectivity issues in certain network
Hi
I know China has a complicated Internet network issue.
So if you have any solutions to solve this problem, just send a PR.@yonghao2011
My questions are- which is better, litellm or openrouter
- is the price info from litellm and openrouter same?
Also openrouter uses different model name.... 🤔
Looks like the key issue here is issue's author find that they cannot let ccusage use proxy to get past GFW.
Submitted a PR to fetch using proxy if HTTP(S)_PROXY env var is configured.Reacted by ryoppippi#51 this PR adds support for
--fetch local_model_price.jsonThen you can download and prepare the data file using whatever proxy you want
- added 6 commits that reference this issue
on Jun 8, 2026
首先感谢作者开发的这个工具,他很有意思,我把遇到的问题向您反馈下。
Background
I discovered this ccusage tool on X.com and found it very meaningful for tracking Claude usage. However, I encountered some issues during local testing that prevented the tool from working properly.
Given my limited technical expertise, I sought assistance from AI to help diagnose the problem. The AI provided some analysis and conclusions, but I'm not entirely certain about the accuracy of its findings. I'd appreciate it if you could review the investigation and let me know your thoughts.
Problem
ccusage becomes completely unusable when the LiteLLM API service is down, failing with "fetch failed" error during pricing data retrieval.
Error Details
Root Cause Investigation
Network connectivity test: ✅ Working fine
$ curl -I https://www.google.com # SuccessLiteLLM API status check: ❌ Service unavailable
$ curl -I https://api.litellm.ai/ HTTP/2 503 server: cloudflare x-render-routing: suspend $ curl -I https://api.litellm.ai/pricing HTTP/2 503Conclusion: The issue is caused by LiteLLM API returning HTTP 503 errors, not user configuration problems.
Impact
Proposed Solution: Multi-Source Pricing Fallback
Implement a robust fallback chain to eliminate dependency on single external service:
Fallback Chain Design
Implementation Benefits
Configuration Options
Additional Improvements
Alternative Data Sources
Expected User Experience
This architecture change would make ccusage much more reliable and user-friendly, ensuring it works even when external dependencies fail.