SkillAgentSearch skills...

Tokentoll

🐾 TokenToll: is a self-hostable billing infrastructure for LLM APIs and SaaS products. Drop-in SDKs for Node.js and Python, YAML-defined pricing plans, Stripe adapter, and a real-time usage dashboard | The open-source alternative to Lago and Orb.

Install / Use

/learn @AlameerAshraf/Tokentoll
About this skill

Quality Score

0/100

Category

Operations

Supported Platforms

Universal

README

<div align="center"> <br /> <img src="https://img.shields.io/badge/🐾_TokenToll-Usage_Based_Billing-FF6B35?style=for-the-badge&labelColor=1a1a2e" alt="TokenToll" /> <br /> <br /> <h3>The open-source billing engine for AI & SaaS products</h3> <p><i>Meter tokens. Enforce quotas. Invoice automatically.</i></p> <br />

<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square" alt="License: MIT" /></a> <a href="https://www.python.org/"><img src="https://img.shields.io/badge/Python-3.11+-3776AB?style=flat-square&logo=python&logoColor=white" alt="Python" /></a> <a href="https://fastapi.tiangolo.com/"><img src="https://img.shields.io/badge/FastAPI-0.109+-009688?style=flat-square&logo=fastapi&logoColor=white" alt="FastAPI" /></a> <a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-5.0+-3178C6?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript" /></a> <a href="https://www.mongodb.com/"><img src="https://img.shields.io/badge/MongoDB-7-47A248?style=flat-square&logo=mongodb&logoColor=white" alt="MongoDB" /></a> <a href="https://redis.io/"><img src="https://img.shields.io/badge/Redis-7-DC382D?style=flat-square&logo=redis&logoColor=white" alt="Redis" /></a> <a href="https://www.docker.com/"><img src="https://img.shields.io/badge/Docker-Ready-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker" /></a> <a href="https://stripe.com/"><img src="https://img.shields.io/badge/Stripe-Integrated-635BFF?style=flat-square&logo=stripe&logoColor=white" alt="Stripe" /></a> <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-Welcome-brightgreen?style=flat-square" alt="PRs Welcome" /></a>

<br /> <br />

Star History

<a href="https://www.star-history.com/?repos=AlameerAshraf%2Ftokentoll&type=timeline&logscale=&legend=top-left"> <picture> <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/image?repos=AlameerAshraf/tokentoll&type=timeline&theme=dark&logscale&legend=top-left" /> <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/image?repos=AlameerAshraf/tokentoll&type=timeline&logscale&legend=top-left" /> <img alt="Star History Chart" src="https://api.star-history.com/image?repos=AlameerAshraf/tokentoll&type=timeline&logscale&legend=top-left" /> </picture> </a>

12 AI Providers Β· 5 Pricing Models Β· 30+ API Endpoints Β· Python & Node SDKs

<br />

πŸš€ Quick Start Β· 🎯 Features Β· πŸ“¦ SDKs Β· πŸ“– API Reference Β· βš™οΈ Configuration Β· 🐳 Deployment Β· 🀝 Contributing

<br />
</div> <br />

🐾 What is TokenToll?

The problem: You're building a SaaS on top of LLMs. You need to track usage per customer, enforce quotas, support free tiers and prepaid credits, and generate invoices. Building all that from scratch takes weeks.

The solution: TokenToll gives you a single API to handle all of it. Ingest usage events, define pricing in YAML, and let TokenToll compute costs, enforce limits, generate invoices, and sync to Stripe β€” or run fully self-hosted.

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚              β”‚  report  β”‚              β”‚  invoice β”‚              β”‚
  β”‚   Your App   │────────▢ β”‚  TokenToll   │────────▢ β”‚   Customer   β”‚
  β”‚  calls LLM   β”‚  tokens  β”‚   API        β”‚  auto    β”‚   gets bill  β”‚
  β”‚              β”‚          β”‚              β”‚          β”‚              β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
<br />

🎯 Features

<table> <tr> <td width="33%" valign="top">

πŸ“Š Usage Metering

βœ… Event ingestion via REST or SDK<br/> βœ… Idempotent (duplicate IDs ignored)<br/> βœ… Batch ingestion<br/> βœ… Multi-meter (tokens, calls, compute)<br/>


πŸ’° Flexible Pricing

βœ… Per-unit β€” qty Γ— rate<br/> βœ… Tiered β€” bracket-based rates<br/> βœ… Volume β€” total determines rate<br/> βœ… Flat β€” fixed monthly fee<br/> βœ… Prepaid β€” credit deduction<br/> βœ… Free tiers β€” free allowance<br/>

</td> <td width="33%" valign="top">

πŸ”’ Quotas & Entitlements

βœ… Hard limits β€” block at cap<br/> βœ… Soft limits β€” alert via webhook<br/> βœ… Budget caps β€” dollar spending limits<br/> βœ… Alert thresholds β€” 80%, 100%, etc.<br/>


🧾 Invoicing & Payments

βœ… Auto monthly invoice generation<br/> βœ… Per-meter line items<br/> βœ… Stripe sync or self-hosted<br/> βœ… Prepaid credit auto-apply<br/> βœ… Invoice status tracking<br/> βœ… Retry with exponential backoff<br/>

</td> <td width="33%" valign="top">

🏒 Multi-Tenancy

