Record Class ResponseMetadata

java.lang.Object
java.lang.Record
com.vaadin.flow.component.ai.provider.ResponseMetadata
Record Components:
finishReason - why the model stopped, worded as the underlying framework reports it — the vocabulary depends on both the model and the provider, see above — or null when no reason was reported
tokenUsage - the token usage of the turn, or null when unknown
All Implemented Interfaces:
Serializable

public record ResponseMetadata(String finishReason, ResponseMetadata.TokenUsage tokenUsage) extends Record implements Serializable
Metadata about an LLM response, published by an LLMProvider through LLMProvider.LLMRequest.metadataSink() when the model reports it.

The metadata describes the turn as far as the provider has observed it: when the turn contains tool-call round trips, the finish reason is the latest one observed and the token usage covers the round trips so far, as far as the underlying framework reports them. On a turn that completes normally the last published instance therefore describes the whole turn.

Finish reason vocabulary. Every model vendor words the reason differently and keeps adding values: a turn cut off at the output limit is "length" on OpenAI and "max_tokens" on Anthropic. Nothing here maps those onto a fixed set of Vaadin values, because such a set goes stale the moment a vendor adds one. Compare only against the values documented for the model you call, and treat an unrecognized value as unknown rather than as an error.

LangChain4JLLMProvider is a step further removed, and shows why the mapping is left alone: LangChain4j collapses the vendor's word onto its own five-constant FinishReason enum before Vaadin sees the response, so the value is that constant's name and both examples above arrive as "LENGTH". The collapsing is per integration and loses whatever it does not recognize — an unrecognized value reaches this record as null through its OpenAI integration and as "OTHER" through its Anthropic one. Use SpringAILLMProvider where the application needs the model's own word.

Since:
25.3
Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • ResponseMetadata

      public ResponseMetadata(String finishReason, ResponseMetadata.TokenUsage tokenUsage)
      Creates an instance of a ResponseMetadata record class.
      Parameters:
      finishReason - the value for the finishReason record component
      tokenUsage - the value for the tokenUsage record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • finishReason

      public String finishReason()
      Returns the value of the finishReason record component.
      Returns:
      the value of the finishReason record component
    • tokenUsage

      public ResponseMetadata.TokenUsage tokenUsage()
      Returns the value of the tokenUsage record component.
      Returns:
      the value of the tokenUsage record component