Track per-request costs across GPT-5.5, GPT-5.4, and GPT-5.4-mini. Attribute spend by developer and feature.
npm install costlens openaiWrap your OpenAI client for automatic tracking and cost optimization:
import { CostLens } from 'costlens';
import OpenAI from 'openai';
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const costlens = new CostLens({
apiKey: process.env.COSTLENS_API_KEY
});
const tracked = costlens.wrapOpenAI(openai);
// Use exactly like normal — tracking is automatic
const result = await tracked.chat.completions.create({
model: 'gpt-5.4',
messages: [{ role: 'user', content: 'Hello!' }]
});Works without a CostLens API key for development and testing:
const costlens = new CostLens();
const ai = costlens.wrapOpenAI(openai);Attribute costs to specific features or users:
const result = await tracked.chat.completions.create({
model: 'gpt-5.4',
messages: [{ role: 'user', content: 'Review this PR' }]
}, {
promptId: 'code-review',
userId: 'dev_alice',
});Streaming responses are tracked automatically after completion:
const stream = await tracked.chat.completions.stream({
model: 'gpt-5.4',
messages: [{ role: 'user', content: 'Tell me a story' }]
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}const costlens = new CostLens({
apiKey: process.env.COSTLENS_API_KEY,
enableCache: true
});
const tracked = costlens.wrapOpenAI(openai);
const result = await tracked.chat.completions.create(
{ model: 'gpt-5.4', messages: [...] },
{ cacheTTL: 3600000 } // 1 hour
);Process multiple requests in a single call for better performance:
const requests = [
{ provider: 'openai', model: 'gpt-5.4', tokens: 150, latency: 1200 },
{ provider: 'openai', model: 'gpt-5.4-mini', tokens: 100, latency: 800 },
];
await costlens.trackBatch(requests);| Model | Input | Output |
|---|---|---|
| GPT-5.4 | $2.50/1M | $15/1M |
| GPT-5.4-mini | $0.75/1M | $4.50/1M |
| GPT-5.5 | $5/1M | $30/1M |