SVG-first GitHub README cards, self-hosted on Vercel.
Lightweight, dependency-light, cache-aware, and designed for stable embeds.
Repository · Live Demo · Features · Deployment · API Endpoints
gh-stats is a minimal Vercel serverless service that generates GitHub profile cards as SVG or JSON output. It is built for profile READMEs, personal dashboards, and low-cost self-hosted usage.
The project currently focuses on a pragmatic feature set:
- GitHub stats card
- Top languages card
- Top repositories card
- Contribution streak card
- Theme-aware output for dark and light embeds
- JSON output for debugging and integrations
- Server-side and CDN caching support
- Static pre-generation workflow for near-zero runtime cost
The latest repository changes also introduce broader card foundations and presentation capabilities, including pin/gist/WakaTime-oriented renderers, expanded theme controls, richer language layouts, and extended diagnostics readiness.
|
|
|
|
|
|
- SVG-first output for clean GitHub README embedding
- Optional
format=jsonoutput for diagnostics and downstream integrations - Vercel serverless-friendly structure using
/api/* - TypeScript codebase with minimal runtime dependency surface
- CDN caching plus server-side cache support
ETagandIf-None-Matchsupport for efficient repeat requests- Stable SVG error cards instead of raw text failures
- Static pregeneration support for repository-committed SVG assets
- Theme support including built-in named themes and custom color overrides
- Configurable borders, border radius, icon colors, title colors, text colors, and background colors/gradients
- Enhanced language card layouts such as
normal,compact,donut,donut-vertical, andpie - Foundations for additional card types such as pinned repository, gist, and WakaTime renderers
gh-stats is positioned as a lean, understandable, self-hosted alternative for developers who want:
- lower hosting complexity
- straightforward TypeScript source code
- tighter control over GitHub token usage
- lighter operational cost through caching and pregeneration
- a smaller code surface that is easier to extend for personal branding
The hosted generator lets you preview cards and generate embed snippets from the browser:
- Live app:
https://gh-stats-gen.vercel.app/ - Health check:
https://gh-stats-gen.vercel.app/api/health - Limits:
https://gh-stats-gen.vercel.app/api/limits?format=json
Renders a GitHub profile stats card.
Purpose
- Repositories
- Followers
- Total stars
- Total forks
Examples
/api/stats?username=octocat&theme=dark
/api/stats?username=octocat&format=json
Renders a top repositories card for public repositories.
Options
count=1..10sort=stars|forks|updated
Examples
/api/repos?username=octocat&theme=dark&count=6&sort=stars
/api/repos?username=octocat&format=json&sort=updated
Renders a top languages card.
Modes
mode=primary— lower-cost default modemode=bytes— more accurate mode for language distribution
Examples
/api/languages?username=octocat&theme=dark
/api/languages?username=octocat&mode=bytes&theme=dark
/api/languages?username=octocat&format=json&mode=primary
Renders a contribution streak card using GitHub GraphQL contribution data.
Examples
/api/streak?username=octocat&theme=dark
/api/streak?username=octocat&format=json
Renders a gist related card using GitHub API.
Examples
/api/gist?id=aa5a315d61ae9438b18d
/api/gist?id=aa5a315d61ae9438b18d&theme=tokyonight&show_icons=true
/api/gist?id=aa5a315d61ae9438b18d&custom_title=Featured%20Gist&card_width=560
/api/gist?id=aa5a315d61ae9438b18d&format=json
Renders a wakatime related card using Wakatime API.
Examples
/api/wakatime?username=octocat
/api/wakatime?username=octocat&range=last_30_days
/api/wakatime?username=octocat&layout=donut&theme=tokyonight
/api/wakatime?username=octocat&format=json
Renders a pinned repository related card using GitHub API.
Examples
/api/pin?repo=SaumilP/gh-stats
/api/pin?repo=SaumilP/gh-stats&theme=tokyonight&show_icons=true
/api/pin?owner=SaumilP&name=gh-stats&show_owner=true&custom_title=Featured%20Repo
/api/pin?repo=SaumilP/gh-stats&format=json
Returns service diagnostics information.
Returns rate limit diagnostics in JSON form.
Most endpoints support these parameters:
username required GitHub username
theme dark | light | default | transparent | radical | merko | gruvbox | tokyonight | onedark | cobalt | synthwave | highcontrast | dracula
format svg | json
cacheSeconds cache header override within allowed clamp
refresh 1 to bypass server-side cache
compact 1 for smaller output where supported
The codebase now supports additional presentation controls such as:
title_color
text_color
icon_color
border_color
bg_color
hide_border
border_radius
bg_color also supports gradient-style input in the theme resolver.
The language renderer supports broader layout options:
layout=normal
layout=compact
layout=donut
layout=donut-vertical
layout=pie
hide_progress=true
maxReposForLanguages=5..50
<picture>
<source
srcset="https://YOUR_DOMAIN/api/stats?username=YOUR_USERNAME&theme=dark"
media="(prefers-color-scheme: dark)"
/>
<img
src="https://YOUR_DOMAIN/api/stats?username=YOUR_USERNAME&theme=light"
alt="GitHub stats card"
/>
</picture><a href="https://github.com/YOUR_USERNAME">
<img height="180" src="https://YOUR_DOMAIN/api/stats?username=YOUR_USERNAME&theme=dark" />
</a>
<a href="https://github.com/YOUR_USERNAME?tab=repositories">
<img height="180" src="https://YOUR_DOMAIN/api/languages?username=YOUR_USERNAME&theme=dark&layout=compact" />
</a>$> npm installFor local Vercel development:
$> npm install -g vercel
$> npm run vercel:devvercelGITHUB_TOKEN
GH_TOKEN
CACHE_ENABLED=true
KV_REST_API_URL
KV_REST_API_TOKEN
CACHE_TTL_STATS=21600
CACHE_TTL_REPOS=21600
CACHE_TTL_LANGUAGES=86400
CACHE_TTL_STREAK=21600
If you want minimal runtime cost for public README views, pre-generate SVGs and commit them into the repository.
GH_STATS_BASE_URL
GH_STATS_USERNAME
Use the pregeneration workflow to periodically refresh committed card assets and reference them directly from your profile README.
.github/workflows/
api/
cards/
lib/
public/
scripts/
README.md
package.json
tsconfig.json
vercel.json
api/— Vercel function entrypointscards/— SVG renderers and card composition logiclib/— query parsing, GitHub API helpers, theme resolution, ranking, diagnostics, formatting, response helperspublic/— static marketing page and public assetsscripts/— pregeneration support
The most recent work in the repository indicates a broader evolution beyond the initial four cards. The codebase now shows support or preparation for:
- richer theme/token handling
- custom color parameters
- border and radius customization
- advanced language-card layouts
- pinned repository card renderer
- gist card renderer
- WakaTime-oriented renderer
- extended health diagnostics coverage for newly introduced card categories
This makes the project more aligned with a self-hosted GitHub README card platform rather than a single-purpose stats endpoint set.
The repository includes a simple static landing page at / that previews cards and generates embed snippets.
Key homepage goals:
- explain the product quickly
- let users preview cards against a chosen username
- provide copy/paste embed snippets
- expose health and rate-limit diagnostics
- encourage self-hosting and low-cost usage patterns
- Minimal dependency footprint
- TypeScript-based codebase
- Cache-aware design to reduce upstream API pressure
- Friendly fallback cards instead of hard failures in embeds
- GitHub REST API
- GitHub GraphQL API
- Vercel
- The broader GitHub profile README ecosystem, including inspiration from
anuraghazra/github-readme-stats
MIT. See LICENSE for details.