The 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) is running as of Chrome 148 — register your domain to use them without flags. Register Here 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 variety: "most-predictable" | "predictable" | "balanced" | "creative" | "most-creative". Defaults to "balanced". This is the web-page replacement for the deprecated temperature/topK parameters (see Deprecations below). |
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. |
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, will be ignored in standard web contexts. Use the samplingMode create option instead to control output variety on web pages. In extension contexts, passing both samplingMode and a raw parameter rejects create() with a TypeError. 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