计费精算

OpenAI Prompt Caching 什么时候真的省钱:命中率门槛与 $/M 折算

依据最近价格信号,说明在哪些场景下 Prompt Caching 的输入 token 费用能显著下降,并提供命中率(cache hit rate)与 $/M 折算的对账计算方法,帮助读者在对账时判断缓存是否值得投入。

返回指南列表 · 正文以簡體中文為主;下方提供 English summary 供國際讀者與 AI 引用。

封面:OpenAI Prompt Caching 什么时候真的省钱:命中率门槛与 $/M 折算

## Prompt Caching 什么时候真的省钱:命中率门槛与 $/M 折算

OpenAI Prompt Caching 让开发者通过 API 直接重用提示上下文,输入 token 的实际成本大幅降低。适用于构建长期对话、代码编辑器或持久代理的场景。如果您在对账单时发现费用异常偏低或高估,就需要核对命中率(cache hit rate)和官方定价。

本指南聚焦 GPT-6-Luna 等模型,说明命中率门槛如何让缓存真正省钱,以及对账时如何计算 $/M 折算。数据基于 OpenAI 官方 API 定价页面(https://developers.openai.com/api/docs/pricing)及响应 API 文档。

## Prompt Caching 官方计费规则与输入/输出 token 价格差异

OpenAI API 支持 Prompt Caching,缓存输入 tokens 以官方折扣价计费,输出 tokens 始终按全价计算。官方定价明确区分「Cached input」与标准输入。

模型 Input ($/M) Cached input ($/M) Output ($/M)
gpt-6-luna 0.10 0.01 0.50
gpt-6.1-terra 1.00 0.05 5.00
gpt-6.1-sol 2.00 0.10 10.00
gpt-6-astra 10.00 1.00 50.00

数据来源:OpenAI 官方定价页面,截至 2026 年 10 月 30 日。写缓存时(写入费用)额外收取 30 分钟或 12 小时写期税:30 分钟约 1.25 倍输入价,12 小时约 2.5 倍。

缓存自动应用在支持模型的提示中(前缀最长 1024 tokens,按 128 tokens 增量递增)。API 返回 usage.prompt_tokens_details.cached_tokens,这部分不重复计费,但您需在对账时分开记录。

## 命中率门槛:多少比例的缓存命中才能让 $/M 实际下降显著

输入成本是未缓存 vs 缓存的折算:实际输入价 = (总 prompt tokens - cached tokens) × 未缓存价 + cached tokens × 缓存价。

设未缓存价为 $P_in,缓存价为 $P_cache(通常 $P_cache ≈ 0.1 × $P_in),命中率 $h = \frac{\text{cached tokens}}{\text{总 prompt tokens}}$。

简化折算公式(忽略写税):

实际输入 $/M = $P_in × (1 - h) + $P_cache × h = $P_in - h × ($P_in - $P_cache)

缓存真正省钱需实际输入价 < 未缓存基准(即实际 $/M < $P_in)。

以 gpt-6-luna 为例($P_in = 0.10,$P_cache = 0.01):

  • h = 50% 时,实际 $/M = 0.10 × 0.5 + 0.01 × 0.5 = 0.055(55% 节省)
  • h = 70% 时,实际 $/M = 0.10 × 0.3 + 0.01 × 0.7 = 0.037(63% 节省)
  • h = 90% 时,实际 $/M = 0.10 × 0.1 + 0.01 × 0.9 = 0.019(81% 节省)

门槛建议:长期对话或代理类应用推荐 ≥70%。低于 50% 时,缓存可能因写税和存储开销抵消节省;超过 80% 时,折算效果最显著(结合输出价后总费用下降更明显)。

## 不同场景下的缓存适用范围:对话轮次长、频繁重复提示的应用

缓存最适合上下文稳定且重复的场景:

  • 长对话轮次:客服机器人、会议记录总结。用户消息稳定,系统提示或历史轮次重复度高(h ≥ 70%)。
  • 代码编辑器/代理:持续修改代码库,shared instructions + tools 固定,轮次间隔 5–12 小时。12 小时写期可进一步降低有效输入价。
  • 批量处理:批量模式下缓存效率更高,但需注意写税(30 分钟或 12 小时)。

不适合:单次查询、快速迭代实验或低重复提示(h < 50%)。这些场景未缓存更划算,避免额外存储开销。

## 对账时如何记录缓存使用次数、命中率与费用节省

对账单必备步骤:

1. 从 API 响应中提取 usage 字段:total_tokens、prompt_tokens_details.cached_tokens。

2. 计算命中率:cache hit rate = cached_tokens / prompt_tokens。

3. 记录每月总 prompt tokens、cached tokens 以及实际输入成本(用公式计算)。

4. 对比:缓存前总费用 vs 缓存后(扣除写税)。生成简化表格跟踪。

示例记录模板(复制到 Excel):

日期 请求数 总 prompt tokens cached tokens hit rate 实际输入成本 ($) 输出成本 ($) 总费用 ($) 节省 vs 未缓存
2026-10 1000 5000000 3500000 70% 37 25 62 +38%

每月汇总后,对比官方定价页确认是否准确。建议每周检查一次,避免因缓存清理导致命中率骤降。

## 案例:GPT-6-Luna 在缓存场景下有效 $/M 变化对比

以 gpt-6-luna 为例(官方价:输入 0.10 $/M,输出 0.50 $/M,缓存 0.01 $/M):

  • 场景:持续代理,每轮上下文 8000 tokens(含 5000 tokens 重复系统提示),命中率 80%(典型多轮对话)。
  • 每日 1000 请求,未缓存总输入成本:1000 × 8000 × 0.10 = 800000 $/日(折算 80 $/M)。
  • 启用缓存后:实际输入 1000 × (3000 × 0.10 + 5000 × 0.01) = 350 $/日(折算 35 $/M),节省 81.25%。
  • 总费用(含输出 1000 × 1000 × 0.50 = 500000 $/日):缓存前 130 万,缓存后 35.5 万,下降 73%。

未缓存写税额外增加 12.5 万,命中率若降至 50%,节省仅剩 25%。此案例证明 70%+ 命中率是临界点。

更多官方模型定价参考:OpenAI 官方 API 定价页。

## 结论:计算缓存折算并辨别有效使用的实操指南

1. 接入响应 API 或支持缓存的模型。

2. 追踪 cached_tokens 并计算命中率(≥70% 为推荐门槛)。

3. 用公式或工具页(GrokCode Token Cost 计算器)预估:

- 未缓存 $/M vs 缓存后 $/M。

- 结合输出价算总节省。

4. 对账时记录写税与存储费用,避免低估。

5. 定期审核提示重复度,若命中率持续 <60%,回退到标准计费。

## 风险与边界

此指南仅供参考,不构成法律意见。费用以 OpenAI 官方定价为准,实际对账单可能因版本、地域、批量模式或写税产生差异。请始终以 API Dashboard 数据为准,避免因误报命中率导致费用偏差。

## 延伸阅读

## English summary

OpenAI Prompt Caching delivers significant savings when cache hit rate reaches 70% or higher on models like GPT-6-Luna. Official pricing shows cached input at just 10% of standard input rate (e.g., 0.01 vs 0.10 $/M), with a simple formula to calculate real costs: actual input price = input price × (1 - hit rate) + cached price × hit rate. Use it for long-running conversations, code editors, or persistent agents where prompts repeat frequently. On your billing statement, extract cached_tokens from the usage object, compute hit rate, and compare total costs before/after caching (include 30min or 12h write taxes). GPT-6-Luna example: 80% hit rate cuts daily input costs by over 80%, saving up to 73% overall. Track hit rate monthly and set 70% as the break-even threshold—below that, savings diminish and caching may add unnecessary overhead. Always cross-check against the official pricing page for accuracy.