Class Content

java.lang.Object
com.google.genai.JsonSerializable
com.google.genai.types.Content

public abstract class Content extends JsonSerializable
Contains the multi-part content of a message.
  • Constructor Details

    • Content

      public Content()
  • Method Details

    • parts

      public abstract Optional<List<Part>> parts()
      List of parts that constitute a single message. Each part may have a different IANA MIME type.
    • role

      public abstract Optional<String> role()
      Optional. The producer of the content. Must be either 'user' or 'model'. Useful to set for multi-turn conversations, otherwise can be empty. If role is not specified, SDK will determine the role.
    • builder

      public static Content.Builder builder()
      Instantiates a builder for Content.
    • toBuilder

      public abstract Content.Builder toBuilder()
      Creates a builder with the same values as this instance.
    • fromJson

      public static Content fromJson(String jsonString)
      Deserializes a JSON string to a Content object.
    • fromParts

      public static Content fromParts(Part... parts)
      Constructs a Content from parts, assuming the role is "user".
    • text

      public @Nullable String text()
      Returns the concatenation of all text parts in this content.

      Returns null if there are no parts in the content. Returns an empty string if parts exists but none of the parts contain text.