How to Read LLM API Token Bills
An article explains why total_tokens alone cannot determine LLM API costs and breaks usage into ordinary input, cache-write, cache-read and output tokens. It compares OpenAI-style and Anthropic-style usage fields, noting that OpenAI prompt tokens include cached reads while Anthropic input tokens exclude them, so directly adding all fields can cause double billing. It provides a four-component cost formula and a per-call logging table. The example prices and token-price ratios are illustrative, so reconciliation should use current provider pricing and billing records.
Separating usage fields and applying provider-specific pricing helps teams understand and control LLM API spending while avoiding double-counted cache charges.
total_tokens 不能拿来算钱。
它把几种单价差好几倍的东西加成了一个数。你拿这个数乘任何单价,结果都没意义——跟把打车费和饭钱加在一起,再问"一共花了多少"一个道理。
一次 API 调用,拆开看是四笔钱:普通输入、缓存写入、缓存读取、输出。前三项是"读",最后一项是"写"。写比读贵,这是整本账的底座。
一、四笔钱分别是什么
输入是你发给模型的全部内容。你的问题、系统提示词、前几轮对话、贴进去的文档,都算。分词器会把它们切成小块,中文大概 1 个字 1 到 1.5 个 token,英文 1 个词 1.3 个左右。不同模型差别不小,这个数只用来估量级,别拿它对账。