tokei-api provides a consistent RESTful API for analyzing code statistics in Git repositories.
POST /api/analyses
- Analyze a repositoryGET /api/analyses?url=...
- Retrieve cached analysis result by repository URLGET /api/analyses/:id
- Retrieve a specific analysis resultGET /api/analyses/:id/languages
- Get language statisticsGET /api/analyses/:id/badges/:type
- Get badge dataGET /api/badge/:type?url=...
- Retrieves badge data in Shields.io compatible format for the specified repository.
Available badge types: lines
, language
, languages
, ratio
.
GET /api/github/:owner/:repo
- Analyze a GitHub repositoryGET /api/github/:owner/:repo/languages
- Get language statistics for a GitHub repositoryGET /api/github/:owner/:repo/badges/:type
- Get badge data for a GitHub repositoryGET /badge/github/:owner/:repo/:type
- Simplified URL for retrieving badge data in shields.io compatible formatAvailable badge types: lines
, language
, languages
, ratio
// 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"
All API endpoints return JSON responses. Here's an example response from GET /api/github/:owner/:repo
:
{
"data": {
"id": "12345678-1234-1234-1234-123456789012",
"url": "https://github.com/kojix2/tokei-api",
"owner": "kojix2",
"repo": "tokei-api",
"analyzed_at": "2023-01-01T12:00:00Z",
"status": "completed",
"summary": {
"total_lines": 5000,
"total_code": 4000,
"total_comments": 500,
"total_blanks": 500,
"languages_count": 5,
"top_language": "Crystal",
"code_comment_ratio": 8.0
},
"languages": {
"Crystal": {
"files": 10,
"code": 3000,
"comments": 400,
"blanks": 300
},
"JavaScript": {
"files": 2,
"code": 500,
"comments": 50,
"blanks": 100
},
"...": {}
},
"links": {
"self": "/api/github/kojix2/tokei-api",
"languages": "/api/github/kojix2/tokei-api/languages",
"web": "/github/kojix2/tokei-api",
"badges": {
"lines": "/api/github/kojix2/tokei-api/badges/lines",
"language": "/api/github/kojix2/tokei-api/badges/language",
"languages": "/api/github/kojix2/tokei-api/badges/languages",
"ratio": "/api/github/kojix2/tokei-api/badges/ratio"
}
}
}
}
In case of an error, the API returns an appropriate HTTP status code along with a JSON error response:
{
"error": {
"code": "invalid_request",
"message": "Invalid repository URL",
"status": 400
}
}