lago-client 0.1.16

Lago API client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
# Lago Client

A Rust client library for interacting with the [Lago](https://getlago.com) billing API.

## Features

- **Async/Await Support**: Built with `tokio` and `reqwest` for 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`:

```toml
[dependencies]
lago-client = "0.1.4"
```

## Quick Start

### Using Environment Variables

Set the required environment variables:

```bash
export LAGO_API_KEY="your-api-key"
export LAGO_REGION="us"  # or "eu" or custom URL
```

Then create a client:

```rust
use lago_client::LagoClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = LagoClient::from_env()?;
    
    // Use the client to make API calls
    let invoices = client.list_invoices(None).await?;
    println!("Found {} invoices", invoices.invoices.len());
    
    Ok(())
}
```

### Programmatic Configuration

```rust
use lago_client::{LagoClient, Config, Credentials, Region};
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let config = Config::builder()
        .credentials(Credentials::new("your-api-key"))
        .region(Region::Us)
        .timeout(Duration::from_secs(30))
        .build();
    
    let client = LagoClient::new(config);
    
    // Use the client
    let invoices = client.list_invoices(None).await?;
    
    Ok(())
}
```

## Configuration

### Regions

The client supports multiple regions:

- `Region::Us` - United States (default)
- `Region::Eu` - European Union
- `Region::Custom(url)` - Custom API endpoint

### Retry Configuration

Configure retry behavior for failed requests:

```rust
use lago_client::{Config, RetryConfig, RetryMode};
use std::time::Duration;

let retry_config = RetryConfig::builder()
    .mode(RetryMode::Standard)
    .max_attempts(3)
    .initial_delay(Duration::from_millis(100))
    .max_delay(Duration::from_secs(30))
    .backoff_multiplier(2.0)
    .build();

let config = Config::builder()
    .retry_config(retry_config)
    .build();
```

Retry modes:
- `RetryMode::Off` - No retries
- `RetryMode::Standard` - Standard exponential backoff
- `RetryMode::Adaptive` - Adaptive retry behavior

## API Operations

### Invoices

```rust
use lago_types::requests::invoice::{
    ListInvoicesRequest, GetInvoiceRequest, CreateInvoiceInput, CreateInvoiceFeeInput,
    CreateInvoiceRequest, UpdateInvoiceInput, UpdateInvoiceMetadataInput, UpdateInvoiceRequest,
    ListCustomerInvoicesRequest, RefreshInvoiceRequest, DownloadInvoiceRequest,
    RetryInvoiceRequest, RetryInvoicePaymentRequest,
};

// List invoices with optional filters
let request = ListInvoicesRequest::new();
let invoices = client.list_invoices(Some(request)).await?;

// Get a specific invoice
let request = GetInvoiceRequest::new("invoice-id".to_string());
let invoice = client.get_invoice(request).await?;

// Create a one-off invoice
let fee = CreateInvoiceFeeInput::new("setup_fee".to_string(), 1.0)
    .with_unit_amount_cents(9900)
    .with_description("One-time setup fee".to_string());
let input = CreateInvoiceInput::new(
    "customer_123".to_string(),
    "USD".to_string(),
    vec![fee],
);
let request = CreateInvoiceRequest::new(input);
let created = client.create_invoice(request).await?;

// Update invoice payment status and metadata
let metadata = UpdateInvoiceMetadataInput::new(
    "payment_ref".to_string(),
    "REF-12345".to_string(),
);
let input = UpdateInvoiceInput::new()
    .with_payment_status("succeeded".to_string())
    .with_metadata(vec![metadata]);
let request = UpdateInvoiceRequest::new("invoice-lago-id".to_string(), input);
let updated = client.update_invoice(request).await?;

// List invoices for a specific customer
let request = ListCustomerInvoicesRequest::new("customer_123".to_string());
let invoices = client.list_customer_invoices(request).await?;

// Refresh a draft invoice
let request = RefreshInvoiceRequest::new("invoice-lago-id".to_string());
let refreshed = client.refresh_invoice(request).await?;

// Download invoice PDF
let request = DownloadInvoiceRequest::new("invoice-lago-id".to_string());
let invoice = client.download_invoice(request).await?;
println!("PDF URL: {:?}", invoice.invoice.file_url);

// Retry a failed invoice finalization
let request = RetryInvoiceRequest::new("invoice-lago-id".to_string());
let retried = client.retry_invoice(request).await?;

