The Prompt API
About this codelab
Last updated Feb 18, 2025
Written by Paul Li
1. Overview
In this codelab, you'll learn how to use built-in AI - the Prompt API to vivid web applications. Your involvement is invaluable as we explore opportunities to improve or augment web experiences with AI!

What you'll learn
- Opt-in built-in AI feature > the Prompt API with browser Chrome.
- The basic usage of the Prompt API.
- Available resources to build application quickly.
What you'll need
- Install browser Chrome.
- Opt-in built-in AI feature.
- Use you familiar editor to code JavaScript.
2. Install Chrome
Built-in AI is available for browser Chrome only. We need to install Chrome before experience AI features. Check the follow Chrome download links if current device doesn't have Chrome.

Besides the stable version, you can also choose Chrome Canary to experience the newest features and fastest update cycle.

Here comes the download links
3. Check requirements
Here comes some requirementst before we opt-in built-in AI features.
A. Acknowledge Google’s Generative AI Prohibited Uses Policy.
B. Check the following table and make sure your hardware is OK.

C. Chrome version is is equal or newer than 128.0.6545.0
.
4. Opt-in built-in AI
Let's opt-in built-in AI.
-
Turn on Chrome and copy the following code into chrome omnibox then press Return.
chrome://flags/#optimization-guide-on-device-model Then select Enabled BypassPerfRequirement. This action is just make sure LLM download won't be block by app.
Chrome flags > chrome://flags/#optimization-guide-on-device-model -
Copy the following code into chrome omnibox then press Return.
chrome://flags/#prompt-api-for-gemini-nano Then select Enabled. This action is make sure we would like to experience built-in AI > prompt API.
Chrome flags > prompt-api-for-gemini-nano -
Relaunch Chrome to let the flags we just turned on active.
-
Turn on Chrome DevTool and switch to tab Console (⌘ + ⌥ + i).
-
Copy the following code into tab Console then press Return.
(await ai.languageModel.capabilities()).available; This action will check built-in AI available or not. Everything will be all set once it returned
readily
and you can skip the following steps.DevTool Console > check built-in AI available or not -
Stay tab Console then copy and execute it. This action will force browser download Gemini nano.
await ai.languageModel.create(); The result will likely fail but it’s intended.
-
Copy the following code into chrome omnibox then press Return
chrome://components Find out Optimization Guide On Device Model section. Make sure version is greater or equal to 2024.5.21.1031. If there is no version listed, click on Check for update to force the download.
Chrome components -
Once the model has downloaded and has reached a version greater than shown above. Back to Step.5 to check available or not. If this still fails, please see the troubleshooting.
5. Code with the Prompt API
It's time to experience built-in AI > the Prompt API. Check the following steps and feel its amazing power.
At once version
It's possible to modify systemPrompt
、temperature
and topK
. All we need to do is just adding these parameters with create().
Streaming version
Tracking model download progress
Session persistence
Terminating a session
Session cloning
To preserve resources, you can clone an existing session. The conversation context will be reset, but the initial prompt or the system prompts will remain intact.
6. Congratulations!
You've experienced built-in AI > the Prompt API.
What you've covered
- Opt-in built-in AI.
- the Prompt API > prompt() & promptStreaming() methods.
Next steps
Learn more
7. Optional: Prompt API in Extensions
Join the Prompt API origin trial, running in Chrome 131 to 136, to create Extensions with this API. While there may be usage limits, you can integrate these features for live testing and gathering user feedback. The goal is to inform future iterations of this API, as we work towards wider availability.
Participate in the origin trial
To sign up your extension for the origin trial, use the URL chrome-extension://YOUR_EXTENSION_ID as the Web Origin. For example, chrome-extension://ljjhjaakmncibonnjpaoglbhcjeolhkk
.

After you've signed up for the original trial, you receive a generated token, which you need to pass in an array as the value of the trial_tokens field in the manifest.
Use the Prompt API
Once you have requested permission to use the Prompt API, you can build your extension. There are two new extension functions available to you in the chrome.aiOriginTrial.languageModel
namespace: