How to calculate only uncached tokens
OpenAI Developer Community
May 14, 2026
Hi and welcome back!
Yes. inputTokens is the total input token count, including both cached and uncached tokens.
The Agents SDK docs describe inputTokens as the number of input tokens used across all requests, and inputTokensDetails as the breakdown for those input tokens.
So this is the right calculation:
uncachedInputTokens = inputTokens - cachedTokens
For the Agents SDK inputTokensDetails is an array. Sum the cached token entries first:
const cachedTokens =
usage.inputTokensDetails?.reduce(
(sum, details) => sum + (details.cached_tokens ?? details.cachedTokens ?? 0),
0
) ?? 0;
const uncachedInputTokens = usage.inputTokens - cachedTokens;
For cost estimation treat them as separate buckets:
cost =
uncachedInputTokens * normalInputTokenRate +
cachedTokens * cachedInputTokenRate +
outputTokens * outputTokenRate;
OpenAI Agents SDK
Discussion in the ATmosphere