Skip to content

Token usage

Defines the token usage schema.

Authors

Henry Wicaksono (henry.wicaksono@gdplabs.id)

References

NONE

InputTokenDetails

Bases: BaseModel

Defines the input token details schema.

Attributes:

Name Type Description
cached_tokens int

The number of cached tokens. Defaults to 0.

uncached_tokens int

The number of uncached tokens. Defaults to 0.

__add__(other)

Add two InputTokenDetails objects together.

Parameters:

Name Type Description Default
other InputTokenDetails

The other InputTokenDetails object to add.

required

Returns:

Name Type Description
InputTokenDetails InputTokenDetails

A new InputTokenDetails object with summed values.

OutputTokenDetails

Bases: BaseModel

Defines the output token details schema.

Attributes:

Name Type Description
reasoning_tokens int

The number of reasoning tokens. Defaults to 0.

response_tokens int

The number of response tokens. Defaults to 0.

__add__(other)

Add two OutputTokenDetails objects together.

Parameters:

Name Type Description Default
other OutputTokenDetails

The other OutputTokenDetails object to add.

required

Returns:

Name Type Description
OutputTokenDetails OutputTokenDetails

A new OutputTokenDetails object with summed values.

TokenUsage

Bases: BaseModel

Defines the token usage data structure of a language model.

Attributes:

Name Type Description
input_tokens int

The number of input tokens. Defaults to 0.

output_tokens int

The number of output tokens. Defaults to 0.

input_token_details InputTokenDetails | None

The details of the input tokens. Defaults to None.

output_token_details OutputTokenDetails | None

The details of the output tokens. Defaults to None.

__add__(other)

Add two TokenUsage objects together.

Parameters:

Name Type Description Default
other TokenUsage

The other TokenUsage object to add.

required

Returns:

Name Type Description
TokenUsage TokenUsage

A new TokenUsage object with summed values.

__repr__()

Return string representation of the TokenUsage.

Returns:

Name Type Description
str str

The string representation of the TokenUsage.

__str__()

Return string representation of the TokenUsage.

Returns:

Name Type Description
str str

The string representation of the TokenUsage.

from_token_details(input_tokens=None, output_tokens=None, cached_tokens=None, reasoning_tokens=None) classmethod

Creates a TokenUsage from token details.

Parameters:

Name Type Description Default
input_tokens int | None

The number of input tokens. Defaults to None.

None
output_tokens int | None

The number of output tokens. Defaults to None.

None
cached_tokens int | None

The number of cached tokens. Defaults to None.

None
reasoning_tokens int | None

The number of reasoning tokens. Defaults to None.

None

Returns:

Name Type Description
TokenUsage TokenUsage

The instantiated TokenUsage.