TokenUsage

org.llm4s.llmconnect.model.TokenUsage
See theTokenUsage companion object
@Stable
final case class TokenUsage

Token usage statistics for a completion request.

Value parameters

cacheCreationTokens

Optional number of tokens written into the provider's prompt cache. When present, these tokens are billed at the cache-creation rate, which is typically higher than the normal input rate.

cachedTokens

Optional number of tokens served from the provider's prompt cache (cache read). When present, these tokens are billed at the cheaper cache-read rate.

completionTokens

Number of tokens in the completion (output).

promptTokens

Number of tokens in the prompt (input).

thinkingTokens

Optional number of tokens used for thinking/reasoning. Present when using reasoning modes with Claude or o1/o3 models. These tokens count toward billing but are separate from completion tokens.

totalTokens

Total tokens (prompt + completion).

Attributes

Companion
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def hasThinkingTokens: Boolean

Check if thinking tokens were used.

Check if thinking tokens were used.

Attributes

Total output tokens including thinking.

Total output tokens including thinking.

For billing purposes, thinking tokens are typically billed at the same rate as output tokens.

Attributes

def withCacheCreationTokens(cacheCreationTokens: Int): TokenUsage
def withCacheCreationTokens(cacheCreationTokens: Option[Int]): TokenUsage
def withCachedTokens(cachedTokens: Int): TokenUsage
def withCachedTokens(cachedTokens: Option[Int]): TokenUsage
def withCompletionTokens(completionTokens: Int): TokenUsage
def withPromptTokens(promptTokens: Int): TokenUsage
def withThinkingTokens(thinkingTokens: Int): TokenUsage
def withThinkingTokens(thinkingTokens: Option[Int]): TokenUsage
def withTotalTokens(totalTokens: Int): TokenUsage

Inherited methods

def productElementNames: Iterator[String]

Attributes

Inherited from:
Product
def productIterator: Iterator[Any]

Attributes

Inherited from:
Product