GitHub Stats Cards: Why They Break & How to Fix
In this article
GitHub stats cards break because they rely on GitHub's unauthenticated API, which has strict rate limits and can return incomplete data. To make them reliable, you need to either cache the API response, use a self-hosted service, or switch to a more stable data source.
Background: What Are GitHub Stats Cards?
GitHub stats cards are small, dynamically generated images that display a developer's public GitHub activity—such as total stars, commits, pull requests, and top languages. They're commonly embedded in personal README files, personal websites, or developer portfolios. The most popular service is github-readme-stats, an open-source project that generates these cards on the fly using GitHub's API.
The appeal is obvious: they provide a quick, visual summary of a developer's GitHub presence without requiring any manual updates. However, because they depend on an external API and a third-party server, they can fail for several reasons.
How GitHub Stats Cards Work
When you embed a stats card image URL in your README, the browser (or GitHub's markdown renderer) sends a request to a server (often github-readme-stats.vercel.app). That server then queries the GitHub REST API for your public profile data, processes it, and returns an SVG image. The entire process happens in real-time with each page view.
This architecture introduces several dependencies:
- GitHub API availability – GitHub's API has rate limits (typically 60 requests per hour per IP for unauthenticated requests).
- Server uptime – The service generating the card must be online.
- Network latency – A slow response can cause the image to time out.
Common Reasons Why Stats Cards Break
There are several distinct failure modes, each with its own cause:
- Rate limiting – The most common issue. If many people view your README in a short time, the API hits its hourly limit and returns a 403 error. The card then shows an error message or nothing at all.
- Invalid username – If you type your username incorrectly or change it, the API returns a 404, and the card displays a "User not found" error.
- Repository size limits – For language stats, the API only returns the first 100 repositories by default. If you have more, the percentages may be inaccurate or the card may fail to load.
- Theme or customization errors – Incorrect query parameters (e.g., a typo in
theme) can cause the card to render with default styling or not at all. - Server downtime – The public instance of github-readme-stats is free but not guaranteed to be up 100% of the time.
How to Make Your Stats Card Reliable
Here are practical steps to reduce breakage:
- Use a self-hosted instance – Deploy github-readme-stats on Vercel, Netlify, or your own server. This gives you control over rate limits and uptime. The project's README provides clear deployment instructions.
- Add caching – If self-hosting, configure a cache (e.g., Vercel's built-in caching) to store API responses for a few hours. This reduces the number of API calls.
- Use a personal access token – When self-hosting, set a
GITHUB_TOKENenvironment variable. This raises your API rate limit from 60 to 5,000 requests per hour, making rate limits a non-issue. - Check your username – Ensure the username in the URL exactly matches your GitHub handle. If you've changed it, update the URL.
- Limit repository count – For language stats, you can add
&count_private=trueand&include_all_commits=truebut be aware that these increase API calls. If you have many repos, consider using theexclude_repoparameter to skip large ones. - Use a fallback image – In your README, you can set an
onerrorattribute to show a static badge if the card fails to load. For example:<img src="...">.
Alternatives to GitHub Stats Cards
If you're tired of broken cards, consider these alternatives:
- Static badges – Use shields.io to create static badges that display your follower count or star count. They update less frequently but are highly reliable.
- GitHub's own profile README stats – You can manually update a table of your top languages or repos, but this requires effort.
- Other services – There are alternatives like
github-profile-summary-cardsthat generate a summary image but also rely on the API. - Embed a GitHub gist – Some developers create a gist that updates automatically via a GitHub Action, then embed that gist. This is more complex but fully under your control.
Comparing Self-Hosted vs. Public Service
The public instance of github-readme-stats is convenient but suffers from shared rate limits and occasional downtime. Self-hosting gives you:
- Higher rate limits – With a token, 5,000 requests/hour instead of 60.
- Customization – You can modify the code or add features.
- Reliability – You control the uptime, but you're responsible for maintenance.
However, self-hosting requires some technical knowledge and a free tier on a cloud provider (Vercel, Netlify, etc.). For most users, the public service is fine if you don't have high traffic. But if your README gets thousands of views, it's worth the effort to self-host.
Frequently Asked Questions
Why does my stats card show "Rate limit exceeded"?
This happens when the public instance has made too many requests from your IP address within an hour. The free GitHub API allows 60 requests per hour per IP. If you're viewing your README multiple times or many people are viewing it, the limit is hit. The fix is to self-host with a token or wait an hour.
Can I use a GitHub token with the public service?
No. The public instance does not accept tokens for security reasons. You must self-host to use your own token.
Why are my language percentages wrong?
The language stats are based on the repositories GitHub returns in the API response. By default, it only fetches the first 100 repositories. If you have more, the percentages are calculated from that subset. You can increase the limit by self-hosting and modifying the code, but it's easier to accept the approximation.
What is the best theme for a stats card?
There's no "best" theme; it depends on your README's background. Popular themes include dark, radical, and onedark. You can preview them in the github-readme-stats repo. If you want a custom color, use the title_color, text_color, and bg_color parameters.
Why does my card sometimes load slowly?
The public service can be slow during peak hours because it's handling many requests. Additionally, if you have many repositories, the API call takes longer. Self-hosting with caching can speed things up significantly.
Is it safe to embed stats cards in my README?
Yes, it's safe. The image is just an SVG/PNG, and the URL only contains your username and parameters. No sensitive data is exposed. However, be aware that the card reveals your public activity, which is already public on GitHub.