我如何意外地构建了一个 LLM 成本追踪工具

📄 中文摘要

上个月,我收到了一个让我感到震惊的 API 账单,金额高达2847美元,完全不知道费用来源。为了开发一个侧项目,我使用了多种服务,包括 OpenAI、Anthropic、Stripe、Supabase 和 SendGrid,每个服务都有自己的仪表盘和计费页面。每天早上,我不得不打开五个标签页检查费用是否异常,过程相当痛苦。于是,我编写了一个简单的脚本,拦截 API 调用并记录每次调用的费用。意外的是,我发现每个新用户的引导流程竟然产生了14次 LLM 调用,这让我意识到成本的来源。

📄 English Summary

How I accidentally built a cost tracking tool for LLMs

Last month, I received an API bill that shocked me with a total of $2,847, and I had no idea where the charges came from. While building a side project, I utilized several services including OpenAI, Anthropic, Stripe, Supabase, and SendGrid, each with its own dashboard and billing page. This led to the frustrating routine of checking five tabs every morning to monitor any spikes in costs. To address this, I wrote a simple script to intercept outgoing API calls and log the associated costs. Interestingly, I discovered that my onboarding flow was generating 14 LLM calls per new user, which highlighted the source of the expenses.

Powered by Cloudflare Workers + Payload CMS + Claude 3.5

数据源: OpenAI, Google AI, DeepMind, AWS ML Blog, HuggingFace 等