// Retry a failed invoice payment
let request = RetryInvoicePaymentRequest::new("invoice-lago-id".to_string());
let retried = client.retry_invoice_payment(request).await?;
```

### Invoice Preview

Preview an invoice before creating it:

```rust
use lago_types::requests::invoice::{
    BillingTime, InvoicePreviewInput, InvoicePreviewRequest,
    InvoicePreviewCustomer, InvoicePreviewCoupon, InvoicePreviewSubscriptions,
};

// Preview for an existing customer with a new subscription
let preview_input = InvoicePreviewInput::for_customer("customer_123".to_string())
    .with_plan_code("startup".to_string())
    .with_billing_time(BillingTime::Calendar);

let request = InvoicePreviewRequest::new(preview_input);
let preview = client.preview_invoice(request).await?;
println!("Preview total: {} cents", preview.invoice.total_amount_cents);

// Preview with inline customer details
let customer = InvoicePreviewCustomer::new()
    .with_name("New Customer".to_string())
    .with_currency("USD".to_string());

let preview_input = InvoicePreviewInput::new(customer)
    .with_plan_code("enterprise".to_string())
    .with_subscription_at("2024-01-01T00:00:00Z".to_string());

let request = InvoicePreviewRequest::new(preview_input);
let preview = client.preview_invoice(request).await?;

// Preview with coupons
let coupon = InvoicePreviewCoupon::new("DISCOUNT20".to_string())
    .with_percentage("20".to_string());

let preview_input = InvoicePreviewInput::for_customer("customer_123".to_string())
    .with_plan_code("startup".to_string())
    .with_coupons(vec![coupon]);

let request = InvoicePreviewRequest::new(preview_input);
let preview = client.preview_invoice(request).await?;

// Preview for existing subscriptions with plan upgrade
let subscriptions = InvoicePreviewSubscriptions::new(vec!["sub_123".to_string()])
    .with_plan_code("enterprise".to_string());

let preview_input = InvoicePreviewInput::for_customer("customer_123".to_string())
    .with_subscriptions(subscriptions);

let request = InvoicePreviewRequest::new(preview_input);
let preview = client.preview_invoice(request).await?;
```

### Activity Logs

```rust
use lago_types::{
    filters::activity_log::ActivityLogFilters,
    models::ActivitySource,
    requests::activity_log::{GetActivityLogRequest, ListActivityLogsRequest},
};

// List all activity logs
let activity_logs = client.list_activity_logs(None).await?;

// List activity logs with filters
let request = ListActivityLogsRequest::new().with_filters(
    ActivityLogFilters::new()
        .with_activity_types(vec!["invoice.created".to_string()])
        .with_activity_sources(vec![ActivitySource::Api, ActivitySource::Front])
        .with_user_emails(vec!["admin@example.com".to_string()])
        .with_resource_types(vec!["Invoice".to_string()])
        .with_date_range("2025-01-01".to_string(), "2025-01-31".to_string()),
);
let filtered_logs = client.list_activity_logs(Some(request)).await?;

// Get a specific activity log by activity ID
let request = GetActivityLogRequest::new("activity-id".to_string());
let activity_log = client.get_activity_log(request).await?;
println!("Activity: {} - {:?}",
    activity_log.activity_log.activity_type,
    activity_log.activity_log.activity_source
);
```

### API Logs

```rust
use lago_types::{
    filters::api_log::ApiLogFilters,
    models::{HttpMethod, HttpStatus, StatusOutcome},
    requests::api_log::{GetApiLogRequest, ListApiLogsRequest},
};

// List all API logs
let api_logs = client.list_api_logs(None).await?;

// List API logs with filters
let request = ListApiLogsRequest::new().with_filters(
    ApiLogFilters::new()
        .with_http_methods(vec![HttpMethod::Post, HttpMethod::Put])
        .with_http_statuses(vec![HttpStatus::Outcome(StatusOutcome::Failed)])
        .with_api_version("v1".to_string())
        .with_request_paths(vec!["/invoices".to_string(), "/customers".to_string()])
        .with_date_range("2025-01-01".to_string(), "2025-01-31".to_string()),
);
let filtered_logs = client.list_api_logs(Some(request)).await?;

// Get a specific API log by request ID
let request = GetApiLogRequest::new("request-id".to_string());
let api_log = client.get_api_log(request).await?;
println!("Request: {:?} {} - Status {}",
    api_log.api_log.http_method,
    api_log.api_log.request_path,
    api_log.api_log.http_status
);
```

### Billable Metrics

```rust
use lago_types::{
    models::{BillableMetricAggregationType, BillableMetricFilter},
    requests::billable_metric::{CreateBillableMetricInput, CreateBillableMetricRequest},
};

