Anthropic
Use autoLog() with the Anthropic client.
Overview
autoLog() is framework-agnostic. It does not care whether your application is built with Express, Next.js, a CLI tool, or a plain script. The only thing that matters is three steps:
- Create a provider client
Instantiate your Anthropic client as normal.
- Wrap it with autoLog()
Pass the client to
aiLogger.autoLog(anthropic)— this is the only change needed. - Use the wrapped variable for all AI calls
Use
clientinstead of your original instance. Every call through is automatically logged, secured and verified.
Usage example
import { AILogger } from "@integritas-technology/ai-logger";
import Anthropic from "@anthropic-ai/sdk";
const aiLogger = new AILogger({
systemId: "your-system-name",
});
// Step 1
const anthropic = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
});
// Step 2
const client = aiLogger.autoLog(anthropic);
// Step 3
const response = await client.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 100,
messages: [{ role: "user", content: "Hello!" }],
});
Always use the wrapped client variable for your calls — not the original
anthropic instance. Calls made through the unwrapped instance will not be
logged.
Works with any setup
It does not matter how the surrounding code is structured. As long as every AI call passes through the wrapped client, it will be captured and logged.
// Next.js API route — works fine
export async function POST(req: Request) {
const { message } = await req.json();
const response = await client.messages.create({
model: "claude-3-5-sonnet-20241022",
max_tokens: 100,
messages: [{ role: "user", content: message }],
});
return Response.json({ reply: response.content[0].text });
}