Developer Guide · 10 min
Quickstart
Get up and running with Bear Lumen in 10 minutes. Track your first AI API call and query your costs.
Before you start
- A Bear Lumen account (sign up here)
- An API key from your dashboard settings
- Node.js 18+ or Python 3.9+ installed (or use the REST API from any language)
- An AI provider API key (e.g. OpenAI, Anthropic) for making calls to track
Installation & setup
- 1
Install the SDK
Install the Bear Lumen Node.js SDK:
npm install @bearlumen/node-sdk - 2
Initialize the client
Set up your API client 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. It auto-detects the provider and extracts token counts and cost:
import OpenAI from 'openai'; const openai = new OpenAI(); const response = await openai.chat.completions.create({ model: 'gpt-4o', messages: [{ role: 'user', content: 'Hello!' }], }); // Bear Lumen auto-detects the provider and extracts tokens + cost const result = await bear.track(response); console.log(`Cost: $${result.cost}`); - 4
Add attribution
Tag calls with a user, feature, or agent to see where your AI spend is going:
// Add attribution to know who spent what and where const result = await bear.track(response, { userId: 'user_123', feature: 'chat', agentId: 'support-bot', }); console.log(`User ${result.userId} spent $${result.cost} on ${result.model}`); - 5
Query your costsOptional
Pull cost breakdowns by model, provider, or user:
// See costs broken down by model const byModel = await bear.costs.byModel({ startDate: '2025-01-01', endDate: '2025-01-31', }); console.log(byModel); // See costs for a specific user const userCosts = await bear.costs.forUser('user_123').summary(); console.log(userCosts);
You're all set
You're now tracking AI costs with Bear Lumen. Every call you track builds a real-time picture of your AI spending by model, user, and feature.
Next steps
Need help?
Our team is here to help you get the most out of Bear Lumen. Email support →