v148 · web ai · origin trial
Prompt API Sampling Parameters
Adds temperature and topK sampling parameters to the built-in Prompt API's LanguageModel interface, giving developers direct control over the randomness and diversity of on-device model outputs. Also exposes static helpers to query the browser's supported ranges for these parameters.
at a glance
| Status in 148 | Origin trial |
|---|---|
| Flag | None (requires OT token) |
| Standards position | Firefox: No signal · Safari: No signal |
| Spec | webmachinelearning.github.io/prompt-api (W3C WICG) |
| Blink component | Blink>AI>Prompt |
| ChromeStatus | 6325545693478912 — Prompt API Sampling Parameters |
why it exists
The built-in Prompt API relies on an on-device language model managed by the browser. Without sampling controls, every prompt runs with the browser's fixed defaults, which can produce deterministic but low-creativity outputs. By exposing temperature (how "random" the distribution is) and topK (how many candidate tokens are considered at each step), developers can tune the trade-off between coherence and variety — useful for creative writing, brainstorming, or testing model robustness.
shape of the API
The Prompt API sampling parameters extend session options and language model instances with temperature and topK controls, alongside the LanguageModel.params() capability inspector.
Session creation options
| LanguageModelCreateOptions.temperature | float — Controls token distribution sharpness. 0.0 = fully deterministic (argmax); higher values increase randomness. Default and max are device-dependent. |
|---|---|
| LanguageModelCreateOptions.topK | unsigned long — Restricts sampling to the top-K most probable tokens. 1 = greedy decoding. Device-dependent max. |
Instance attributes (read-back)
| LanguageModel.temperature | The effective temperature for this session (the value set at creation, or browser default). |
|---|---|
| LanguageModel.topK | The effective topK for this session. |
Static capability query
| LanguageModel.params() | Returns a Promise<LanguageModelParams> describing the browser's defaultTemperature, maxTemperature, defaultTopK, and maxTopK. |
|---|
example
Query device limits and configure sampling parameters with LanguageModel.create():
// 1. Check what the device supports
const params = await LanguageModel.params();
console.log(params.defaultTemperature, params.maxTemperature);
// e.g. 1.0, 2.0
// 2. Create a higher-temperature session for brainstorming
const session = await LanguageModel.create({
temperature: Math.min(1.8, params.maxTemperature),
topK: 40,
systemPrompt: "You are a creative writing assistant."
});
// 3. Verify the applied values
console.log(session.temperature, session.topK); // 1.8, 40
// 4. Prompt
const result = await session.prompt("Give me five unusual fantasy city names.");
console.log(result);
Conservative/deterministic session
const session = await LanguageModel.create({
temperature: 0.2,
topK: 1, // greedy decoding — most deterministic
systemPrompt: "Extract structured data from text."
});
const json = await session.prompt(
"Extract: 'Alice, 30, engineer, London'"
);
browser support
| Chrome | Origin trial in 148 |
|---|---|
| Edge | Tracking Chromium |
| Firefox | No signal |
| Safari | No signal |