v148 · AI · JavaScript
Prompt API
Direct access to Gemini Nano running on-device in Chrome. Text, image, and audio inputs; structured JSON output; no server round-trip, no API key, no network dependency for inference.
concepts
-
Prompt Playground
A chat-style interface that sends your prompts to Gemini Nano via
LanguageModel.create()and streams the response back. Falls back to a simulation when the model isn't available, with step-by-step setup instructions. -
Structured Output Studio
Force the model to respond in strict JSON using
responseConstraint: { type: "json_schema", ... }. Enter a piece of text and see it analyzed and returned as a structured object — sentiment, keywords, a summary — guaranteed valid JSON. -
Conversation History
Multi-turn chat backed by Chrome's on-device Gemini Nano via the Prompt API. Watch the context window fill as the conversation grows — when it nears the limit, the oldest turns are pruned and the session is recreated with trimmed history.
-
Function Calling Demo
Three clickable tool cards (get_weather, set_reminder, search_web) with JSON schemas. Enter a natural language query and watch a 5-step pipeline animate: system prompt engineering → model JSON tool call → parsed tool call → tool execution result → follow-up answer. Heuristic simulation fallback when
LanguageModelis unavailable. -
Writing Assistant
Five writing modes — continue, improve clarity, summarise, make formal, make casual — backed by
session.promptStreaming(). Suggestions stream token-by-token and can be accepted or dismissed. Falls back to a local template simulation when the Prompt API is not available. -
Local-First Workflow
Three concrete on-device app flows: a PII redaction assistant, a support-ticket triage and classifier, and a customer-reply form assistant with tone control. All inference runs locally with no server round-trip.
-
Quality Control Panel
Benchmark the Prompt API across six test cases — short completions, structured JSON output, summarisation, classification, creative writing, and long-context reasoning. Tune temperature and top-K and compare first-token latency vs. total response time.
-
Safety Harness
14-case edge-case test suite covering API availability, empty input, very long input, prompt injection attempts, structured output validation, session reuse, context overflow, abort/cancel, invalid parameters, and graceful fallback patterns.
why it shipped
Server-side AI inference requires an API key, a network request, latency, and ongoing per-token costs. For use cases that don't need the full power of cloud models — local spell-check, content summarization, form auto-fill, privacy-sensitive user data analysis — a local model is strictly better. Chrome ships with Gemini Nano, a small language model optimized for device execution. The Prompt API exposes it through a standardized JavaScript interface: check availability, create a session with optional system prompt and temperature, send prompts, stream responses. The API is designed to match the emerging W3C Web AI specification so that other browsers can implement the same interface.
references
implementation reference
Need the exact API surface, compatibility boundaries, errors, lifecycle, and source links? Read the matching gendn reference ↗