Back to Guides

SDK Quickstart

5 min

Install the Bear Lumen SDK, initialize the client, and track your first AI call. Choose your language to get started.

Getting Started

1

Install the SDK

Install the Bear Lumen Node.js SDK via npm:

npm install @bearlumen/node-sdk
2

Initialize 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,
});
3

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}`);
4

Query Your Costs

Optional

Pull 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);

Next Steps