// Create a billable metric
let metric = CreateBillableMetricInput::new(
    "Storage Usage".to_string(),
    "storage_gb".to_string(),
    BillableMetricAggregationType::SumAgg,
)
.with_description("Tracks storage usage".to_string())
.with_field_name("gb_used".to_string());

let request = CreateBillableMetricRequest::new(metric);
let created = client.create_billable_metric(request).await?;

// List billable metrics
let metrics = client.list_billable_metrics(None).await?;

// Get specific billable metric
let metric = client.get_billable_metric(
    GetBillableMetricRequest::new("storage_gb".to_string())
).await?;
```

### Customers

```rust
use lago_types::{
    models::{CustomerType, CustomerPaymentProvider},
    requests::customer::{CreateCustomerInput, CreateCustomerRequest},
};

// Create or Update a customer
let customer = CreateCustomerInput::new("customer_123".to_string())
    .with_name("Acme Corp".to_string())
    .with_email("billing@acme.com".to_string())
    .with_customer_type(CustomerType::Company)
    .with_currency("USD".to_string());

let request = CreateCustomerRequest::new(customer);
let created = client.create_customer(request).await?;

// List customers
let customers = client.list_customers(None).await?;

// Get specific customer
let customer = client.get_customer(
    GetCustomerRequest::new("customer_123".to_string())
).await?;
```

### Applied Coupons

```rust
use lago_types::{
    filters::applied_coupon::AppliedCouponFilter,
    models::{AppliedCouponStatus, PaginationParams},
    requests::applied_coupon::{ApplyCouponInput, ApplyCouponRequest, ListAppliedCouponsRequest},
};

// Apply a coupon to a customer
let apply_input = ApplyCouponInput::new(
    "customer_123".to_string(),
    "WELCOME10".to_string()
);
let request = ApplyCouponRequest::new(apply_input);
let applied = client.apply_coupon(request).await?;

// Apply with a fixed amount discount
let apply_input = ApplyCouponInput::new("customer_123".to_string(), "DISCOUNT50".to_string())
    .with_fixed_amount(5000, "USD".to_string()); // $50.00 discount
let request = ApplyCouponRequest::new(apply_input);
let applied = client.apply_coupon(request).await?;

// Apply with a percentage discount
let apply_input = ApplyCouponInput::new("customer_123".to_string(), "SAVE20".to_string())
    .with_percentage_rate("20".to_string()); // 20% discount
let request = ApplyCouponRequest::new(apply_input);
let applied = client.apply_coupon(request).await?;

// List all applied coupons
let applied_coupons = client.list_applied_coupons(None).await?;

// List with filters
let request = ListAppliedCouponsRequest::new()
    .with_pagination(PaginationParams::default().with_page(1).with_per_page(20))
    .with_filters(
        AppliedCouponFilter::new()
            .with_status(AppliedCouponStatus::Active)
            .with_external_customer_id("customer_123".to_string())
            .with_coupon_codes(vec!["WELCOME10".to_string()])
    );
let filtered = client.list_applied_coupons(Some(request)).await?;
```

### Coupons

```rust
use lago_types::{
    models::{CouponExpiration, CouponFrequency, PaginationParams},
    requests::coupon::{
        CreateCouponInput, CreateCouponRequest, DeleteCouponRequest,
        GetCouponRequest, ListCouponsRequest, UpdateCouponInput, UpdateCouponRequest,
    },
};

// Create a percentage-based coupon
let coupon = CreateCouponInput::percentage(
    "Welcome 10% Discount".to_string(),
    "WELCOME10".to_string(),
    "10".to_string(),
    CouponFrequency::Once,
    CouponExpiration::NoExpiration,
)
.with_reusable(true);
let request = CreateCouponRequest::new(coupon);
let created = client.create_coupon(request).await?;

// Create a fixed amount coupon
let coupon = CreateCouponInput::fixed_amount(
    "Summer $50 Off".to_string(),
    "SUMMER50".to_string(),
    5000, // $50.00 in cents
    "USD".to_string(),
    CouponFrequency::Recurring,
    CouponExpiration::NoExpiration,
)
.with_frequency_duration(3);
let request = CreateCouponRequest::new(coupon);
let created = client.create_coupon(request).await?;

// List all coupons
let coupons = client.list_coupons(None).await?;

// List coupons with pagination
let request = ListCouponsRequest::new()
    .with_pagination(PaginationParams::default().with_per_page(20));
let coupons = client.list_coupons(Some(request)).await?;

// Get a specific coupon
let request = GetCouponRequest::new("WELCOME10".to_string());
let coupon = client.get_coupon(request).await?;

