Show HN: I built CostLens SDK to cut my AI bills by routing to cheaper models

My OpenAI bills were getting out of hand - I was using GPT-4 for everything, even simple tasks that GPT-3.5 could handle perfectly.

So I built CostLens. It's a drop-in replacement that automatically routes requests to cheaper models when possible, but falls back to premium ones when quality matters.

How it works: js // Just swap this: const openai = new OpenAI({ apiKey: 'sk-...' });

// For this: const costlens = new CostLens(); const openai = costlens.openai({ apiKey: 'sk-...' }); // Everything else stays exactly the same

Real savings: • Simple tasks: GPT-4 → GPT-4o-mini (95% cheaper) • Complex tasks: Still uses GPT-4 when needed • My bills dropped ~70% with zero code changes

Features: • Quality detection (auto-retries with better models if response is bad) • Works with existing code - no prompt changes needed • Caching with Redis • Instant mode (no signup required)

Try it: npm install costlens

The core SDK is free and works locally. I'm also building a dashboard for teams to track their AI spending.

NPM: https://www.npmjs.com/package/costlens

Anyone else tired of overpaying for AI APIs? What's your biggest cost pain point?

2 points j_filipe 11 months ago 2 comments

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton