Class TokenUsage

  • All Implemented Interfaces:

    
    public class TokenUsage
    
                        

    Represents the token usage of a response.

    • Constructor Detail

      • TokenUsage

        TokenUsage()
        Creates a new TokenUsage instance with all fields set to null.
      • TokenUsage

        TokenUsage(Integer inputTokenCount)
        Creates a new TokenUsage instance with the given input token count.
        Parameters:
        inputTokenCount - The input token count.
      • TokenUsage

        TokenUsage(Integer inputTokenCount, Integer outputTokenCount)
        Creates a new TokenUsage instance with the given input and output token counts.
        Parameters:
        inputTokenCount - The input token count, or null if unknown.
        outputTokenCount - The output token count, or null if unknown.
      • TokenUsage

        TokenUsage(Integer inputTokenCount, Integer outputTokenCount, Integer totalTokenCount)
        Creates a new TokenUsage instance with the given input, output and total token counts.
        Parameters:
        inputTokenCount - The input token count, or null if unknown.
        outputTokenCount - The output token count, or null if unknown.
        totalTokenCount - The total token count, or null if unknown.
    • Method Detail

      • inputTokenCount

         Integer inputTokenCount()

        Returns the input token count, or null if unknown.

        Returns:

        the input token count, or null if unknown.

      • outputTokenCount

         Integer outputTokenCount()

        Returns the output token count, or null if unknown.

        Returns:

        the output token count, or null if unknown.

      • totalTokenCount

         Integer totalTokenCount()

        Returns the total token count, or null if unknown.

        Returns:

        the total token count, or null if unknown.

      • sum

         static TokenUsage sum(TokenUsage first, TokenUsage second)

        Adds two token usages. If one of the token usages is null, the other is returned without changes. Fields which are null in both responses will be null in the result.

        Parameters:
        first - The first token usage to add.
        second - The second token usage to add.
        Returns:

        a new TokenUsage instance with the sum of token usages.

      • add

         TokenUsage add(TokenUsage that)

        Adds the token usage of two responses together.

        Fields which are null in both responses will be null in the result.

        Parameters:
        that - The token usage to add to this one.
        Returns:

        a new TokenUsage instance with the token usage of both responses added together.