Table of Contents

Class ModalityTokenCount

Namespace
Google.GenAI.Types
Assembly
Google.GenAI.dll

Represents a breakdown of token usage by modality. This message is used in CountTokensResponse and GenerateContentResponse.UsageMetadata to provide a detailed view of how many tokens are used by each modality (e.g., text, image, video) in a request. This is particularly useful for multimodal models, allowing you to track and manage token consumption for billing and quota purposes.

public record ModalityTokenCount : IEquatable<ModalityTokenCount>
Inheritance
ModalityTokenCount
Implements
Inherited Members

Properties

Modality

The modality that this token count applies to.

[JsonPropertyName("modality")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public MediaModality? Modality { get; set; }

Property Value

MediaModality?

TokenCount

The number of tokens counted for this modality.

[JsonPropertyName("tokenCount")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? TokenCount { get; set; }

Property Value

int?

Methods

FromJson(string, JsonSerializerOptions?)

Deserializes a JSON string to a ModalityTokenCount object.

public static ModalityTokenCount? FromJson(string jsonString, JsonSerializerOptions? options = null)

Parameters

jsonString string

The JSON string to deserialize.

options JsonSerializerOptions

Optional JsonSerializerOptions.

Returns

ModalityTokenCount

The deserialized ModalityTokenCount object, or null if deserialization fails.