← Chrome 148 reference

v148 · web api · experimental

Prompt API

A browser-provided interface to an on-device large language model (Gemini Nano in Chrome). Pages call LanguageModel.create() to get a session, then send text, images, or audio via session.prompt() — no API key, no network round-trip, inference runs locally.

Chrome-specific / experimental The Prompt API is a Chrome-only origin trial feature currently proposed to W3C Web Machine Learning CG. The interface is subject to change. The model is available only where Gemini Nano is installed; always check LanguageModel.availability() before calling create(). This page is generated from the webmachinelearning/prompt-api explainer.

at a glance

Shipped inChrome 148 (desktop)
StatusOrigin trial / Enabled by default (requires Gemini Nano download)
Flagchrome://flags/#optimization-guide-on-device-model (must be set to Enabled)
Standards positionProposed at W3C Web Machine Learning CG
Spec / Explainerwebmachinelearning/prompt-api
ChromeStatus5134603979063296 — Prompt API

why it exists

Cloud AI APIs require a network connection, a billing account, and introduce latency and privacy concerns for sensitive content. Devices running Chrome already download a small on-device LLM (Gemini Nano) for browser-level features. The Prompt API exposes that same model to web pages through a sandboxed JS interface, letting developers add language model capabilities without external dependencies, API keys, or sending user data off-device.

Source: webmachinelearning/prompt-api README §Background, May 2026.

shape of the API

All interactions flow through a session object. The static LanguageModel namespace creates and introspects sessions; each session maintains a rolling conversation context and token budget.

LanguageModel static methods

MethodReturnsDescription
LanguageModel.availability(opts?) Promise<"unavailable" | "downloadable" | "downloading" | "available"> Check whether the model is ready before attempting creation. "available" = ready to use; "downloadable" = supported but not yet downloaded.
LanguageModel.create(opts?) Promise<LanguageModelSession> Create a session. Options: initialPrompts, expectedInputs, expectedOutputs, tools, temperature, topK, signal, monitor.
LanguageModel.params() Promise<{defaultTemperature, maxTemperature, defaultTopK, maxTopK}> Retrieve the model's default and maximum sampling parameter values.

LanguageModelSession instance members

MemberTypeDescription
prompt(input, opts?)Promise<string>Send a message, get a complete response. input can be a string or array of multimodal parts.
promptStreaming(input, opts?)ReadableStream<string>Stream the response token by token as an async iterable.
append(messages, opts?)Promise<void>Add messages to the context without generating a reply — useful for seeding few-shot examples.
measureContextUsage(input, opts?)Promise<number>Count the tokens a hypothetical prompt would consume, without actually prompting.
clone(opts?)Promise<LanguageModelSession>Create a copy of the current session (including conversation history).
destroy()voidRelease the session's resources.
contextUsagenumberTokens consumed so far by this session.
contextWindownumberTotal token budget for the session.
Source: webmachinelearning/prompt-api README, May 2026.

recipes

Check availability and create a session

const avail = await LanguageModel.availability();
if (avail === 'unavailable') {
  console.warn('Prompt API not supported on this device');
} else {
  // 'downloadable' → browser will fetch the model on create()
  const session = await LanguageModel.create({
    initialPrompts: [
      { role: 'system', content: 'You are a concise technical writer.' }
    ]
  });
  const answer = await session.prompt('Explain CSS cascade in one sentence.');
  console.log(answer);
  session.destroy();
}

Streaming response

const session = await LanguageModel.create();
const stream = session.promptStreaming('Write a haiku about the browser cache.');
let text = '';
for await (const chunk of stream) {
  text += chunk;
  outputEl.textContent = text;
}
session.destroy();

Structured output (JSON schema constraint)

const session = await LanguageModel.create();
const schema = {
  type: 'object',
  properties: {
    sentiment: { type: 'string', enum: ['positive', 'neutral', 'negative'] },
    score: { type: 'number', minimum: 0, maximum: 1 }
  },
  required: ['sentiment', 'score']
};
const raw = await session.prompt(
  'Analyse: "The docs were clear and the API is elegant."',
  { responseConstraint: schema }
);
const { sentiment, score } = JSON.parse(raw);
session.destroy();

Multimodal input (image)

const session = await LanguageModel.create({
  expectedInputs: [{ type: 'image' }]
});
const blob = await fetch('/screenshot.png').then(r => r.blob());
const result = await session.prompt([
  { type: 'text', value: 'Describe what is wrong in this UI screenshot.' },
  { type: 'image', value: blob }
]);
session.destroy();
Source: webmachinelearning/prompt-api README examples, May 2026.

browser support

BrowserSupport
Chrome 148+ (desktop)Enabled by default where Gemini Nano is installed
EdgeSeparate Phi-based implementation under consideration
FirefoxNo position
SafariNo position
Source: chromestatus.com and webmachinelearning/prompt-api §Status, May 2026.

see also