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.

Experimental: The Prompt API is stable for Chrome Extensions (Chrome 138+), while the version for web pages is still in development. An origin trial covering sampling parameters (temperature / topK) is running as of Chrome 148 — register your domain to use them without flags. Register Here

LanguageModel.availability()

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>;

Parameters (LanguageModelCreateCoreOptions)

NameTypeDescription
expectedInputssequence<LanguageModelExpected>Signals expected inputs to pre-download needed adapters (e.g. { type: "audio" } or { type: "text", languages: ["es"] }).
expectedOutputssequence<LanguageModelExpected>Signals expected output formats/languages. Currently only supports text.
toolssequence<LanguageModelTool>Array of tool definitions with name, description, inputSchema, and execute functions.
samplingModeLanguageModelSamplingModeHigh-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).
Interactive Playground

LanguageModel.create()

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>;

Parameters (LanguageModelCreateOptions)

Inherits all properties from LanguageModelCreateCoreOptions (above), plus:

NameTypeDescription
initialPromptssequence<LanguageModelMessage>Establishes system context or n-shot examples. The "system" role must be at the 0th index.
monitorCreateMonitorCallbackA function (m) => void where m emits downloadprogress events to track model weight download (e.loaded 0 to 1).
signalAbortSignalPass an AbortController.signal to cancel session creation and halt the model download.
Interactive Playground

session.prompt()

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>;

Input Parameter (LanguageModelPrompt)

The input can be a simple DOMString (zero-shot shorthand), or an array of LanguageModelMessage objects for complex/multimodal prompts:

[
  {
    role: "user" | "assistant",
    content: "String content" | [
      { type: "text", value: "Hello" },
      { type: "image", value: ImageBitmapSource | BufferSource },
      { type: "audio", value: Blob | AudioBuffer | BufferSource }
    ],
    prefix: boolean // (If true, pre-fills the assistant response. Valid only on final assistant message)
  }
]

Options Parameter

NameTypeDescription
responseConstraintobject | RegExpA JSON Schema object or RegExp to strictly constrain the model's output formatting.
omitResponseConstraintInputbooleanIf true, stops the browser from automatically injecting the schema definition into the prompt context, saving tokens.
signalAbortSignalPass an AbortController.signal to cancel this specific generation request.
Interactive Playground

session.promptStreaming()

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).

Interactive Playground

session.append()

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>;
Interactive Playground

session.measureContextUsage()

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>;

Related Context Attributes

  • 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.
Interactive Playground

session.clone()

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.

Interactive Playground

session.destroy()

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;
Interactive Playground

Deprecations & Aliases

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.

  • Hyperparameterstemperature 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.
  • LanguageModel.params() The static params() method used to query default topK/temperature is deprecated for web pages.
  • Renamed Aliases
    • inputUsage is now contextUsage
    • inputQuota is now contextWindow
    • measureInputUsage() is now measureContextUsage()
    • onquotaoverflow is now oncontextoverflow