package com.ankurm.aimigration; import org.springframework.ai.chat.metadata.Usage; /** * Since Spring AI 2.0.3 (and so in 2.1.0) an Anthropic or Bedrock Converse prompt-token count * includes the cache reads and writes. Subtract them to get the full-price input; never add them. */ public final class UncachedTokens { private UncachedTokens() { } public static long of(Usage usage) { return usage.getPromptTokens() - orZero(usage.getCacheReadInputTokens()) - orZero(usage.getCacheWriteInputTokens()); } private static long orZero(Long value) { return value == null ? 0 : value; } }