Getting Started

IntroductionLocal ProxySDK Quick Start

AI ROI

Analytics & ReportsTeam ManagementGitHub Integration

Cost Management

Smart RoutingBudget & AlertsPrompt ClassifierCaching & Performance

Integrations

OpenAIAnthropicMCP ServerSlack

Reference

SDKREST APIErrors
Docs/Getting Started/SDK Quick Start

Quick Start

Get CostLens running in your project in 2 minutes.

1. Install

npm install costlens

2. Get your API key

Go to Settings → API Keys and create a key. Add it to your environment:

.env

COSTLENS_API_KEY=cl_your_key_here

3. Wrap your client

app.ts

import { CostLens } from 'costlens'
import OpenAI from 'openai'

const costlens = new CostLens({
  apiKey: process.env.COSTLENS_API_KEY
})

// Wrap once
const openai = costlens.wrapOpenAI(new OpenAI())

// Use exactly like normal — tracking is automatic
const result = await openai.chat.completions.create({
  model: 'gpt-5.4',
  messages: [{ role: 'user', content: 'Summarize this document' }]
})

That's it. Every request is now tracked with cost, tokens, latency, and model used.

4. Tag requests (optional)

Add tags to attribute costs to specific features or users:

app.ts

const result = await openai.chat.completions.create({
  model: 'gpt-5.4',
  messages: [{ role: 'user', content: 'Review this PR' }]
}, {
  promptId: 'code-review',    // Track by feature
  userId: 'dev_alice',        // Track by developer
})

View per-developer and per-feature breakdowns in Analytics.

5. Invite your team

A workspace is created automatically when you sign up. Invite team members from Settings → Team.

Owner — full access, billing, invite/remove members

Admin — manage settings and API keys

Member — view dashboard and analytics

Each member's API calls are automatically attributed to them in the analytics dashboard.

6. Set up budget alerts

Configure alerts in Settings → Alerts:

Cost spike — alert when daily spend exceeds a threshold

Error rate — alert when failure rate exceeds a percentage

Slow response — alert when latency exceeds a threshold

7. Connect Slack (optional)

Receive budget alerts in your Slack channel:

  1. Create an Incoming Webhook in your Slack workspace
  2. Copy the webhook URL (starts with https://hooks.slack.com/services/...)
  3. Paste it in Settings → Alerts → Slack Notifications
  4. Click "Test" to verify the connection

8. Enable smart routing (optional)

CostLens can automatically route simple prompts to cheaper models:

app.ts

const costlens = new CostLens({
  apiKey: process.env.COSTLENS_API_KEY,
  smartRouting: true,     // Route simple prompts to cheaper models
  enableCache: true,      // Cache repeated requests
  costLimit: 0.10,        // Max $0.10 per request
})

Configure routing strategy and quality thresholds in Settings → Routing.

Next steps

OpenAI integration guide →Anthropic integration guide →Full SDK reference →REST API docs →

Previous

← Local Proxy

Next

Analytics & Reports →