Java / Kotlin SDK
Full reference for the NotiLens Java SDK. Compatible with Java 11+ and Kotlin.
Installation
Install
<!-- Maven -->
<dependency>
<groupId>com.notilens</groupId>
<artifactId>notilens</artifactId>
<version>0.4.1</version>
</dependency>
// Gradle (Kotlin DSL)
implementation("com.notilens:notilens:0.4.1")Setup
Initialize
import com.notilens.NotiLens;
// Java
NotiLens nl = NotiLens.init("my-app", "YOUR_TOKEN", "YOUR_SECRET");
// Or use environment variables
NotiLens nl = NotiLens.init("my-app");
// Kotlin
val nl = NotiLens.init("my-app", "YOUR_TOKEN", "YOUR_SECRET")Task Lifecycle
Task Events
Real-world uses: wrap an AI research agent (start → progress → complete/fail), a nightly invoice import (loop per batch → complete), or a user-triggered export (start → output_generated → complete).
NotiLens.Run run = nl.task("email");
run.queue();
run.start();
run.progress("Fetching records...");
run.loop("Processing batch 2");
run.retry();
run.pause("Rate limited");
run.resume("Resuming");
run.wait("Awaiting tool");
run.error("Non-fatal error");
run.complete("All done");
run.fail("Unrecoverable");
run.timeout("Exceeded 30s");
run.cancel("User cancelled");
run.terminate("OOM");Metrics
Metrics
Real-world uses: track LLM token spend across a multi-step run. Monitor records in a nightly ETL — NotiLens alerts if count drops vs baseline. Watch API error rate across runs.
run.metric("tokens", 350);
run.metric("tokens", 210); // now 560
run.metric("cost", 0.0012);
run.metric("model", "gpt-4");
run.resetMetrics("tokens");
run.resetMetrics();Full Example
Complete Working Example
import com.notilens.NotiLens;
NotiLens nl = NotiLens.init("summarizer", "TOKEN", "SECRET");
NotiLens.Run run = nl.task("report");
run.start();
try {
run.progress("Fetching PDF");
Result result = llm.complete(prompt);
run.metric("tokens", result.getUsage().getTotalTokens());
run.metric("cost", result.getUsage().getCost());
run.outputGenerated("Summary ready");
run.complete("Done");
} catch (Exception e) {
run.fail(e.getMessage());
}