prompt 缓存
工作原理
缓存从消息数组的起始位置开始生效。请求到达时,系统会检查开头有多少条消息与之前的请求完全匹配;匹配的部分称为“前缀”,并由缓存直接提供:
首次请求 — 完整 prompt 会被处理并缓存
后续请求 — 如果 prompt 前缀匹配,就会复用已缓存的部分(即缓存命中)
计费 — 缓存 token 按较低费率计费
示例
请求 1:
[system] "You are a helpful assistant."
[user] "What is the capital of France?"
[assistant] "The capital of France is Paris."请求 2:
[system] "You are a helpful assistant." ← cached
[user] "What is the capital of France?" ← cached
[assistant] "The capital of France is Paris." ← cached
[user] "What about Germany?" ← new前 3 条消息与请求 1 完全匹配,因此由缓存直接提供;只有新增消息需要计算。
后续内容
最后更新:2026 年 3 月 16 日