Code Line Counter

Enter a Git repository URL to get source code statistics using tokei.

Badge Feature

tokei-api provides dynamic badges that you can add to your README or other documentation. These badges visually display code statistics.

Available Badges

  • Lines of Code: Total lines of code
  • Top Language: Most used programming language
  • Languages: Number of languages used
  • Code to Comment: Ratio of code to comments
Lines of Code Top Language Languages Code to Comment

How to Use Badges

tokei-api provides badges for both GitHub repositories and any other Git repository. You can add these badges to your README or other documentation.

For GitHub Repositories

To add badges for a GitHub repository, use the following markdown format:

[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fowner%2Frepo%2Flines)](https://tokei.kojix2.net/github/owner/repo)

For example, badges for this project (tokei-api):

[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Ftokei-api%2Flines)](https://tokei.kojix2.net/github/kojix2/tokei-api)
[![Top Language](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Ftokei-api%2Flanguage)](https://tokei.kojix2.net/github/kojix2/tokei-api)
[![Languages](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Ftokei-api%2Flanguages)](https://tokei.kojix2.net/github/kojix2/tokei-api)
[![Code to Comment](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fbadge%2Fgithub%2Fkojix2%2Ftokei-api%2Fratio)](https://tokei.kojix2.net/github/kojix2/tokei-api)
For Any Git Repository

For repositories hosted on other platforms (GitLab, Bitbucket, etc.), first analyze the repository using the form above, then use the following markdown format:

[![Lines of Code](https://img.shields.io/endpoint?url=https%3A%2F%2Ftokei.kojix2.net%2Fapi%2Fbadge%2Flines%3Furl%3Dhttps%3A%2F%2Fexample.com%2Fuser%2Frepo.git)](https://example.com/user/repo)

Replace https://example.com/user/repo.git with your repository URL. You can use any of the badge types: lines, language, languages, or ratio.

Note: These badges are dynamic and will automatically reflect the latest analysis of your repository. For efficiency, analysis results are cached for 24 hours. If you've made changes to your repository and want to update the badge data, you can run a new analysis after the cache period expires.

GitHub Direct Access

You can directly access GitHub repositories using the following format:

https://tokei.kojix2.net/github/:owner/:repo

For example, to analyze the Crystal language repository:

https://tokei.kojix2.net/github/kojix2/tokei-api

This allows you to access analysis results directly without having to input the repository URL.

API Documentation

tokei-api provides a consistent RESTful API. The following endpoints are available:

Core API

  • POST /api/analyses - Analyze a repository
  • GET /api/analyses?url=... - Retrieve cached analysis result by repository URL
  • GET /api/analyses/:id - Retrieve a specific analysis result
  • GET /api/analyses/:id/languages - Get language statistics
  • GET /api/analyses/:id/badges/:type - Get badge data
  • GET /api/badge/:type?url=... - Retrieves badge data in Shields.io compatible format for the specified repository. Available badge types: lines, language, languages, ratio.

GitHub-specific API

  • GET /api/github/:owner/:repo - Analyze a GitHub repository
  • GET /api/github/:owner/:repo/languages - Get language statistics for a GitHub repository
  • GET /api/github/:owner/:repo/badges/:type - Get badge data for a GitHub repository

Usage Examples


// Analyze a repository
curl -X POST \
  -H "Content-Type: application/json" \
  -d '{"url":"https://github.com/kojix2/tokei-api"}' \
  https://tokei.kojix2.net/api/analyses

// Retrieve cached analysis result
curl "https://tokei.kojix2.net/api/analyses?url=https://github.com/kojix2/tokei-api"

// Analyze a GitHub repository directly
curl https://tokei.kojix2.net/api/github/kojix2/tokei-api

// Retrieve badge data for any Git repository
curl "https://tokei.kojix2.net/api/badge/lines?url=https://github.com/kojix2/tokei-api"