Pre-execution cost prediction and budget enforcement for LLM applications. Stop bill shock before it happens.
AI costs are unpredictable and can spiral out of control. Current tools only tell you after the damage is done.
"$120 OpenAI bill after AutoGPT ran 8 hours unchecked" - Real developer stories from every AI community.
LangChain, CrewAI, AutoGPT - none of them have built-in cost controls. They leave it entirely to developers.
Context accumulation in agents compounds every turn. What starts at $0.01 can reach $10 in minutes.
Tokencap predicts costs before execution and enforces budgets automatically. Open source and MIT licensed.
Know exactly what a request will cost before you send it. Exact input costs, output estimates with confidence intervals.
Set hard caps per request, session, or project. Automatic termination at limits with graceful degradation options.
Track costs across multi-step workflows. Iteration-aware budgets with loop detection and circuit breakers.
Monitor costs by project, user, or model. Historical trends, alerts, and team-wide visibility.
Drop-in replacement for your existing OpenAI client. Start tracking costs in minutes.
import { Tokencap } from '@tokencap/sdk';
// Initialize with your API key
const tokencap = new Tokencap({
apiKey: process.env.TOKENCAP_API_KEY,
budget: {
maxCostPerRequest: 0.10, // $0.10 max per request
maxCostPerSession: 5.00, // $5.00 max per session
}
});
// Wrap your OpenAI client
const openai = tokencap.wrap(
new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
);
// Get cost estimate before execution
const estimate = await tokencap.estimate({
model: 'gpt-4',
messages: [{ role: 'user', content: prompt }]
});
console.log(estimate);
// { inputCost: 0.03, outputCost: { min: 0.02, max: 0.08 }, total: { min: 0.05, max: 0.11 } }
// Execute with automatic budget enforcement
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: prompt }]
});
// Automatically tracks cost and enforces budget limits
Start free, scale as you grow. Open source core with optional hosted dashboard.
Perfect for side projects and experimentation.
For growing teams building production AI apps.
For teams that need more capacity and control.
Join developers who are taking control of their AI costs. Open source, MIT licensed, and ready to use.