*Tech News • Jun 25, 2024* --- The new `window.ai` Chrome API, currently available in **Chrome Canary**, introduces native AI models that operate fully offline on your local device. ## Overview of the API The only model currently available for use is **Gemini Nano**. This API introduces six new functions: - **window.ai object** - **canCreateGenericSession** and **canCreateTextSession**: Check if your setup is ready for these features. If the result is `'readily'`, you're all set. - **createGenericSession** and **createTextSession**: These functions initiate sessions where the model can be utilized. - **defaultGenericSessionOptions** and **defaultTextSessionOptions**: Provide default options for the session functions. ## How do I get it? To try `window.ai`, you’ll need the latest Chrome Canary build with a few internal flags enabled. ### Enable the "Prompt API for Gemini Nano" flag Navigate to the Chrome flags page and enable this flag: **chrome://flags/#prompt-api-for-gemini-nano** ### Turn on the "Enable optimization guide on device" flag Enable this flag as well by heading to: **chrome://flags/#optimization-guide-on-device-model** Select **Enabled BypassPerfRequirement**. ### Install the Chrome component To finalize, navigate to **chrome://components** and install the *Optimization Guide On Device Model Chrome component* by clicking **Check for update**. This may take some time since it downloads the AI model to your device, allowing it to run offline. # Example Here’s an example of using `window.ai`: ```javascript const start = new Date().getTime(); const model = await window.ai.createTextSession(); const result = await model.prompt("What do you think is the meaning of life?"); const end = new Date().getTime(); console.log(result); console.log(`%cTook ${end - start}ms to generate.`, 'color: lime');