Skip to content

LanguageModelUsage

Namespace: Vercel.AI.Provider

public sealed class LanguageModelUsage

Token counts for a model call.

Inheritance: object

View source

LanguageModelUsage(int?, int?, int?, int?, int?, int?, JsonElement?, int?, int?)

Section titled “LanguageModelUsage(int?, int?, int?, int?, int?, int?, JsonElement?, int?, int?)”
public LanguageModelUsage(int? inputTokens, int? outputTokens, int? totalTokens, int? cacheReadTokens = null, int? cacheWriteTokens = null, int? reasoningTokens = null, JsonElement? raw = null, int? noCacheInputTokens = null, int? textTokens = null)

Creates usage counts.

Parameters

Name Type Description
inputTokens int?
outputTokens int?
totalTokens int?
cacheReadTokens int?
cacheWriteTokens int?
reasoningTokens int?
raw JsonElement?
noCacheInputTokens int?
textTokens int?

View source

public int? CacheReadTokens { get; }

Input tokens read from cache, when the provider reports them.

Value: int?

View source

public int? CacheWriteTokens { get; }

Input tokens written to cache, when the provider reports them.

Value: int?

View source

public static LanguageModelUsage Empty { get; }

Zero usage.

Value: LanguageModelUsage

View source

public int? InputTokens { get; }

Prompt tokens.

Value: int?

View source

public int? NoCacheInputTokens { get; }

Input tokens that were not served from cache, when the provider reports them.

Value: int?

View source

public static LanguageModelUsage Null { get; }

Usage with every count and Raw unset. It is the start value for adding steps.

Value: LanguageModelUsage

View source

public int? OutputTokens { get; }

Generated tokens.

Value: int?

View source

public JsonElement? Raw { get; }

Provider usage object, unchanged.

Value: JsonElement?

View source

public int? ReasoningTokens { get; }

Output tokens spent on reasoning, when the provider reports them.

Value: int?

View source

public int? TextTokens { get; }

Output tokens that were not reasoning tokens, when the provider reports them.

Value: int?

View source

public int? TotalTokens { get; }

Input plus output tokens.

Value: int?

View source

Add(LanguageModelUsage, LanguageModelUsage)

Section titled “Add(LanguageModelUsage, LanguageModelUsage)”
public static LanguageModelUsage Add(LanguageModelUsage left, LanguageModelUsage right)

Adds two usage values. Raw survives only when one side is Null.

Parameters

Name Type Description
left LanguageModelUsage
right LanguageModelUsage

Returns: LanguageModelUsage

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product