File: README.md
See Lago price an AI workload
Run the maintained demo from this repository:
./examples/agentic-ai-demo/run.shIt starts the Lago version that matches this checkout, creates a disposable local organization, and prices three illustrative AI requests. Each request sends one input-token event and one output-token event:
3 AI requests
5,000 input tokens x $0.000002 = $0.01
1,250 output tokens x $0.000008 = $0.01
Lago usage total = $0.02Docker Compose starts an isolated Lago service, then a small script seeds and verifies the example through Lago's API. It retrieves current usage, independently reconciles the result, and retries one transaction to confirm that usage does not increase. Everything stays on your machine; the demo does not access Lago Cloud. The bundled credentials and API key are disposable and only intended for this local demo.
Log into http://localhost:8080 with [email protected] / agentic-ai-demo-local-password, then open Customers → Agentic AI Demo Customer → Agentic AI Demo subscription → Usage.
Requirements: Docker, curl, and jq. If ports 8080 or 3001 are occupied, set LAGO_DEMO_UI_PORT and LAGO_DEMO_API_PORT before running. The demo keeps Lago running so you can inspect the customer, metrics, plan, subscription, events, and usage in the UI. Remove its isolated Compose project and data volume when you are done:
./examples/agentic-ai-demo/run.sh --cleanupUse Claude Code, Codex, or Cursor
Open this repository in your coding agent and paste:
Run Lago's maintained Agentic AI demo by following this README. Keep it local;
do not modify source files or unrelated Docker resources. When it passes, give
me the UI URL, token usage and charges, idempotency evidence, and cleanup
command. Then offer to connect this agent to Lago's local MCP server.What is Lago?
Lago is the programmable system between product usage and revenue. Send events from your application, turn them into billable metrics, apply pricing and entitlements, then generate invoices and collect payments.
Usage events -> Metering -> Pricing and credits -> Entitlements -> Invoices -> Payments -> RevenueUse Lago to launch and change pricing without rebuilding billing:
- tokens by model, input, output, cache, reasoning, or tool call
- GPU, CPU, storage, and other compute consumption
- API calls, transactions, seats, active users, or custom events
- prepaid credits with automatic top-ups
- subscriptions with allowances, minimum commitments, and overages
- self-serve plans and negotiated enterprise contracts in the same system
Lago is headless and API-first. Your application, internal tools, and agents use the same billing primitives through the REST API, SDKs, webhooks, and MCP server. Product, finance, and operations teams can use the Lago UI when a human interface is faster.
How Lago fits into your stack
Lago keeps metering and pricing independent from payment processing. Connect Stripe, Adyen, GoCardless, or another provider without making its product catalog your source of truth.
Lago Direct and Lago Embedded
The same Lago engine supports two operating models:
| Lago Direct | Lago Embedded | |
|---|---|---|
| Who monetizes | You monetize your own product | Your customers monetize through your platform |
| Experience | Your application and teams use Lago through APIs, agent interfaces, and Lago UI | Your customers use billing capabilities inside your product through APIs and white-label interfaces |
| Brand | Lago powers your billing stack | Lago stays behind the scenes under your brand |
| Public example | Mistral AI | PayPal |
Lago Direct is the standard way to use Lago: send your own product usage, model your pricing, and bill your customers. Lago Embedded uses the same primitives to let platforms, marketplaces, AI builders, fintech products, and developer tools offer metering and billing to their customers.
Both models start with Lago's open-source billing engine and can be paired with Premium deployment, customization, security, and support options. With Lago Embedded, you control the customer experience and which capabilities your users can access.
Agentic-first by design
Agentic-first means Lago's billing model is available as structured, inspectable interfaces instead of being trapped in a dashboard.
| Interface | What it enables | Availability |
|---|---|---|
| REST API and OpenAPI | Program every core billing workflow and generate typed clients or tools from the schema | Open source |
| Lago MCP server | Give an MCP-compatible agent tools to read and write invoices, usage, customers, payments, credit notes, coupons, and other Lago primitives | Open source, MIT |
| Lago Agent SDK for Python | Wrap supported LLM clients, normalize usage, and send token or model-cost events without blocking the LLM call | Open source, MIT |
| Lago Agent SDK for JavaScript and TypeScript | Instrument OpenAI, Anthropic, Mistral, Gemini, and AWS Bedrock clients with under 5 ms p99 wrapper overhead | Open source, MIT |
| Finance Assistant | Ask read-only questions about billing, usage, and revenue in plain language | Beta, early access |
| Billing Assistant | Query billing data and run operations in natural language, with confirmation for important or destructive actions | Premium beta, available upon request |
The MCP server exposes read and write tools and inherits the permissions of its Lago API key. Treat agent credentials as privileged, control who can access the agent, review tool calls, and keep human confirmation around sensitive billing changes.
Platform
| Layer | Capabilities |
|---|---|
| Meter usage | Real-time event ingestion, filters, dimensions, custom aggregations, batch ingestion, and idempotency by transaction_id |
| Model pricing | Usage-based, recurring, prepaid, percentage, graduated, package, volume, minimum-commitment, and hybrid charges |
| Control access | Entitlements, allowances, wallets, credit grants, top-ups, and usage alerts |
| Bill customers | Subscriptions, invoices, credit notes, taxes, multiple currencies, multiple entities, and customer-specific overrides |
| Collect revenue | Payment-provider orchestration, retries, dunning, and payment-status synchronization |
| Understand revenue | Usage, MRR, invoice, customer, and revenue analytics |
| Connect the stack | Salesforce, HubSpot, NetSuite, Xero, Avalara, cloud marketplaces, data warehouses, and webhooks |
| Lago Direct | Meter and bill your own customers through Lago APIs, agent interfaces, and UI |
| Lago Embedded | White-label metering and billing for platforms, marketplaces, AI builders, and fintech products |
Explore metering, billing and invoicing, entitlements, cash collection, revenue analytics, and integrations.
Production characteristics
- Idempotent ingestion. Lago deduplicates usage events by
transaction_id, so retrying an event does not bill it twice. Read the ingestion guide. - Atomic batches. If one event in a batch is invalid, Lago rejects the batch and persists none of its events. Read the batch API reference.
- Asynchronous processing. Dedicated workers can isolate events, billing, payments, invoices, webhooks, PDFs, alerts, and analytics as volume grows. Review the architecture.
- Observable operation. Lago exposes Prometheus metrics for APIs, queues, workers, events, billing, webhooks, and dependencies. Review monitoring.
- Deployment control. Run Lago locally, in your cloud, or on your infrastructure. Production deployments can separate and scale stateful services and workers independently.
- Security. Lago is SOC 2 Type II certified and supports self-hosting for teams that need infrastructure and data control. Review security.
Chosen by teams operating at scale
Mistral AI, Groq, PayPal, Synthesia, Blacksmith, and other teams have publicly selected Lago for billing. The figures below describe the companies using Lago, not volume processed by Lago.
| Company | Lago use | Public company context |
|---|---|---|
| Mistral AI | Token metering, prepaid credits, invoicing, taxes, and payment collection for paid AI products | Reported at more than $400M in annualized revenue run rate |
| Groq | Lago customer | More than 5M developers and trillions of AI tokens processed weekly |
| Blacksmith | Usage-based billing for compute-intensive CI workloads | More than 6,000 companies; raised a $45M Series B at a $550M valuation |
| Synthesia | Lago customer | Approximately $140M ARR |
| PayPal | Embedded, usage-based billing for merchants | More than 430M active accounts worldwide |
Sources for company context: Mistral AI, Groq, Blacksmith, Synthesia, and PayPal.
Open source and managed options
| Option | Best for | Access |
|---|---|---|
| Lago open source | Teams that want to inspect, extend, and operate the billing platform on their infrastructure | This repository, AGPLv3 |
| Agent tooling | Teams that want to meter LLM usage or expose billing primitives to agents | Separate open-source Agent SDK and MCP repositories, MIT |
| Lago Cloud | Teams that want Lago to operate the platform and provide commercial support | Talk to us |
| Premium capabilities | Teams that need selected assistants, enterprise integrations, governance, or embedded use cases | Availability varies by feature; talk to us |
Deploy Lago
For a source-based local deployment:
git clone --depth 1 https://github.com/getlago/lago.git
cd lago
echo "LAGO_RSA_PRIVATE_KEY=\"$(openssl genrsa 2048 | openssl base64 -A)\"" >> .env
docker compose up -dUse the self-hosted deployment guide for persistent storage, SMTP, TLS, object storage, Redis, database configuration, and upgrades. For larger deployments, use the Lago Helm charts and configure dedicated workers.
SDKs and developer resources
| Language | Client |
|---|---|
| Node.js | lago-javascript-client |
| Python | lago-python-client |
| Ruby | lago-ruby-client |
| Go | lago-go-client |
- Getting started
- API reference
- OpenAPI specification
- Pricing templates
- Architecture
- Monitoring
- Changelog
- Public roadmap
- System status
Contributing
Lago is built in the open. Read the contributing guide and development environment setup to get started.
Look for issues labeled beginner or help-wanted, or join the Lago Slack community.
License
The Lago platform is distributed under the AGPLv3 license. Read why Lago chose AGPLv3. Lago's Agent SDKs and MCP server are distributed from separate repositories under the MIT license.
Analytics and tracking
Self-hosted Lago instances collect basic product analytics by default. Lago does not collect customer PII or financial data through this tracking. Review what is collected or opt out.
File: deploy/README.md
Lago Deploy
This repository contains the necessary files to deploy the Lago project.
Docker Compose Local
To deploy the project locally, you need to have Docker and Docker Compose installed on your machine.
This configuration can be used for small production usages but it's not recommended for large scale deployments.
Get Started
- Get the docker compose file
curl -o docker-compose.yml https://raw.githubusercontent.com/getlago/lago/main/deploy/docker-compose.local.yml- Run the following command to start the project:
docker compose up --profile all
# If you want to run it in the background
docker compose up -d --profile allDocker Compose Light
This configuration provide Traefik as a reverse proxy to ease your deployment.
It supports SSL with Let's Encrypt. :warning: You need a valid domain (with at least one A or AAA record)!
- Get the docker compose file
curl -o docker-compose.yml https://raw.githubusercontent.com/getlago/lago/main/deploy/docker-compose.light.yml
curl -o .env https://raw.githubusercontent.com/getlago/lago/main/deploy/.env.light.example- Replace the .env values with yours
LAGO_DOMAIN=domain.tld
[email protected]- Run the following command to start the project
docker compose up --profile all
# If you want to run it in the background
docker compose up -d --profile allDocker Compose Production
This configuration provide Traefik as a reverse proxy to ease your deployment.
It supports SSL wth Let's Encrypt. :warning: You need a valid domain (with at least one A or AAA record)!
It also adds multiple services that will help your to handle more load.
Portainer is also packed to help you scale services and manage your Lago stack.
curl -o docker-compose.yml https://raw.githubusercontent.com/getlago/lago/main/deploy/docker-compose.production.yml
curl -o .env https://raw.githubusercontent.com/getlago/lago/main/deploy/.env.production.example- Replace the .env values with yours
LAGO_DOMAIN=domain.tld
[email protected]
PORTAINER_USER=lago
PORTAINER_PASSWORD=changeme- Run the following command to start the project
docker compose up --profile all
# If you want to run it in the background
docker compose up -d --profile allConfiguration
Profiles
The docker compose file contains multiple profiles to enable or disable some services.
Here are the available profiles:
all: Enable all servicesall-no-pg: Disable the PostgreSQL serviceall-no-redis: Disable the Redis serviceall-no-keys: Disable the RSA keys generation service
This allow you to start only the service you want to use, please see the following sections for more information.
# Start all services
docker compose up --profile all
# Start without PostgreSQL
docker compose up --profile all-no-pg
# Start without Redis
docker compose up --profile all-no-redis
# Start without PostgreSQL and Redis
docker compose up --profile all-no-db
# Start without RSA keys generation
docker compose up --profile all-no-keys
# Start without PostgreSQL, Redis and RSA keys generation
docker compose upPostgreSQL
It is possible to disable the usage of the PostgreSQL database to use an external database instance.
- Set those environment variables:
POSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_DBPOSTGRES_HOSTPOSTGRES_PORTPOSTGRES_SCHEMAoptional
- Run the following command to start the project without PostgreSQL:
docker compose up --profile all-no-pgRedis
It is possible to disable the usage of the Redis database to use an external Redis instance.
- Set those environment variables:
REDIS_HOSTREDIS_PORTREDIS_PASSWORDoptional
- Run the following command to start the project without Redis:
docker compose up --profile all-no-redisRSA Keys
Those docker compose file generates an RSA Keys pair for the JWT tokens generation.
You can find the keys in the lago_rsa_data volume or in the /app/config/keys directory in the backends containers.
If you do not want to use those keys:
- Remove the
lago_rsa_datavolume - Generate your own key using
openssl genrsa 2048 | openssl base64 -A - Export this generated key to the
LAGO_RSA_PRIVATE_KEYenv var. - Run the following command to start the project without the RSA keys generation:
docker compose up --profile all-no-keysAll BE Services use the same RSA key, they will exit immediately if no key is provided.
Monitoring
For production deployments, we recommend setting up monitoring for Sidekiq workers. See the Monitoring documentation for:
- Prometheus metrics endpoints and available metrics
- Recommended alerting rules
- Grafana dashboard recommendations
File: docker/README.md
Lago Docker Image
This is the official one docker image for Lago.
This docker image is designed for testing and staging environments only. It is not recommended for production use due to its simplified architecture and resource constraints. For production deployments, please refer to our deployment guides in the deploy folder or use our helm chart for a more robust and scalable setup.
Features
This docker image embed everything to run Lago with just one command line to ease the deployment.
Here are the services that are running into the container :
- PostgreSQL
- Redis
- Lago UI
- Lago API
- Lago Worker
- Lago Clock
- PDF Service (optional)
Get Started
docker run -d --name lago -p 80:80 -p 3000:3000 getlago/lago:latestPDF generation is disabled by default. We use Gotenberg, which is only available as a Docker image. To enable PDF generation, use the following command:
docker run -d --name lago -v /var/run/docker.sock:/var/run/docker.sock -p 80:80 -p 3000:3000 getlago/lago:latestYou will see an other docker container named lago-pdf running.
Using External Services
You can use external services for the database and Redis instance.
Here are the env var you should pass to the container to use them :
| Env Var | Description | Default |
|---|---|---|
| DATABASE_URL | The URL of the database | postgres://lago:lago@localhost:5432/lago |
| REDIS_URL | The URL of the Redis instance | redis://localhost:6379/0 |
Storage
The container is using a volume to store the data, you can mount it to your host to keep the data safe.
You can find many folders for each services in the /data folder.
SSL
SSL is disabled by default in this development/staging image. To enable SSL support when using a proxy or load balancer:
For new installations:
- Add the environment variable
LAGO_DISABLE_SSL=falsewhen running the containerbashdocker run -e LAGO_DISABLE_SSL=false ...
For existing installations:
- Navigate to your
/datavolume - Edit the
.envfile to changeLAGO_DISABLE_SSL=truetoLAGO_DISABLE_SSL=false
:warning: Note that this only enables SSL support - you must still configure SSL certificates and termination through your reverse proxy or load balancer.
Logs
Database Logs (creation, migration) are stored in the /data/db.log file.
Applicative logs are streamed to the standard output.
Contributing
This docker image is a work in progress.
Feel free to open issues or PRs to improve it or ask for new features.
File: events-processor/README.md
Lago Events Processor
High throughput events processor for Lago.
This service is in charge of providing a post-process for events in high volume scenarios.
This service need to be configured with Clickhouse and Redpanda. Please contact us for further informations.
How to run it
With the docker compose environment:
go build -o event_processors .
./event_processorsDevelopment
Running
lago up -d events-processorTesting
lago exec events-processor go test ./...Configuration
This app requires some env vars
| Variable | Description |
|---|---|
| ENV | Set as production to not load .env file |
| DATABASE_URL | PostgreSQL server URL (eg: postgresql://lago_user:lago_password@lago_server:5432/lago_db) |
| LAGO_KAFKA_BOOTSTRAP_SERVERS | Kafka Brokers list URL with port (eg: "redpanda:9092,kafka:9092") |
| LAGO_KAFKA_RAW_EVENTS_TOPIC | Events Kafka Topic (eg: events_raw) |
| LAGO_KAFKA_ENRICHED_EVENTS_TOPIC | Events Enriched Kafka Topic (eg: events_enriched) |
| LAGO_KAFKA_ENRICHED_EVENTS_EXPANDED_TOPIC | Events Enriched Expanded Kafka Topic (eg: events_enriched_expanded) |
| LAGO_KAFKA_EVENTS_CHARGED_IN_ADVANCE_TOPIC | Events Charge In Advance Kafka Topic (eg: events_charge_in_advance) |
| LAGO_KAFKA_EVENTS_DEAD_LETTER_TOPIC | Events Dead Letter Queue (eg: events_dead_letter) |
| LAGO_KAFKA_CONSUMER_GROUP | Kafka Consumer Group Name for Post Processing |
| LAGO_REDIS_STORE_URL | Redis URL to store subscription refresh IDs |
| LAGO_REDIS_CACHE_URL | Redis URL to store charge usage cache entries |
Additionally there's a few optional environment variables
| Variable | Description |
|---|---|
| LAGO_REDIS_STORE_DB | Redis database number to use for the store (default: 0) |
| LAGO_REDIS_STORE_PASSWORD | Password for the Redis store (if required) |
| LAGO_REDIS_STORE_TLS | Redis TLS configuration for the Redis store (default: false) |
| LAGO_REDIS_CACHE_DB | Redis database number to use for the cache (default: 0) |
| LAGO_REDIS_CACHE_PASSWORD | Password for the Redis cache (if required) |
| LAGO_REDIS_CACHE_TLS | Redis TLS configuration for charge usage cache entries (default: false) |
| LAGO_KAFKA_TLS | Set to true if your broker uses TLS termination |
| LAGO_KAFKA_SCRAM_ALGORITHM | Your Broker SCRAM algo, supported values are SCRAM-SHA-256 and SCRAM-SHA-512. If you provide a SCRAM Algo, LAGO_KAFKA_USERNAME and LAGO_KAFKA_PASSWORD are required |
| LAGO_KAFKA_USERNAME | If your broker needs auth, your Kafka Username |
| LAGO_KAFKA_PASSWORD | If your broker needs auth, your Kafka password |
| OTEL_SERVICE_NAME | OpenTelemetry service name (eg: events-processor) |
| OTEL_EXPORTER_OTLP_ENDPOINT | OpenTelemetry server URL. Setting this environment variable will enable tracing |
| OTEL_INSECURE | Set to true to use the insecure mode of OpenTelemetry |
| LAGO_USE_MEMORY_CACHE | Use the new in memory cache instead of DB calls |
| LAGO_DEBEZIUM_TOPIC_PREFIX | Mandatory if USE_MEMORY_CACHE is set to true, debezium kafka topic prefix (eg: lago_dbz) |