class TextUsage extends Usage

Methods

__construct(int $inputTokens = 0, int $outputTokens = 0, int|null $cacheReadInputTokens = null, int|null $cacheWriteInputTokens = null, int|null $reasoningTokens = null)

Create text generation usage data.

int
totalTokens()

Get the total number of input and output tokens.

from  Usage
array
toArray()

Get the instance as an array.

array
jsonSerialize()

Get the JSON serializable representation of the instance.

from  Usage
static TextUsage
fromArray(array $data)

Reconstruct an instance from a previously serialized toArray() payload.

int
uncachedInputTokens()

Get the input tokens that were neither read from nor written to a prompt cache.

add(TextUsage $usage)

Add the given usage to the current usage and return a new usage instance.

static int|null
sum(int|null $a, int|null $b)

Sum two optional counts, preserving null when neither was reported.

Details

at line 18
__construct(int $inputTokens = 0, int $outputTokens = 0, int|null $cacheReadInputTokens = null, int|null $cacheWriteInputTokens = null, int|null $reasoningTokens = null)

Create text generation usage data.

Parameters

int $inputTokens
int $outputTokens
int|null $cacheReadInputTokens

subset of the input tokens read from a prompt cache, or null when unreported

int|null $cacheWriteInputTokens

subset of the input tokens written to a prompt cache, or null when unreported

int|null $reasoningTokens

subset of the output tokens spent on reasoning, or null when unreported

in Usage at line 24
int totalTokens()

Get the total number of input and output tokens.

Return Value

int

at line 77
array toArray()

Get the instance as an array.

Return Value

array

in Usage at line 43
array jsonSerialize()

Get the JSON serializable representation of the instance.

Return Value

array

at line 33
static TextUsage fromArray(array $data)

Reconstruct an instance from a previously serialized toArray() payload.

Parameters

array $data

Return Value

TextUsage

at line 47
int uncachedInputTokens()

Get the input tokens that were neither read from nor written to a prompt cache.

Return Value

int

at line 55
TextUsage add(TextUsage $usage)

Add the given usage to the current usage and return a new usage instance.

Parameters

TextUsage $usage

Return Value

TextUsage

at line 69
static protected int|null sum(int|null $a, int|null $b)

Sum two optional counts, preserving null when neither was reported.

Parameters

int|null $a
int|null $b

Return Value

int|null