# GenerativeModel


```
public interface GenerativeModel
```

<br />

*** ** * ** ***

Provides an interface for performing content generation.

It supports both standard and streaming inferences, as well as methods for preparing and cleaning up model resources.

Typical usage:

```
val request = generateContentRequest { text("Your input text here.") }

try {
  val result = generativeModel.generateContent(request)
  println(result.text)
} catch (e: GenAiException) {
  // Handle exception
}
```

## Summary

| ### Public methods |
|---|---|
| `abstract @https://developers.google.com/android/reference/com/google/mlkit/genai/common/FeatureStatus int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#checkStatus()()` Checks the current availability status of the content generation feature. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#clearImplicitCaches()()` Clears all caches created by implicit prefix caching. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#close()()` Releases resources associated with the content generation engine. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#countTokens(com.google.mlkit.genai.prompt.GenerateContentRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request)` Counts the number of tokens in the request. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#countTokens(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest<@https://developer.android.com/reference/androidx/annotation/NonNull.html T> request )` Counts the number of tokens in the request for generating a typed response. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#download()()` Downloads the required model assets for the content generation feature if they are not already available. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt)` Performs asynchronous content generation on the provided input prompt. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request)` Performs asynchronous content generation on the provided input request. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentResponse<@https://developer.android.com/reference/androidx/annotation/NonNull.html T>` | `<T extends https://developer.android.com/reference/java/lang/Object.html> https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest<@https://developer.android.com/reference/androidx/annotation/NonNull.html T> request )` Performs asynchronous content generation on the provided input request, returning a strongly typed response. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(kotlin.String,com.google.mlkit.genai.common.StreamingCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback streamingCallback )` Performs streaming content generation inference on the provided input prompt. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest,com.google.mlkit.genai.common.StreamingCallback)( @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request, @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback streamingCallback )` Performs streaming content generation inference on the provided input request. |
| `default @https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContentStream(kotlin.String)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt)` Performs streaming content generation inference on the provided input prompt. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContentStream(com.google.mlkit.genai.prompt.GenerateContentRequest)(@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request)` Performs streaming content generation inference on the provided input request. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/Integer.html>` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getAvailableFeatures()()` Returns the list of features (capabilities) available for this model. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getBaseModelName()()` Returns the name of the base model used by this generator instance. |
| `abstract @https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Caches` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getCaches()()` Provides explicit management of cached contexts. |
| `abstract int` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getTokenLimit()()` Returns total token limit for the API including both input and output tokens. |
| `abstract boolean` | `[isCachingFeatureAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isCachingFeatureAvailable())()` **This method is deprecated.** Use getAvailableFeatures() instead. |
| `abstract boolean` | `[isStructuredOutputFeatureAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isStructuredOutputFeatureAvailable())()` **This method is deprecated.** Use getAvailableFeatures() instead. |
| `abstract boolean` | `[isSystemPromptAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isSystemPromptAvailable())()` **This method is deprecated.** Use getAvailableFeatures() instead. |
| `abstract boolean` | `[isThinkingModeAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isThinkingModeAvailable())()` **This method is deprecated.** Use getAvailableFeatures() instead. |
| `abstract void` | `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#warmup()()` Warms up the inference engine for use by loading necessary models and initializing runtime components. |

## Public methods

### checkStatus

```
abstract @FeatureStatus int checkStatus()
```

Checks the current availability status of the content generation feature.

| Returns |
|---|---|
| `@https://developers.google.com/android/reference/com/google/mlkit/genai/common/FeatureStatus int` | a feature status indicating the feature's readiness. |

### clearImplicitCaches

```
abstract void clearImplicitCaches()
```

Clears all caches created by implicit prefix caching.

This experimental method clears all caches created by implicit prefix caching. When `promptPrefix` is provided in `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest)` or `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContentStream(com.google.mlkit.genai.prompt.GenerateContentRequest)`, the system caches its processing implicitly to reduce inference time for subsequent requests sharing the same prefix. This method clears all such created caches.

