Lago Client
A Rust client library for interacting with the Lago billing API.
Features
- Async/Await Support: Built with
tokioandreqwestfor modern async Rust - Automatic Retries: Configurable retry logic with exponential backoff
- Multiple Regions: Support for US, EU, and custom API endpoints
- Flexible Configuration: Environment variables or programmatic configuration
- Type Safety: Strongly typed requests and responses using
lago-types - Authentication: Secure API key-based authentication
Installation
Add this to your Cargo.toml:
[]
= "0.1.4"
Quick Start
Using Environment Variables
Set the required environment variables:
# or "eu" or custom URL
Then create a client:
use LagoClient;
async
Programmatic Configuration
use ;
use Duration;
async
Configuration
Regions
The client supports multiple regions:
Region::Us- United States (default)Region::Eu- European UnionRegion::Custom(url)- Custom API endpoint
Retry Configuration
Configure retry behavior for failed requests:
use ;
use Duration;
let retry_config = builder
.mode
.max_attempts
.initial_delay
.max_delay
.backoff_multiplier
.build;
let config = builder
.retry_config
.build;
Retry modes:
RetryMode::Off- No retriesRetryMode::Standard- Standard exponential backoffRetryMode::Adaptive- Adaptive retry behavior
API Operations
Invoices
use ;
// List invoices with optional filters
let request = builder
.limit
.build;
let invoices = client.list_invoices.await?;
// Get a specific invoice
let request = new;
let invoice = client.get_invoice.await?;
Billable Metrics
use ;
// Create a billable metric
let metric = new
.with_description
.with_field_name;
let request = new;
let created = client.create_billable_metric.await?;
// List billable metrics
let metrics = client.list_billable_metrics.await?;
// Get specific billable metric
let metric = client.get_billable_metric.await?;
Customers
use ;
// Create or Update a customer
let customer = new
.with_name
.with_email
.with_customer_type
.with_currency;
let request = new;
let created = client.create_customer.await?;
// List customers
let customers = client.list_customers.await?;
// Get specific customer
let customer = client.get_customer.await?;
## Error Handling
The client uses the `lago-types` error system:
```rust
use LagoError;
match client.list_invoices.await
Environment Variables
| Variable | Description | Default |
|---|---|---|
LAGO_API_KEY |
API key for authentication | Required |
LAGO_REGION |
API region (us, eu, or custom URL) |
us |
LAGO_API_URL |
Custom API endpoint URL | - |
Examples
See the examples/ directory for complete usage examples:
basic_usage.rs- Basic client usagecustom_configuration.rs- Advanced configuration optionsbillable_metric.rs- Billable metrics managementcustomer.rs- Customers management operations
# Run the basic usage example
# Run the billable metrics example
# Run the customer management example
Release
Before publishing a release
cargo check
cargo test
cargo doc --no-deps --open
cargo package
Run the release
cargo login API_KEY
cargo publish
License
This project is licensed under the same license as the parent Lago Rust Client.