The Prompt API
4 hours ago
- #Browser AI
- #Prompt API
- #Gemini Nano
- The Prompt API enables developers to send natural language requests to Gemini Nano directly in the browser, offering potential use cases like AI-powered search, personalized news feeds, content filtering, and calendar or contact extraction.
- The Prompt API and other AI features (like Summarizer, Writer, Rewriter, Proofreader) have specific hardware and operating system requirements, including Windows 10/11, macOS 13+, Linux, or ChromeOS on Chromebook Plus, with at least 22 GB free storage, >4 GB VRAM or 16 GB RAM, and 4+ CPU cores for GPU/CPU usage.
- Developers can use Prompt API methods like `LanguageModel.availability()` to check model readiness, `create()` to start a session, and `prompt()` or `promptStreaming()` for request-based or streamed outputs, with support for multimodal inputs (audio, image) and JSON Schema for structured responses.
- Sessions in the Prompt API manage conversation context, have a token limit tracked via `session.contextUsage` and `session.contextWindow`, and can be cloned, terminated with `destroy()`, or handle overflow events when context limits are exceeded.
- The API supports cross-origin iframe access using Permission Policy with `allow="language-model"`, but is not available in Web Workers, and developers are encouraged to provide feedback via GitHub, bug reports, or the early preview program to influence future versions.