{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreiftd35iaumv66n65p7r5f53vdmi2nitqttpkxx67tqlw6n5bcxmdi",
    "uri": "at://did:plc:lk3jfj3zq4k4wxnk474axylu/app.bsky.feed.post/3mlsqvr7emdy2"
  },
  "path": "/t/how-to-calculate-only-uncached-tokens/1380908#post_2",
  "publishedAt": "2026-05-14T09:59:49.000Z",
  "site": "https://community.openai.com",
  "tags": [
    "OpenAI Agents SDK",
    "Usage"
  ],
  "textContent": "Hi and welcome back!\n\nYes. `inputTokens` is the total input token count, including both cached and uncached tokens.\n\nThe Agents SDK docs describe `inputTokens` as the number of input tokens used across all requests, and `inputTokensDetails` as the breakdown for those input tokens.\n\nSo this is the right calculation:\n\n`uncachedInputTokens = inputTokens - cachedTokens`\n\nFor the Agents SDK `inputTokensDetails` is an array. Sum the cached token entries first:\n\n\n    const cachedTokens =\n      usage.inputTokensDetails?.reduce(\n        (sum, details) => sum + (details.cached_tokens ?? details.cachedTokens ?? 0),\n        0\n      ) ?? 0;\n\n    const uncachedInputTokens = usage.inputTokens - cachedTokens;\n\n\nFor cost estimation treat them as separate buckets:\n\n\n    cost =\n      uncachedInputTokens * normalInputTokenRate +\n      cachedTokens * cachedInputTokenRate +\n      outputTokens * outputTokenRate;\n\n\nOpenAI Agents SDK\n\n### Usage",
  "title": "How to calculate only uncached tokens"
}