### close

```
abstract void close()
```

Releases resources associated with the content generation engine.

This should be called when the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel` is no longer needed. Can be safely called multiple times.

### countTokens

```
abstract @NonNull CountTokensResponse countTokens(@NonNull GenerateContentRequest request)
```

Counts the number of tokens in the request.

The number of tokens counted includes only input request tokens. The result can be compared with `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getTokenLimit()` to check if the request is within the token limit.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` containing input content. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` containing the number of tokens in the request. |

### countTokens

```
abstract @NonNull CountTokensResponse <T extends Object> countTokens(
    @NonNull GenerateTypedContentRequest<@NonNull T> request
)
```

Counts the number of tokens in the request for generating a typed response.

This is an experimental feature.

The number of tokens counted includes only input request tokens. The result can be compared with `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#getTokenLimit()` to check if the request is within the token limit.

If `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest#includeSchemaInPrompt()` is `true`, the token count will also include tokens related to the response schema definition.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest<@https://developer.android.com/reference/androidx/annotation/NonNull.html T> request` | A non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest` containing input content and output type information. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` | A `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/CountTokensResponse` containing the number of tokens in the request. |

### download

```
abstract @NonNull Flow<@NonNull DownloadStatus> download()
```

Downloads the required model assets for the content generation feature if they are not already available.

Use this method to proactively download models before inference. The returned `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` emits `https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus` to report progress and completion status.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus>` | a `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` which will emit `https://developers.google.com/android/reference/com/google/mlkit/genai/common/DownloadStatus`s for download progress updates. |

### generateContent

```
default @NonNull GenerateContentResponse generateContent(@NonNull String prompt)
```

Performs asynchronous content generation on the provided input prompt.

This is a convenience method that wraps the input prompt in a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` with default generation parameters.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt` | the input prompt text. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` containing the generated content. |

| Throws |
|---|---|
| `GenAiException` | if the inference fails. |

| See also |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest)` | (request: GenerateContentRequest) |

### generateContent

```
abstract @NonNull GenerateContentResponse generateContent(@NonNull GenerateContentRequest request)
```

Performs asynchronous content generation on the provided input request.

This is the standard, non-streaming version of inference. The full generation suggestions are returned once the model completes processing.

This method is non-blocking. To handle the result, callers should use `try`/`catch` to handle the returned `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` or a potential GenAiException.

The coroutine that runs `generateContent` is cancellable. If the inference is no longer needed (e.g., the user navigates away or input changes), the coroutine can be cancelled.

Note that inference requests may fail under certain conditions such as:

- Invalid or malformed input in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest`.

- Exceeded usage quota or failed safety checks.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` containing input content. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` containing the generated content. |

| Throws |
|---|---|
| `GenAiException` | if the inference fails. |

### generateContent

```
abstract @NonNull GenerateTypedContentResponse<@NonNull T> <T extends Object> generateContent(
    @NonNull GenerateTypedContentRequest<@NonNull T> request
)
```

Performs asynchronous content generation on the provided input request, returning a strongly typed response.

This is an experimental feature.

This is the standard, non-streaming version of inference. The full generation suggestions are returned once the model completes processing. The model's response is parsed into an instance of the class specified by outputClass.

This method is non-blocking. To handle the result, callers should use `try`/`catch` to handle the returned `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentResponse` or a potential GenAiException.

The coroutine that runs `generateContent` is cancellable. If the inference is no longer needed (e.g., the user navigates away or input changes), the coroutine can be cancelled.

Note that inference requests may fail under certain conditions such as:

- Invalid or malformed input in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest`.

- Exceeded usage quota or failed safety checks.

- The output class is missing the `@Generable` annotation, throwing a GenAiException with GenAiException.ErrorCode.STRUCTURED_OUTPUT_REQUEST_ERROR.

