WebAI StudioThe Prompt API gives web pages the ability to directly prompt an instruction-tuned language model natively provided by the browser. It supports zero-shot and n-shot prompting, multimodal inputs, streaming responses, JSON schema constraints, and intelligent tool calling.
temperature / topK / LanguageModel.params()) are deprecated for web pages. Use the semantic samplingMode option (e.g. "most-predictable" for strict reproducibility and speculative decoding, or "balanced" by default) when creating a session. Read Explainer A static method that checks if the browser currently supports creating a language model session with the provided configuration. It returns a Promise resolving to an Availability string: 'available' | 'downloadable' | 'downloading' | 'unavailable'.
static availability(options?: LanguageModelCreateCoreOptions): Promise<Availability>;| Name | Type | Description |
|---|---|---|
| expectedInputs | sequence<LanguageModelExpected> | Signals expected inputs to pre-download needed adapters (e.g. { type: "audio" } or { type: "text", languages: ["es"] }). |
| expectedOutputs | sequence<LanguageModelExpected> | Signals expected output formats/languages. Currently only supports text. |
| tools | sequence<LanguageModelTool> | Array of tool definitions with name, description, inputSchema, and execute functions. |
| samplingMode | LanguageModelSamplingMode | High-level control over output predictability vs. creativity: "most-predictable" | "predictable" | "slightly-predictable" | "balanced" | "slightly-creative" | "creative" | "most-creative". Defaults to "balanced". Replaces the deprecated temperature and topK parameters. |
Creates and returns a new language model session. If the model is not yet available but is "downloadable", calling this method initiates the network download. If download fails, it throws a NetworkError.
static create(options?: LanguageModelCreateOptions): Promise<LanguageModel>;Inherits all properties from LanguageModelCreateCoreOptions (above), plus:
| Name | Type | Description |
|---|---|---|
| initialPrompts | sequence<LanguageModelMessage> | Establishes system context or n-shot examples. The "system" role must be at the 0th index. |
| monitor | CreateMonitorCallback | A function (m) => void where m emits downloadprogress events to track model weight download (e.loaded 0 to 1). |
| signal | AbortSignal | Pass an AbortController.signal to cancel session creation and halt the model download. |
Rather than exposing raw model-dependent parameters like topK and temperature, the API provides seven semantic presets and exposes the active mode on session.samplingMode:
| Mode | Use Case |
|---|---|
| "most-predictable" | Strict consistency, reproducibility, code generation, content extraction, and speculative decoding. |
| "predictable" | Focused outputs with minimal variation. |
| "slightly-predictable" | Focused outputs with a bit more variation than "predictable". |
| "balanced" | Default. Standard preset suitable for most conversational interactions. |
| "slightly-creative" | Creative outputs slightly more focused than "creative". |
| "creative" | Variety and creativity preferred over strict reproducibility. |
| "most-creative" | Maximum diversity of output and creative brainstorming. |
Executes inference and returns a single Promise resolving to the complete generated text. If the input exceeds the available context window, it evicts older conversation history one prompt/response pair at a time (the initialPrompts are never evicted), and throws a QuotaExceededError only when eviction cannot free enough space.
prompt(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise<DOMString>; The input can be a simple DOMString (zero-shot shorthand), or an array of LanguageModelMessage objects for complex/multimodal prompts:
| Name | Type | Description |
|---|---|---|
| responseConstraint | object | RegExp | A JSON Schema object or RegExp to strictly constrain the model's output formatting. |
| omitResponseConstraintInput | boolean | If true, stops the browser from automatically injecting the schema definition into the prompt context, saving tokens. |
| signal | AbortSignal | Pass an AbortController.signal to cancel this specific generation request. |
Identical parameters to prompt(), but returns a ReadableStream of string chunks as they are generated by the model.
promptStreaming(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): ReadableStream; Typically consumed with an async iterator (e.g., for await (const chunk of stream)), though getReader() works too. Highly recommended for improving perceived latency (TTFT).
Ingests and processes tokens into the context window ahead of time without triggering a response from the model. Extremely useful for "pre-warming" the session with large files or multimodal images before the user hits "Generate".
append(input: LanguageModelPrompt, options?: LanguageModelAppendOptions): Promise<undefined>;Measures how many tokens a given prompt will consume (implementations must include control tokens in the count). Returns a Promise. Note: This does not add the prompt to the session history.
measureContextUsage(input: LanguageModelPrompt, options?: LanguageModelPromptOptions): Promise<double>;readonly contextUsage: double - The current number of tokens stored in the session history.readonly contextWindow: double - The absolute maximum token limit for this model instance.oncontextoverflow - Event fired when a prompt causes the session history to overflow and evict older messages. Creates a new session starting from this session's initialPrompts and configuration. Whether conversation history appended after creation is carried over is implementation-defined — the explainer's canonical use is running multiple unrelated continuations of the same initial setup without re-processing it.
clone(options?: LanguageModelCloneOptions): Promise<LanguageModel>;Options takes an optional AbortSignal.
Immediately unloads the session from memory. Any pending prompt() or promptStreaming() calls on this session are rejected with an AbortError. If no other APIs are using the language model, Chrome can free the VRAM/RAM payload.
destroy(): undefined;To address inconsistencies across models, several parameters have been heavily restricted. The following features are deprecated in web pages and are now only functional within Chrome Extension contexts.
temperature and topK inside create() options, as well as accessing session.temperature and session.topK, are deprecated and ignored in standard web page contexts. Use the samplingMode option instead. If both samplingMode and raw parameters are provided, samplingMode takes precedence and the raw parameters are ignored. params() method used to query default topK/temperature is deprecated for web pages. inputUsage is now contextUsageinputQuota is now contextWindowmeasureInputUsage() is now measureContextUsage()onquotaoverflow is now oncontextoverflow