Loading...
Loading...
Start saving 50-80% on AI costs in 5 minutes.
💰 Save money automatically
Enable auto-optimization and smart routing to cut costs by 50-80%
.env
fileCOSTLENS_API_KEY=cl_your_key_here
npm install costlens
import { CostLens } from 'costlens';
import OpenAI from 'openai';
const openai = new OpenAI();
const costlens = new CostLens({
apiKey: process.env.COSTLENS_API_KEY,
autoOptimize: true, // 🚀 Saves 50-80% on tokens
smartRouting: true, // 🚀 Routes to cheapest model
enableCache: true, // 🚀 Saves 80% on repeated queries
costLimit: 0.10 // 🚀 Prevents budget overruns
});
// Wrap your client - savings happen automatically!
const tracked = costlens.wrapOpenAI(openai);
// Use it exactly like normal OpenAI
const result = await tracked.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Hello!' }]
});
// ✅ Prompt optimized, routed to cheaper model, cached, and tracked!
💰 Money-saving features: autoOptimize reduces tokens by 50-80%, smartRouting uses GPT-3.5 for simple queries (20x cheaper), and caching saves 80% on repeated prompts.
import { CostLens } from 'costlens';
import Anthropic from '@anthropic-ai/sdk';
const anthropic = new Anthropic();
const costlens = new CostLens({
apiKey: process.env.COSTLENS_API_KEY
});
// Wrap and use
const tracked = costlens.wrapAnthropic(anthropic);
const result = await tracked.messages.create({
model: 'claude-3-opus-20240229',
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello!' }]
});
// ✅ Done!
Your AI costs are being optimized automatically. Check your dashboard to see:
cl_