- Failure to parse the model output into type `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)`, throwing a GenAiException with GenAiException.ErrorCode.STRUCTURED_OUTPUT_RESPONSE_ERROR. This can occur if:

  - The response reaches the token limit, resulting in incomplete output.

  - The model's response is malformed or incompatible with the type `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest<@https://developer.android.com/reference/androidx/annotation/NonNull.html T> request` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentRequest` containing input content. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentResponse<@https://developer.android.com/reference/androidx/annotation/NonNull.html T>` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateTypedContentResponse` containing the generated content as a parsed object of type `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)`. |

| Throws |
|---|---|
| `GenAiException` | if the inference fails or the output cannot be parsed into the type `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateTypedContentRequest)`. |

### generateContent

```
default @NonNull GenerateContentResponse generateContent(
    @NonNull String prompt,
    @NonNull StreamingCallback streamingCallback
)
```

Performs streaming content generation inference on the provided input prompt.

This is a convenience method that wraps the input prompt in a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` with default generation parameters.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt` | the input prompt text. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback streamingCallback` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback` for receiving streamed results. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` containing the final generated content. |

| Throws |
|---|---|
| `GenAiException` | if the inference fails. |

| See also |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest)` | (request: GenerateContentRequest, streamingCallback: StreamingCallback) |

### generateContent

```
abstract @NonNull GenerateContentResponse generateContent(
    @NonNull GenerateContentRequest request,
    @NonNull StreamingCallback streamingCallback
)
```

Performs streaming content generation inference on the provided input request.

Partial results are delivered incrementally through the provided `https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback`. The function suspends until all results are received and returns the complete, final `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse`. If streaming is interrupted by a GenAiException, consider removing any already streamed partial output from the UI.

The coroutine that runs `generateContent` is cancellable. If the inference is no longer needed (e.g., the user navigates away or input changes), the coroutine can be cancelled.

Note that inference requests may fail under certain conditions such as:

- Invalid or malformed input in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest`.

- Exceeded usage quota or failed safety checks.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` containing input content. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback streamingCallback` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/common/StreamingCallback` for receiving streamed results. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` | a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` containing the final generated content. |

| Throws |
|---|---|
| `GenAiException` | if the inference fails. |

### generateContentStream

```
default @NonNull Flow<@NonNull GenerateContentResponse> generateContentStream(@NonNull String prompt)
```

Performs streaming content generation inference on the provided input prompt.

This is a convenience method that wraps the input prompt in a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` with default generation parameters.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html prompt` | the input prompt text. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse>` | a `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` which will emit `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse`s as they are returned from the model. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if `request.candidateCount` is greater than 1. If you need to receive multiple candidates in the final result, please use the generateContent(prompt: String, streamingCallback: StreamingCallback) method instead. |

| See also |
|---|---|
| `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContentStream(com.google.mlkit.genai.prompt.GenerateContentRequest)` | (request: GenerateContentRequest) |

### generateContentStream

```
abstract @NonNull Flow<@NonNull GenerateContentResponse> generateContentStream(@NonNull GenerateContentRequest request)
```

Performs streaming content generation inference on the provided input request.

Partial results are delivered incrementally through the returned `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html`. Each `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse` contains a single `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Candidate`. The last emitted value contains a `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/Candidate` with a FinishReason that is a non-null FinishReason (e.g., FinishReason.STOP or FinishReason.MAX_TOKENS)

This streaming mode is useful to build a more responsive UI. Streaming can be interrupted by a GenAiException. In that case, consider removing any already streamed partial output from the UI.

The coroutine collecting the `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` is cancellable. If the inference is no longer needed (e.g., the user navigates away or input changes), the coroutine can be cancelled

Note that inference requests may fail under certain conditions such as:

- Invalid or malformed input in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest`.

- Exceeded usage quota or failed safety checks.

