Heuristic:1jehuang Jcode Cache Inclusive Awareness
| Knowledge Sources | |
|---|---|
| Domains | Telemetry, Cost_Optimization |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Telemetry tracks cache_read_input_tokens separately from input_tokens to prevent double-billing cached tokens in usage accounting.
Description
The Cache_Inclusive_Awareness heuristic ensures that cached input tokens are tracked separately in the telemetry pipeline. LLM providers (e.g., OpenAI, Anthropic) use prompt caching where previously-seen prompt prefixes are served from cache at reduced cost. The usage firehose schema includes cache_read_input_tokens and cache_creation_input_tokens as separate fields alongside input_tokens and output_tokens. This prevents double-counting: cached tokens should not be billed at the full input rate. The v2 usage contract (usage_contract_version: 2) enforces this separation, and incompatible clients are rejected before normalization or storage.
Usage
Use this heuristic when recording LLM token usage. Always separate cache_read_input_tokens from input_tokens in usage reports. This is the mandatory accounting practice for the v2 usage report endpoint (POST /v2/usage).
The Insight (Rule of Thumb)
- Action: Track
cache_read_input_tokensandcache_creation_input_tokensas separate firehose double fields. - Value: Usage contract version 2 required for v2 endpoint; incompatible clients rejected with HTTP 400.
- Trade-off: Slightly more complex schema but prevents cost over-reporting.
- Compatibility: The FIREHOSE_USAGE_SCHEMA includes all token types as doubles.
Reasoning
If cached tokens were counted as regular input tokens, usage accounting would over-report actual cost by the full input rate for tokens that were actually served from cache at a fraction of the cost. By tracking cache reads separately, the billing system can apply the correct cached rate. The v2 usage contract enforces this at the API level, rejecting clients that don't provide the cache-aware fields.
Code Evidence
Usage firehose schema from telemetry-worker/src/worker.js:329-334:
export const FIREHOSE_USAGE_SCHEMA = {
blobs: ["event", "event_id", "session_id", "id", "version", "os", "arch",
"source", "provider", "model", "build_channel", "occurred_at", "country"],
doubles: ["input_tokens", "output_tokens", "cache_read_input_tokens",
"cache_creation_input_tokens", "total_tokens", "responses", "is_ci", "usage_contract_version"],
};
v2 contract enforcement from telemetry-worker/src/worker.js:545-548:
// Reject incompatible clients before normalization or any storage side effects.
if (isUsageV2 && (body.event !== "usage_report" || body.usage_contract_version !== 2)) {
return jsonResponse({ error: "Expected usage_report with usage_contract_version 2" }, 400, cors);
}
Token fields in turn details from telemetry-worker/src/worker.js:1379-1385:
["input_tokens", body.input_tokens || 0],
["output_tokens", body.output_tokens || 0],
["cache_read_input_tokens", body.cache_read_input_tokens || 0],
["cache_creation_input_tokens", body.cache_creation_input_tokens || 0],
["total_tokens", body.total_tokens || 0],