loglens-sdk
v0.4.5
Published
AI observability SDK — wraps Anthropic and OpenAI clients and logs every request
Maintainers
Readme
loglens-sdk
See exactly what your AI is doing. LogLens is a lightweight LLM observability SDK that intercepts every Anthropic and OpenAI call your app makes and logs the prompt, completion, latency, token count, cost, and errors to a real-time dashboard — with one line of code.
No proxy. No framework lock-in. Works with your existing client.
Install
npm install loglens-sdkQuick start
Sign up at llm-watch.vercel.app and grab your API key from Settings, then wrap your existing client:
Anthropic
import Anthropic from "@anthropic-ai/sdk";
import { wrapAnthropic } from "loglens-sdk";
const anthropic = wrapAnthropic(new Anthropic(), {
apiKey: "lw_live_your_key", // from LogLens Settings
projectId: "my-app", // optional
});
// Use the client exactly as before — every call is now logged
const msg = await anthropic.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1024,
messages: [{ role: "user", content: "Hello" }],
});OpenAI
import OpenAI from "openai";
import { wrapOpenAI } from "loglens-sdk";
const openai = wrapOpenAI(new OpenAI(), {
apiKey: "lw_live_your_key",
projectId: "my-app",
});
const res = await openai.chat.completions.create({
model: "gpt-4o",
messages: [{ role: "user", content: "Hello" }],
});Then open your dashboard and watch the calls appear in real time.
Options
| Option | Type | Description |
| --- | --- | --- |
| apiKey | string | Your LogLens API key (required). |
| projectId | string | Label calls by project or feature for filtering. |
| userId | string | Attribute calls to a specific end user. |
| sessionId | string | Group calls belonging to the same session. |
| tags | string[] | Arbitrary labels, e.g. ["prod", "chat"]. |
| maskPrompts | boolean | When true, prompt and completion text is replaced with [masked] before leaving your app — only metadata (latency, tokens, cost) is sent. |
const anthropic = wrapAnthropic(new Anthropic(), {
apiKey: "lw_live_your_key",
projectId: "support-bot",
userId: req.user.id,
tags: ["prod"],
maskPrompts: true, // privacy-first: send metadata only
});What gets logged
Every call records:
- Prompt and completion text (unless
maskPromptsis enabled) - Model name
- Latency in milliseconds
- Token usage — input and output
- Cost in USD, computed from a built-in pricing table
- Errors — failed calls log the error type and message
How it works
The SDK wraps your existing client in place, so your TypeScript types and method calls are unchanged. Telemetry is sent fire-and-forget — a slow or unreachable LogLens endpoint will never block or crash your app. Streaming responses are fully supported, including exact token counts captured after the stream completes.
Streaming notes
- Anthropic:
messages.stream()andmessages.create({ stream: true })are both supported. Token counts are captured exactly from the final message. - OpenAI: for accurate token counts on streamed responses, pass
stream_options: { include_usage: true }in your request.
Privacy
LogLens stores prompt and completion text to power the dashboard. If you handle sensitive data, enable maskPrompts: true to send only metadata, or review the data handling page. Configurable log retention is available in your account settings.
Links
- Dashboard & sign-up: llm-watch.vercel.app
- Python SDK: pypi.org/project/loglens-sdk
- Source: github.com/DevMatrix06/LLM_WATCH
License
MIT
