SDK Quickstart
5 minInstall the Bear Lumen SDK, initialize the client, and track your first AI call. Choose your language to get started.
Install the SDK
Install the Bear Lumen Node.js SDK via npm:
npm install @bearlumen/node-sdkInitialize the Client
Create a client instance with your API key:
import { BearLumen } from '@bearlumen/node-sdk';
const bear = new BearLumen({
apiKey: process.env.BEAR_LUMEN_API_KEY,
});Track an AI Call
Make an AI API call and pass the response to Bear Lumen for automatic cost tracking:
import OpenAI from 'openai';
const openai = new OpenAI();
const response = await openai.chat.completions.create({
model: 'gpt-4o',
messages: [{ role: 'user', content: 'Hello!' }],
});
const result = await bear.track(response, {
userId: 'user_123',
feature: 'chat',
});
console.log(`Cost: $${result.cost}`);Query Your Costs
OptionalPull cost breakdowns by model or user:
const byModel = await bear.costs.byModel({
startDate: '2025-01-01',
endDate: '2025-01-31',
});
console.log(byModel);
const userCosts = await bear.costs.forUser('user_123').summary();
console.log(userCosts);