Content.Builder

classContent.Builder


Builder class to facilitate constructing complexContent objects.

Summary

Public constructors

Public functions

Content

Returns a newContent using the definedrole andparts.

Content.Builder
fileData(uri: String, mimeType: String)

Adds a newFileDataPart with the provideduri andmimeType toparts.

Content.Builder
image(image: Bitmap)

Adds a newImagePart with the providedimage toparts.

Content.Builder
inlineData(bytes: ByteArray, mimeType: String)

Adds a newInlineDataPart with the providedbytes, which should be interpreted by the model based on themimeType, toparts.

Content.Builder
<T : Part>part(data: T)

Adds a newPart toparts.

Content.Builder
Content.Builder
setRole(role: String?)
Content.Builder
text(text: String)

Adds a newTextPart with the providedtext toparts.

Public properties

MutableList<Part>

The mutable list ofParts comprising theContent.

String?

The producer of the content.

Public constructors

Builder

Builder()

Public functions

build

fun build(): Content

Returns a newContent using the definedrole andparts.

fileData

fun fileData(uri: String, mimeType: String): Content.Builder

Adds a newFileDataPart with the provideduri andmimeType toparts.

image

fun image(image: Bitmap): Content.Builder

Adds a newImagePart with the providedimage toparts.

inlineData

fun inlineData(bytes: ByteArray, mimeType: String): Content.Builder

Adds a newInlineDataPart with the providedbytes, which should be interpreted by the model based on themimeType, toparts.

part

fun <T : Part>part(data: T): Content.Builder

Adds a newPart toparts.

setParts

fun setParts(parts: MutableList<Part>): Content.Builder

setRole

fun setRole(role: String?): Content.Builder

text

fun text(text: String): Content.Builder

Adds a newTextPart with the providedtext toparts.

Public properties

parts

var partsMutableList<Part>

The mutable list ofParts comprising theContent.

Prefer using the provided helper methods over modifying this list directly.

role

var roleString?

The producer of the content. Must be either 'user' or 'model'. By default, it's "user".

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-07-21 UTC.