Class OpenAiImageTokenUsage

java.lang.Object
dev.langchain4j.model.output.TokenUsage
dev.langchain4j.model.openai.OpenAiImageTokenUsage

public class OpenAiImageTokenUsage extends TokenUsage
Token usage of an OpenAI image generation or edit request, as returned by OpenAiImageModel in Response.tokenUsage().

In addition to the input, output and total token counts, it reports how many of the input and output tokens were image tokens and how many were text tokens. OpenAI prices these differently, so the split is needed to compute the cost of a request.

Only models that report usage (such as gpt-image-1) return it. For other models (such as dall-e-3), Response#tokenUsage() is null.

Since:
1.21.0
  • Method Details

    • inputTokensDetails

      public OpenAiImageTokenUsage.TokensDetails inputTokensDetails()
      Returns the breakdown of the input tokens into image and text tokens, or null if OpenAI did not report it.
    • outputTokensDetails

      public OpenAiImageTokenUsage.TokensDetails outputTokensDetails()
      Returns the breakdown of the output tokens into image and text tokens, or null if OpenAI did not report it.
    • add

      public OpenAiImageTokenUsage add(TokenUsage that)
      Description copied from class: TokenUsage
      Adds the token usage of two responses together.

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

      When one of the two is an instance of a TokenUsage subclass, that subclass performs the addition, so that the extra fields it carries are preserved. The result then has the type of that subclass, no matter which of the two sides it was on.

      A subclass carrying extra fields should therefore override this method and sum those fields as well. When neither side overrides it, there is nothing that knows how to sum the extra fields and the result is a plain TokenUsage.

      Overrides:
      add in class TokenUsage
      Parameters:
      that - The token usage to add to this one.
      Returns:
      a new TokenUsage instance with the token usage of both responses added together.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class TokenUsage
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class TokenUsage
    • toString

      public String toString()
      Overrides:
      toString in class TokenUsage
    • builder

      public static OpenAiImageTokenUsage.Builder builder()