v137 · miscellaneous
Prompt API
Prompt API gives web developers direct access to a browser-provided on-device AI language model. The API design offers fine-grained control, aligned with cloud API shapes, for progressively enhancing sites with model interactions tailored to individualized use cases. This complements task-based language model APIs, for example, Summarizer API, as well as a v
concepts
-
Prompt
On-device general-purpose Prompt API. The foundation model that the other on-device AI APIs ride on top of.
-
Structured Output
Constrain the model to a JSON schema with
responseConstraint— no parse-retry loops. Three task presets (review, event, contact) with validation side-by-side against unconstrained output. -
Streaming meter
Pick a prompt and watch the model stream tokens. Live meters track first-token latency, tokens/sec, and inter-token gaps; sparkline shows the gap distribution. Falls back to a synthetic stream so the metering still works in unsupported browsers.
-
Multi-turn chat & quota
A real
LanguageModelsession with system prompt, persisting turns,session.clone()branching, and a live quota panel readingtokensSoFar/tokensLeft/maxTokens.
why it shipped
Direct access to a language model can help web developers accomplish tasks beyond those with dedicated APIs (e.g. Summarizer API) , and tailor their usage for site-specific requirements. Compared to the low-level APIs approach (e.g a custom AI model run via WebGPU, WASM, or WebNN), using the built-in language model can save the user's bandwidth and disk space, and has a lower barrier to entry. The design offers simple shorthands for common patterns (e.g. await session.prompt(‘write a haiku’)), and supports more complex use cases for handling structured content sequences, streaming responses, a