// Update a coupon
let update_input = UpdateCouponInput::new()
    .with_name("Welcome 15% Discount".to_string())
    .with_percentage_rate("15".to_string());
let request = UpdateCouponRequest::new("WELCOME10".to_string(), update_input);
let updated = client.update_coupon(request).await?;

// Delete a coupon
let request = DeleteCouponRequest::new("SUMMER50".to_string());
let deleted = client.delete_coupon(request).await?;
```

### Events

```rust
use lago_types::{
    models::PaginationParams,
    requests::event::{CreateEventInput, CreateEventRequest, GetEventRequest, ListEventsRequest},
};
use serde_json::json;

// Create a usage event for a customer
let event_input = CreateEventInput::for_customer(
    "transaction_123".to_string(),
    "customer_456".to_string(),
    "api_calls".to_string(),
)
.with_properties(json!({"calls": 150}))
.with_timestamp(1705312200);

let request = CreateEventRequest::new(event_input);
let created = client.create_event(request).await?;
println!("Created event: {}", created.event.transaction_id);

// Create a usage event for a subscription
let event_input = CreateEventInput::for_subscription(
    "transaction_456".to_string(),
    "subscription_789".to_string(),
    "storage_gb".to_string(),
)
.with_properties(json!({"gb": 50.5}))
.with_precise_total_amount_cents(1234567);

let request = CreateEventRequest::new(event_input);
let created = client.create_event(request).await?;

// Get a specific event by transaction ID
let request = GetEventRequest::new("transaction_123".to_string());
let event = client.get_event(request).await?;
println!("Event code: {}, timestamp: {}", event.event.code, event.event.timestamp);

// List all events
let events = client.list_events(None).await?;
println!("Found {} events", events.events.len());

// List events with filters
let request = ListEventsRequest::new()
    .with_pagination(PaginationParams::new().with_per_page(50))
    .with_external_subscription_id("subscription_123".to_string())
    .with_code("api_calls".to_string())
    .with_timestamp_range(
        "2024-01-01T00:00:00Z".to_string(),
        "2024-01-31T23:59:59Z".to_string(),
    );
let filtered_events = client.list_events(Some(request)).await?;
println!("Found {} filtered events", filtered_events.events.len());
```

### Plans

```rust
use lago_types::{
    models::{ChargeModel, PaginationParams, PlanInterval},
    requests::plan::{
        CreatePlanChargeInput, CreatePlanInput, CreatePlanRequest, DeletePlanRequest,
        GetPlanRequest, ListPlansRequest, UpdatePlanInput, UpdatePlanRequest,
    },
};

// List all plans
let plans = client.list_plans(None).await?;

// List plans with pagination
let request = ListPlansRequest::new()
    .with_pagination(PaginationParams::default().with_per_page(20));
let plans = client.list_plans(Some(request)).await?;

// Get a specific plan by code
let request = GetPlanRequest::new("starter_plan".to_string());
let plan = client.get_plan(request).await?;

// Create a basic plan
let plan_input = CreatePlanInput::new(
    "Starter Plan".to_string(),
    "starter_plan".to_string(),
    PlanInterval::Monthly,
    9900, // $99.00 in cents
    "USD".to_string(),
)
.with_description("Our starter plan".to_string())
.with_pay_in_advance(true)
.with_trial_period(14.0);

let request = CreatePlanRequest::new(plan_input);
let created = client.create_plan(request).await?;

// Create a plan with usage-based charges
let charge = CreatePlanChargeInput::new(
    "billable_metric_lago_id".to_string(),
    ChargeModel::Standard,
)
.with_invoiceable(true)
.with_properties(serde_json::json!({"amount": "0.01"}));

let plan_input = CreatePlanInput::new(
    "Usage Plan".to_string(),
    "usage_plan".to_string(),
    PlanInterval::Monthly,
    4900,
    "USD".to_string(),
)
.with_charges(vec![charge]);

let request = CreatePlanRequest::new(plan_input);
let created = client.create_plan(request).await?;

// Update a plan
let update_input = UpdatePlanInput::new()
    .with_name("Updated Starter Plan".to_string())
    .with_amount_cents(12900);

let request = UpdatePlanRequest::new("starter_plan".to_string(), update_input);
let updated = client.update_plan(request).await?;

// Delete a plan
let request = DeletePlanRequest::new("starter_plan".to_string());
let deleted = client.delete_plan(request).await?;
```

### Credit Notes

```rust
use lago_types::{
    filters::credit_note::CreditNoteFilter,
    models::{CreditNoteReason, CreditNoteRefundStatus, PaginationParams},
    requests::credit_note::{
        CreateCreditNoteInput, CreateCreditNoteItemInput, CreateCreditNoteRequest,
        GetCreditNoteRequest, ListCreditNotesRequest, UpdateCreditNoteInput, UpdateCreditNoteRequest,
    },
};

