Skip to content

ML Kit GenAI Prompt API

Guides Android developers integrating on-device Gemini Nano prompts, structured output, and prefix caching

Repository
android/skills
Stars
10,278
Licence
Apache-2.0
Files
7 files

What it does

When installed, the agent can analyze an Android codebase and help add on-device AI features using Google's ML Kit GenAI Prompt API, which sends natural language requests to Gemini Nano running on the phone. It walks through setup (minimum Android API 26, dependency versions), checks that the model is available before use, releases resources properly, and refactors free-text prompt code to return typed structured data. It also advises on prompt optimization and prefix caching for long prompts.

Great for

  • Android developers adding on-device generative AI features to an app
  • Teams refactoring existing Gemini Nano prompt code to use structured output
  • Developers who want guidance on caching and optimizing long prompts

Skip it if

  • Non-Android projects, since the guidance is specific to ML Kit on Android (wrong platform for web or iOS work)
  • Apps needing cloud-hosted large models or features on devices that cannot run Gemini Nano (the skill assumes on-device availability and gives no fallback)

Try asking

  • “Add ML Kit GenAI Prompt API to my Android app and set up the Gradle dependencies”
  • “Refactor my parseEmail function to return a structured @Generable object instead of a String”
  • “Check whether my prompt is over 200 words and add prefix caching if it is”
  • “Review my ViewModel to make sure I release the generative model with close()”
Step-by-step guide: how to use ML Kit GenAI Prompt APIInstall, first run, examples, tips and FAQs

Install in 3 steps

  1. 1

    Download the skill

    The ZIP contains the 7 original files, the Apache-2.0 licence and an attribution note.

    ml-kit-genai-prompt-api.zip
  2. 2

    Add it to your agent

    Claude Code (all projects)

    mkdir -p ~/.claude/skills && unzip ml-kit-genai-prompt-api.zip -d ~/.claude/skills/

    Claude Code / Agent SDK (this project only)

    mkdir -p .claude/skills && unzip ml-kit-genai-prompt-api.zip -d .claude/skills/

    Claude apps (web/desktop): Settings → Capabilities → Skills → Upload skill, and choose the ZIP.

  3. 3

    Ask for the task

    No special command needed — the agent reads the skill's description and loads it when your request matches. Try one of the prompts above.

Get better results

  • Point the agent at your app's module so it can find your minSdk, build.gradle and existing prompt functions before editing
  • Ask for structured output only when you need typed fields; check the FeatureStatus and isStructuredOutputFeatureAvailable() guards in your code
  • Review the dependency and minSdk changes the agent proposes, since they affect your whole app build

What's inside

  • references/get-started.md
  • references/prefix-caching.md
  • references/prompt-design.md
  • references/prompt-optimization.md
  • references/structured-output.md
  • references/system-instructions.md
  • SKILL.md

Redistributed unmodified from android/skills under the Apache-2.0 licence. The assessment was drafted with AI from the skill's files on 2026-10-29. Skills can instruct your agent to run code — read SKILL.md and any scripts before installing.