Class InMemoryCostTracker

java.lang.Object
com.tnsai.llm.cost.InMemoryCostTracker
All Implemented Interfaces:
CostTracker

public class InMemoryCostTracker extends Object implements CostTracker
In-memory implementation of CostTracker.

Stores usage records in memory with thread-safe operations. Suitable for development, testing, and single-instance deployments.

Features

  • Thread-safe record storage
  • Efficient time-range queries
  • Automatic statistics calculation
  • Optional max records limit

Usage Example


 CostTracker tracker = InMemoryCostTracker.builder()
     .maxRecords(10000)
     .build();

 tracker.record(UsageRecord.builder()
     .modelId("gpt-4o")
     .inputTokens(1000)
     .outputTokens(500)
     .build());