# Ml Kit Genai Prompt API

Analyzes Android codebases to implement ML Kit GenAI Prompt API.

- Repository: https://github.com/android/skills (10219 stars)
- Category: Data and ML
- License: Complete terms in LICENSE.txt
- Last updated: 2026-10-29
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add android/skills --skill ml-kit-genai-prompt-api -g -a claude-code -y`
Codex: `npx skills add android/skills --skill ml-kit-genai-prompt-api -g -a codex -y`
Cursor: `npx skills add android/skills --skill ml-kit-genai-prompt-api -g -a cursor -y`
Gemini CLI: `npx skills add android/skills --skill ml-kit-genai-prompt-api -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add android/skills`

## Description

Analyzes Android codebases to implement ML Kit GenAI Prompt API. Use this skill to send natural language requests on-device to Gemini Nano, use structured output with Prompt API, implement prefix caching, optimize the current prompt, or apply best practices.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

This skill provides step-by-step guidance for integrating and optimizing the ML
Kit GenAI Prompt API in Android apps.

## Prerequisites

- Android API level must be 26 or higher. If `minSdk` is below 26, update it to 26.
- Add the ML Kit GenAI Prompt API dependency (`com.google.mlkit:genai-prompt`) to the app-level `build.gradle` file, with version at least `1.0.0-beta4`.
- If `com.google.mlkit:genai-schema-compiler` dependency is used and KSP plugin version is below 2.3.6, update it to 2.3.6.

## Detailed steps

### 1. Prompt optimization

To optimize prompts for use with the ML Kit Prompt API, follow the
[prompt optimization guide](https://developer.android.com/agents/skills/device-ai/prompt-api/references/prompt-optimization).

### 2. Prefix caching optimization

If the prompt is more than 200 words, implement the [prefix caching API](https://developer.android.com/agents/skills/device-ai/prompt-api/references/prefix-caching).

### 3. Lifecycle and best practices

- The model must be fully downloaded and available before calling the first inference. Follow the guide on [implementing a generative model](https://developer.android.com/agents/skills/device-ai/prompt-api/references/get-started) to check that the `FeatureStatus` of a model is `AVAILABLE` before making an inference.
- Release ML Kit instances by calling `close()` when an `Activity`,
  `Fragment`, or `ViewModel` is destroyed. Example:


  ```kotlin
  // Instantiating model in activity, fragment, or ViewModel
      val generativeModel = Generation.getClient()

  // When activity, fragment, or ViewModel is destroyed
      generativeModel.close()
  ```

  <br />

### 4. Structured output

When implementing or refactoring a prompt to use structured output, follow
these rules:

The rest: https://github.com/android/skills/blob/HEAD/device-ai/ml-kit-genai-prompt-api/SKILL.md
