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.
To enable it: register your origin for the AIPromptAPIParams origin trial (desktop only: Windows, macOS, Linux, ChromeOS; third-party tokens allowed) and serve the token. For local testing, launch Chrome with --enable-blink-features=AIPromptAPIParams. Since Chrome 148 the API surface has already moved: the current spec deprecates these raw parameters in favour of samplingMode.
AIPromptAPIParams implies AIPromptAPILegacyParams); trial window 148–153 from the ChromeStatus API record.
at a glance
| Status in 148 | Origin trial |
|---|---|
| Flag | Origin trial token (AIPromptAPIParams); local testing: --enable-blink-features=AIPromptAPIParams |
| Standards position | Firefox: Negative · Safari: Oppose (parent Prompt API, per ChromeStatus 2026-11-15) |
| 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.
Formal syntax (Web IDL)
The sampling-parameter members as they appear in the current spec (excerpt, verbatim, including the spec's own deprecation comments). Chrome 148 exposes the same members with the same types, gated by AIPromptAPILegacyParams (implied by the AIPromptAPIParams origin trial).
[Exposed=Window, SecureContext]
interface LanguageModel : EventTarget {
static Promise<LanguageModel> create(optional LanguageModelCreateOptions options = {});
static Promise<Availability> availability(optional LanguageModelCreateCoreOptions options = {});
// **DEPRECATED**: This method will be removed; use samplingMode instead. Only available in extension contexts.
static Promise<LanguageModelParams?> params();
// (other LanguageModel members omitted from this excerpt)
// **DEPRECATED**: This attribute will be removed; use samplingMode instead. Only available in extension contexts.
readonly attribute unsigned long topK;
// **DEPRECATED**: This attribute will be removed; use samplingMode instead. Only available in extension contexts.
readonly attribute float temperature;
};
// **DEPRECATED**: This interface will be removed; use samplingMode instead. Only available in extension contexts.
[Exposed=Window, SecureContext]
interface LanguageModelParams {
readonly attribute unsigned long defaultTopK;
readonly attribute unsigned long maxTopK;
readonly attribute float defaultTemperature;
readonly attribute float maxTemperature;
};
dictionary LanguageModelCreateCoreOptions {
// Note: these two have custom out-of-range handling behavior, not in the IDL layer.
// They are unrestricted double so as to allow +Infinity without failing.
// **DEPRECATED**: This option will be removed; use samplingMode instead. Only available in extension contexts.
unrestricted double topK;
// **DEPRECATED**: This option will be removed; use samplingMode instead. Only available in extension contexts.
unrestricted double temperature;
};
Source: Prompt API spec IDL index (fetched 2026-11-15); Chrome 148 shape from M148 language_model.idl and M148 language_model_create_options.idl.
Session creation options
| LanguageModelCreateOptions.temperature | unrestricted double — Controls token distribution sharpness. 0.0 = fully deterministic (argmax); higher values increase randomness. Default and max are device-dependent. |
|---|---|
| LanguageModelCreateOptions.topK | unrestricted double — Restricts sampling to the top-K most probable tokens. 1 = greedy decoding. Device-dependent max. Fractional values are rounded down (WebIDL IntegerPart). |
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. |
|---|
unrestricted double per the IDL above (2026-11-15).
Errors and out-of-range values
temperaturebelow 0:create()returns a promise rejected with aRangeError.temperatureabovemaxTemperature: clamped tomaxTemperature(+Infinityis allowed, as a way of requesting the maximum).topKbelow 1:create()returns a promise rejected with aRangeError.topKabovemaxTopK(including+Infinityand numbers aboveNumber.MAX_SAFE_INTEGER): clamped tomaxTopK.params()fulfils withnullif the language model is not available at all in this browser.- In the current spec, web page contexts may still pass
topK/temperaturewithout an error (a deprecation warning is logged), but the values are ignored; if bothsamplingModeand a raw parameter are passed where raw parameters work,samplingModewins.
Successor: samplingMode (not in Chrome 148)
After Chrome 148 the spec replaced the raw parameters with seven semantic presets, and the ChromeStatus record for this feature is now titled “Prompt API Sampling Mode” with shipping proposed for Chrome 160. The Chrome 148 branch IDL has no samplingMode member, so it is not part of this release’s surface:
enum LanguageModelSamplingMode { "most-predictable", "predictable", "slightly-predictable", "balanced", "slightly-creative", "creative", "most-creative" };
// on LanguageModelCreateCoreOptions:
LanguageModelSamplingMode samplingMode;
// on LanguageModel:
readonly attribute LanguageModelSamplingMode? samplingMode;
Source: Prompt API spec IDL index; explainer §Configuration of sampling modes; ChromeStatus 6325545693478912.
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,
initialPrompts: [
{ role: "system", content: "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
initialPrompts: [
{ role: "system", content: "Extract structured data from text." }
]
});
const json = await session.prompt(
"Extract: 'Alice, 30, engineer, London'"
);
System prompts go in initialPrompts with role: "system"; Chrome 148’s LanguageModelCreateOptions has no systemPrompt member, so the earlier version of these examples passed an option that was silently ignored (corrected 2026-11-15).
initialPrompts); explainer §System prompts.
Live example
All concept demos for this feature are listed on the Chrome Platform Showcase feature page. The embedded sampling playground uses the raw temperature/topK options, so it needs the origin trial (or the local-testing switch above) and an on-device model.
browser support
Per-version data for the parent LanguageModel interface from BCD api/LanguageModel.json (raw JSON fetched 2026-11-15). BCD has no entries for the temperature/topK options and attributes or for params(), so the sampling-parameter column is interim data from ChromeStatus and the Chromium M148 branch, labelled as such.
| Browser | LanguageModel (BCD) | Sampling parameters (interim) |
|---|---|---|
| Chrome (desktop) | 148 | 148–153 origin trial AIPromptAPIParams (ChromeStatus); spec now deprecates them for web pages |
| Chrome Android | Not supported (version_added: false) | Not supported: the trial is desktop-only (origin_trial_os) |
| Edge | 138 behind flag #edge-llm-prompt-api-for-phi-mini | Unknown (no BCD or ChromeStatus data) |
| Firefox | Not supported (version_added: false) | Not supported; position: negative (#1213) |
| Safari | Not supported (version_added: false) | Not supported; position: oppose (#495) |