**Important:** This function currently only supports a `candidateCount` of 1 in the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest`. Providing a `candidateCount` greater than 1 will result in an `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html`. If you need to receive multiple candidates in the final result, please use the generateContent(request: GenerateContentRequest, streamingCallback: StreamingCallback) method instead.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest request` | a non-null `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest` containing the input content. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse>` | a `https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` which will emit `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentResponse`s as they are returned from the model. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-illegal-argument-exception/index.html` | if `request.candidateCount` is greater than 1. |

### getAvailableFeatures

```
abstract @NonNull List<@NonNull Integer> getAvailableFeatures()
```

Returns the list of features (capabilities) available for this model.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/Integer.html>` | the list of available features. |

### getBaseModelName

```
abstract @NonNull String getBaseModelName()
```

Returns the name of the base model used by this generator instance.

The model name may be used for logging, debugging, or feature gating purposes.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull.html https://developer.android.com/reference/java/lang/String.html` | a `https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-string/index.html` representing the base model name. |

### getCaches

```
abstract @NonNull Caches getCaches()
```

Provides explicit management of cached contexts.

This experimental property offers direct control over cached contexts to accelerate inference.

The `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel` supports two types of caching:

1. Implicit Caching: Automatically created when a promptPrefix is provided in `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContent(com.google.mlkit.genai.prompt.GenerateContentRequest)` or `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#generateContentStream(com.google.mlkit.genai.prompt.GenerateContentRequest)`. The system manages their lifecycle. These caches cannot be accessed directly but can be cleared using `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#clearImplicitCaches()`.

2. Explicit Caching: Managed via this `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#caches()` property. Users can explicitly create, retrieve, and manage the lifecycle of cache entries.

Use `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isCachingFeatureAvailable()` to check if the caching feature is available. Attempting to use the `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#caches()` property when the feature is not available will result in an exception.

### getTokenLimit

```
abstract int getTokenLimit()
```

Returns total token limit for the API including both input and output tokens.

This limit can be used with `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#countTokens(com.google.mlkit.genai.prompt.GenerateContentRequest)` to check if a request is within limits before running inference. The input size returned by `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#countTokens(com.google.mlkit.genai.prompt.GenerateContentRequest)` plusing the output size specified by `https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerateContentRequest#maxOutputTokens()` should be no larger than the limit returned by this method.

| Returns |
|---|---|
| `int` | token limit. |

### isCachingFeatureAvailable

```
abstract boolean [isCachingFeatureAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isCachingFeatureAvailable())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the caching feature is available.

| Returns |
|---|---|
| `boolean` | `true` if the caching feature is available, `false` otherwise. |

### isStructuredOutputFeatureAvailable

```
abstract boolean [isStructuredOutputFeatureAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isStructuredOutputFeatureAvailable())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the structured output feature is available.

This is an experimental feature.

| Returns |
|---|---|
| `boolean` | `true` if the structured output feature is available, `false` otherwise. |

### isSystemPromptAvailable

```
abstract boolean [isSystemPromptAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isSystemPromptAvailable())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the system prompt feature is supported on the device.

| Returns |
|---|---|
| `boolean` | `true` if the system prompt feature is available, `false` otherwise. |

### isThinkingModeAvailable

```
abstract boolean [isThinkingModeAvailable](https://developers.google.com/android/reference/com/google/mlkit/genai/prompt/GenerativeModel#isThinkingModeAvailable())()
```

> [!CAUTION]
> **This method is deprecated.**   
> Use getAvailableFeatures() instead.

Checks if the thinking mode feature is supported on the device.

| Returns |
|---|---|
| `boolean` | `true` if the thinking mode feature is available, `false` otherwise. |

### warmup

```
abstract void warmup()
```

Warms up the inference engine for use by loading necessary models and initializing runtime components.

While calling this method is optional, we recommend invoking it well before the first inference call to reduce the latency of the initial inference.

| Throws |
|---|---|
| `GenAiException` | if the preparation fails. |