βœ… Full tenant isolation<br/> βœ… Operator super-admin API<br/> βœ… Per-tenant API key rotation<br/> βœ… SHA-256 hashed key storage<br/>


πŸ”” Webhooks & Observability

βœ… HMAC-SHA256 signed delivery<br/> βœ… 3 event types with auto-retry<br/> βœ… Full audit logging<br/> βœ… Event replay / reconciliation<br/> βœ… Platform analytics endpoint<br/> βœ… Rate limiting per tenant<br/>

</td> </tr> </table> <br />

πŸ€– Built-in AI Provider Pricing

TokenToll ships with pre-configured cost tables for 12 providers and 100+ models. Pass provider and model with your events β€” costs are calculated automatically.

<table> <tr> <td align="center" width="25%"><img src="https://img.shields.io/badge/-OpenAI-412991?style=for-the-badge&logo=openai&logoColor=white" /><br/><sub>GPT-4o Β· o1 Β· o3</sub></td> <td align="center" width="25%"><img src="https://img.shields.io/badge/-Anthropic-D4A574?style=for-the-badge&logo=anthropic&logoColor=white" /><br/><sub>Claude 4 Β· 3.5 Β· Haiku</sub></td> <td align="center" width="25%"><img src="https://img.shields.io/badge/-Google-4285F4?style=for-the-badge&logo=google&logoColor=white" /><br/><sub>Gemini 2.5 Β· Flash</sub></td> <td align="center" width="25%"><img src="https://img.shields.io/badge/-Mistral-FF7000?style=for-the-badge&logoColor=white" /><br/><sub>Large Β· Codestral</sub></td> </tr> <tr> <td align="center"><img src="https://img.shields.io/badge/-DeepSeek-4D6BFE?style=for-the-badge&logoColor=white" /><br/><sub>V3 Β· R1</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Meta-0467DF?style=for-the-badge&logo=meta&logoColor=white" /><br/><sub>Llama 3 Β· Llama 4</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Cohere-39594D?style=for-the-badge&logoColor=white" /><br/><sub>Command R+</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Groq-F55036?style=for-the-badge&logoColor=white" /><br/><sub>LPU Inference</sub></td> </tr> <tr> <td align="center"><img src="https://img.shields.io/badge/-xAI-000000?style=for-the-badge&logo=x&logoColor=white" /><br/><sub>Grok</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Perplexity-20808D?style=for-the-badge&logoColor=white" /><br/><sub>Sonar Pro</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Together_AI-6B4FBB?style=for-the-badge&logoColor=white" /><br/><sub>Open Models</sub></td> <td align="center"><img src="https://img.shields.io/badge/-Azure_OpenAI-0078D4?style=for-the-badge&logo=microsoftazure&logoColor=white" /><br/><sub>Hosted OpenAI</sub></td> </tr> </table>

[!TIP] Rates are YAML files in config/provider_pricing/ β€” update them anytime and hot-reload without restart.

<br />

πŸ—οΈ Architecture

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                 β”‚         β”‚                  β”‚         β”‚               β”‚
  β”‚    Your App     │────────▢│   TokenToll API  │────────▢│   MongoDB     β”‚
  β”‚  (SDK / HTTP)   β”‚         β”‚   (FastAPI)      β”‚         β”‚               β”‚
  β”‚                 β”‚         β”‚                  β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚  Redis Streams   β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
                     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€-┐
                     β”‚                β”‚                 β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
              β”‚  Ingestion  β”‚  β”‚   Invoice   β”‚   β”‚   Webhook   β”‚
              β”‚   Worker    β”‚  β”‚   Worker    β”‚   β”‚   Worker    β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                      β”‚
                              β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”
                              β”‚    Stripe      β”‚
                              β”‚  (optional)    β”‚
                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

| Component | Role | |:---|:---| | 🌐 API Server | FastAPI REST API β€” auth, rate limiting, multi-tenant routing | | ⚑ Ingestion Worker | Processes usage events, updates wallets, checks entitlements | | πŸ’΅ Invoice Worker | Monthly invoice generation, Stripe sync, credit application | | πŸ“¨ Webhook Worker | HMAC-signed delivery with retries to your endpoints | | πŸƒ MongoDB | Persistent storage β€” tenants, customers, events, invoices, audit logs | | πŸ”΄ Redis | Stream-based queue + per-tenant rate limiting |

<br />

πŸš€ Quick Start

[!NOTE] You need Docker & Docker Compose. Stripe is optional β€” without it, TokenToll runs in manual invoicing mode.

Step 1 β€” Start the stack

git clone https://github.com/AlameerAshraf/tokentoll.git
cd tokentoll
docker compose -f docker/docker-compose.yml up -d

Step 2 β€” Verify it's running

curl http://localhost:8000/health | jq
# βœ… {"status": "ok", "database": "ok"}

Step 3 β€” Create a tenant (your SaaS company)


curl -s -X POST http://localhost:8000/v1/tenants \
  -H "Content-Type: application/json" \
  -d '{"name": "My SaaS", "slug": "my-saas"}' | jq

Step 4 β€” Generate an API key

curl -s -X POST http://localhost:8000/v1/tenan
View on GitHub
GitHub Stars75
CategoryOperations
Updated5d ago
Forks9

Languages

Python

Security Score

85/100

Audited on Mar 28, 2026

No findings