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.0"
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?;
Error Handling
The client uses the lago-types error system:
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 options
# Run the basic usage example
# Run the custom configuration 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.