// List all credit notes
let credit_notes = client.list_credit_notes(None).await?;

// List credit notes with filters
let request = ListCreditNotesRequest::new()
    .with_pagination(PaginationParams::default().with_page(1).with_per_page(20))
    .with_filters(
        CreditNoteFilter::new()
            .with_external_customer_id("customer_123".to_string())
            .with_reason(CreditNoteReason::Other)
            .with_date_range("2024-01-01".to_string(), "2024-12-31".to_string())
    );
let filtered = client.list_credit_notes(Some(request)).await?;

// Get a specific credit note
let request = GetCreditNoteRequest::new("credit-note-lago-id".to_string());
let credit_note = client.get_credit_note(request).await?;

// Create a credit note
let items = vec![
    CreateCreditNoteItemInput::new("fee_lago_id".to_string(), 1000),
];
let input = CreateCreditNoteInput::new(
    "invoice_lago_id".to_string(),
    CreditNoteReason::Other,
    1000, // credit_amount_cents
    0,    // refund_amount_cents
    items,
)
.with_description("Credit for billing adjustment".to_string());
let request = CreateCreditNoteRequest::new(input);
let created = client.create_credit_note(request).await?;

// Update a credit note's refund status
let update_input = UpdateCreditNoteInput::new()
    .with_refund_status(CreditNoteRefundStatus::Succeeded);
let request = UpdateCreditNoteRequest::new("credit-note-lago-id".to_string(), update_input);
let updated = client.update_credit_note(request).await?;
```

### Customer Usage

```rust
use lago_types::requests::customer_usage::GetCustomerCurrentUsageRequest;

// Get current usage for a customer's subscription
let request = GetCustomerCurrentUsageRequest::new(
    "customer_123".to_string(),
    "subscription_456".to_string(),
);
let usage = client.get_customer_current_usage(request).await?;
println!("Total amount: {} cents", usage.customer_usage.total_amount_cents);
println!("Charges: {:?}", usage.customer_usage.charges_usage.len());

// Get usage without applying taxes
let request = GetCustomerCurrentUsageRequest::new(
    "customer_123".to_string(),
    "subscription_456".to_string(),
)
.with_apply_taxes(false);
let usage = client.get_customer_current_usage(request).await?;
```

## Error Handling

The client uses the `lago-types` error system:

```rust
use lago_types::error::LagoError;

match client.list_invoices(None).await {
    Ok(invoices) => println!("Success: {} invoices", invoices.invoices.len()),
    Err(LagoError::Unauthorized) => println!("Invalid API key"),
    Err(LagoError::RateLimit) => println!("Rate limit exceeded"),
    Err(LagoError::Api { status, message }) => {
        println!("API error {}: {}", status, message);
    }
    Err(e) => println!("Other error: {}", e),
}
```

## 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 usage
- `custom_configuration.rs` - Advanced configuration options
- `activity_log.rs` - Activity logs listing and filtering
- `api_log.rs` - API logs listing and filtering
- `billable_metric.rs` - Billable metrics management
- `customer.rs` - Customers management operations
- `invoice.rs` - Invoice operations including preview
- `applied_coupon.rs` - Applied coupons listing and filtering
- `coupon.rs` - Coupon CRUD operations
- `event.rs` - Event creation and retrieval
- `credit_note.rs` - Credit note operations
- `customer_usage.rs` - Customer usage retrieval
- `plan.rs` - Plan CRUD operations
- `subscription.rs` - Subscription CRUD operations

```bash
# Run the basic usage example
cargo run --example basic_usage

# Run the activity logs example
cargo run --example activity_log

# Run the API logs example
cargo run --example api_log

# Run the billable metrics example
cargo run --example billable_metric

# Run the customer management example
cargo run --example customer

# Run the invoice example
cargo run --example invoice

# Run the applied coupons example
cargo run --example applied_coupon

# Run the coupons example
cargo run --example coupon

# Run the events example
cargo run --example event

# Run the credit notes example
cargo run --example credit_note

# Run the customer usage example
cargo run --example customer_usage

# Run the plans example
cargo run --example plan

# Run the subscriptions example
cargo run --example subscription
```

## Release

Before publishing a release 

```shell
cargo check
cargo test
cargo doc --no-deps --open
cargo package
```

Run the release 

```shell
cargo login API_KEY
cargo publish
```

## License

This project is licensed under the same license as the parent Lago Rust Client.