Developer Guide · 5 min

SDK Quickstart

Install the Bear Lumen SDK, initialize the client, and track your first AI call. Pick your language below and every example follows along.

Getting started

Examples in
  1. 1

    Install the SDK

    Install the Bear Lumen Node.js SDK via npm:

    npm install @bearlumen/node-sdk
  2. 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. 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. 4

    Query your costsOptional

    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