-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalc_cost.ts
More file actions
42 lines (34 loc) · 1.3 KB
/
Copy pathcalc_cost.ts
File metadata and controls
42 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
const startOfDay = new Date();
startOfDay.setHours(0, 0, 0, 0);
const runs = await prisma.agentRun.findMany({
where: {
createdAt: {
gte: startOfDay,
}
},
select: {
tokensUsed: true,
estimatedCostInr: true
}
});
let totalTokens = 0;
let totalCost = 0;
for (const run of runs) {
if (run.tokensUsed) totalTokens += run.tokensUsed;
if (run.estimatedCostInr) totalCost += run.estimatedCostInr;
}
// If estimatedCostInr isn't fully populated, we can estimate manually.
// gpt-4o-mini cost is roughly $0.150 per 1M input tokens, $0.60 per 1M output tokens.
// Assuming a 70/30 split for input/output, blended rate is ~$0.285 per 1M tokens.
// 1 USD = ~83 INR. So 1M tokens = ~23.65 INR.
// Let's use the DB values first, and fallback to math if they are 0.
let fallbackCost = (totalTokens / 1_000_000) * 23.65;
console.log(`Runs Today: ${runs.length}`);
console.log(`Total Tokens Used: ${totalTokens}`);
console.log(`DB Estimated Cost: ₹${totalCost.toFixed(4)}`);
console.log(`Calculated Baseline Cost: ₹${fallbackCost.toFixed(4)}`);
}
main().then(() => process.exit(0)).catch(e => { console.error(e); process.exit(1); });