ml-kit-genai-prompt-api

Integrates ML Kit GenAI Prompt API for on-device Gemini Nano inference in Android apps.

2|Updated Jun 21, 2026
One-click install
npx skills add https://github.com/IsKenKenYa/skills --skill ml-kit-genai-prompt-api-iskenkenya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ml-kit-genai-prompt-api
Source: https://github.com/IsKenKenYa/skills/tree/main/skills/android/device-ai/ml-kit-genai-prompt-api
Command: npx skills add https://github.com/IsKenKenYa/skills --skill ml-kit-genai-prompt-api-iskenkenya

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Integrating on-device generative AI into Android apps involves tricky setup details—SDK levels, dependency versions, model availability checks, lifecycle cleanup, and structured output refactoring—that are easy to get wrong without guided steps. ## Core Features & Use Cases - Prompt API Integration: Add the ML Kit GenAI Prompt API dependency and send natural language requests to Gemini Nano on-device. - Structured Output: Refactor string-returning prompts into typed @Generable data classes using the Structured Output API. - Prefix Caching & Optimization: Apply prefix caching for prompts over 200 words and follow prompt optimization best practices. - Use Case: You want to parse emails on-device into sender, title, and summary fields. This Skill guides you to check model availability, refactor your function to return a typed ParsedEmail object, and release the model with close() when the ViewModel is destroyed. ## Quick Start Use the ml-kit-genai-prompt-api skill to add on-device Gemini Nano prompting with structured output to my Android app.

Frequently Asked Questions about ml-kit-genai-prompt-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I integrate the ML Kit GenAI Prompt API in an Android app?

Add the com.google.mlkit:genai-prompt dependency (version 1.0.0-beta4 or later) to your app-level build.gradle and ensure minSdk is at least 26. Then create a model with Generation.getClient() and verify its FeatureStatus is AVAILABLE before inference.

How do I use structured output with the ML Kit Prompt API?

Define a data class annotated with @Generable and @Guide field descriptions, then build a typed request with generateTypedContentRequest. Refactor functions to return the typed object instead of a String, and check availability with isStructuredOutputFeatureAvailable() first.

What Android version does ML Kit GenAI Prompt API require?

The API requires Android API level 26 or higher, so minSdk must be updated to 26 if it is lower. If you use the genai-schema-compiler dependency, the KSP plugin must be version 2.3.6 or above.

When should I use prefix caching with Gemini Nano prompts?

Use the prefix caching API when your prompt exceeds 200 words. Caching the shared prefix reduces redundant processing across repeated inference calls that share the same prompt beginning.

Why does my ML Kit Prompt API inference fail on first call?

Inference fails if the model is not fully downloaded and available on the device. Check that the model's FeatureStatus is AVAILABLE before the first generateContent call, and release instances with close() when the Activity, Fragment, or ViewModel is destroyed.