# Prompt API A W3C proposal enabling web developers to access browser-provided or OS-provided language models directly via a JavaScript API. Supports prompt-completion workflows with stateful sessions, streaming, structured outputs, and multimodal inputs — all running on-device with no cloud dependency. Spec repo: https://github.com/webmachinelearning/prompt-api Part of the [[WebMachineLearning]] ecosystem. ## Status Experimental in Chrome and Microsoft Edge (2026). Under active W3C development. ## Core Capabilities | Feature | Description | |---|---| | Session management | Stateful conversations across multiple prompts | | Streaming | `promptStreaming()` for real-time token output | | System prompts | Configurable system context per session | | Multimodal inputs | Text, images, and audio | | Structured outputs | JSON Schema or regex constraints on model output | | Tool calling | Invoke JavaScript functions from model decisions | | Token tracking | Monitor context usage and handle overflow | | Abort signal | Cancel in-flight requests | | Availability check | Detect whether a model is available before using | | Download progress | Monitor model download state | ## Key Design Principles - **Local-first**: model inference happens on device; no data transmitted to external servers - **Privacy by default**: prompts and responses never leave the machine - **Standardized contract**: one API across browsers (once standardized) - **Model abstraction**: developers don't manage model weights directly ## Usage Pattern ```js const session = await ai.languageModel.create({ systemPrompt: "You are a helpful assistant." }); const stream = session.promptStreaming("Summarize this text: ..."); for await (const chunk of stream) { console.log(chunk); } ``` ## Relationship to Sibling APIs - **[[WebNN API]]**: lower-level neural network ops; Prompt API builds on top - **[[Writing Assistance APIs]]**: higher-level task-specific wrappers (Summarizer, Writer, Rewriter) ## References - https://github.com/webmachinelearning/prompt-api - https://github.com/webmachinelearning ## Related - [[WebMachineLearning]] - [[Large Language Models (LLMs)]] - [[AI Inference]] - [[AI Privacy]] - [[WebNN API]] - [[Writing Assistance APIs]] - [[Browser-Provided Language Models]] - [[On-Device Machine Learning]] - [[Gemini Nano]] - [[LLM Tool Calling]] - [[LLM Structured Outputs]] - [[LLM Streaming]] - [[Edge AI]]