{"id":266,"date":"2026-11-19T22:01:57","date_gmt":"2026-11-20T03:01:57","guid":{"rendered":"https:\/\/blog.alangaelrojas.com\/?p=266"},"modified":"2026-11-19T22:01:58","modified_gmt":"2026-11-20T03:01:58","slug":"chrome-prompt-api-gemini-nano","status":"publish","type":"post","link":"https:\/\/blog.alangaelrojas.com\/index.php\/2026\/11\/19\/chrome-prompt-api-gemini-nano\/","title":{"rendered":"Chrome Prompt API + Gemini Nano"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">How I Added a Local AI Chat to My Website (No Backend Required)<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image-1024x576.png\" alt=\"\" class=\"wp-image-267\" srcset=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image-1024x576.png 1024w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image-300x169.png 300w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image-768x432.png 768w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image-1536x864.png 1536w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/image.png 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>A few weeks ago I wanted to add an AI assistant to my personal website, something that could answer questions about my experience, my projects and my talks. The obvious path was calling an LLM API, but that meant API keys, a backend, per-request costs and sending my visitors&#8217; questions to a third-party server. Then I found out about the\u00a0<strong>Chrome Prompt API<\/strong>, and everything changed.<\/p>\n\n\n\n<p>In this post I&#8217;ll explain what the Prompt API is, its key components, why running an LLM locally in the browser is such a big deal, and how I used it to ship a fully local, bilingual AI chat on my own site.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is the Chrome Prompt API?<\/h2>\n\n\n\n<p>The Prompt API is one of Chrome&#8217;s\u00a0<strong>built-in AI APIs<\/strong>. It exposes a small language model  &#8211; <strong>Gemini Nano<\/strong> &#8211; directly inside the browser through a global\u00a0<code>LanguageModel<\/code>\u00a0object. No SDK, no API key, no server: the model lives on the user&#8217;s device.<\/p>\n\n\n\n<p>A few important characteristics:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It is\u00a0<strong>experimental<\/strong>. Today it works on Chrome desktop, and for production sites it requires an\u00a0<strong>origin trial token<\/strong>\u00a0(a\u00a0<code>&lt;meta><\/code>\u00a0tag you add to your pages).<\/li>\n\n\n\n<li>The model is\u00a0<strong>downloaded on demand<\/strong>\u00a0by the browser, only after an explicit user action \u2014 your site can&#8217;t silently pull down several gigabytes.<\/li>\n\n\n\n<li>It is designed for\u00a0<strong>small, focused tasks<\/strong>: text generation, summarization, classification and short question answering.<\/li>\n<\/ul>\n\n\n\n<p>For a personal website, that&#8217;s more than enough.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Key components of the Prompt API<\/h2>\n\n\n\n<p>Getting into the matter, the API surface is surprisingly small. These are the pieces you actually use:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Feature detection and&nbsp;<code>availability()<\/code><\/h3>\n\n\n\n<p>First you check whether the browser even supports it and what state the model is in:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const state = await LanguageModel.availability({  expectedInputs: &#91;{ type: 'text', languages: &#91;'en', 'es'] }],  expectedOutputs: &#91;{ type: 'text', languages: &#91;'en', 'es'] }],});\/\/ 'unavailable' | 'downloadable' | 'downloading' | 'available'<\/code><\/pre>\n\n\n\n<p>This single call drives your entire UX. In my case:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>available<\/code>\u00a0\u2192 the full streaming chat is enabled.<\/li>\n\n\n\n<li><code>downloadable<\/code>\u00a0\/\u00a0<code>downloading<\/code>\u00a0\u2192 I show a &#8220;Activate local AI&#8221; button that only starts the download after an explicit click.<\/li>\n\n\n\n<li><code>unavailable<\/code>\u00a0\/ unsupported \u2192 a &#8220;basic mode&#8221; fallback (more on this below).<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. Creating a session with&nbsp;<code>LanguageModel.create()<\/code><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const session = await LanguageModel.create({  initialPrompts: &#91;{ role: 'system', content: 'You are Alan\\'s assistant\u2026' }],  monitor(m) {    m.addEventListener('downloadprogress', (e) =&gt; updateProgress(e.loaded));  },});<\/code><\/pre>\n\n\n\n<p>Two details worth highlighting:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>initialPrompts<\/code>\u00a0is where your\u00a0<strong>system prompt<\/strong>\u00a0goes \u2014 the model&#8217;s grounding for the whole conversation.<\/li>\n\n\n\n<li>The\u00a0<code>monitor<\/code>\u00a0callback lets you render\u00a0<strong>download progress<\/strong>, which is essential since the model is several GB.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. Prompting:&nbsp;<code>prompt()<\/code>&nbsp;vs&nbsp;<code>promptStreaming()<\/code><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>prompt(input)<\/code>\u00a0resolves with the complete answer.<\/li>\n\n\n\n<li><code>promptStreaming(input)<\/code>\u00a0returns a\u00a0<code>ReadableStream<\/code>\u00a0so you can render the answer token by token \u2014 much better perceived performance for a chat UI.<\/li>\n<\/ul>\n\n\n\n<p>One gotcha I hit: some builds emit&nbsp;<strong>cumulative<\/strong>&nbsp;chunks instead of deltas, so I merge with a small helper instead of always appending.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. Session lifecycle:&nbsp;<code>clone()<\/code>,&nbsp;<code>destroy()<\/code>&nbsp;and quotas<\/h3>\n\n\n\n<p>Sessions have a context window (<code>inputUsage<\/code>&nbsp;\/&nbsp;<code>inputQuota<\/code>, plus a&nbsp;<code>contextoverflow<\/code>&nbsp;event). The pattern I use: keep a&nbsp;<strong>base session<\/strong>&nbsp;with the system prompt,&nbsp;<code>clone()<\/code>&nbsp;it for each conversation, and&nbsp;<code>destroy()<\/code>&nbsp;clones on reset \u2014 a &#8220;new conversation&#8221; costs almost nothing.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why run a local LLM in the browser?<\/h2>\n\n\n\n<p>The advantages that convinced me:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Privacy by design.<\/strong>\u00a0Questions never leave the device. For a personal site, I don&#8217;t want to handle (or pay for) anyone&#8217;s data.<\/li>\n\n\n\n<li><strong>Zero marginal cost.<\/strong>\u00a0No API bill, no rate limits on my side, no infra to maintain. My site stays a purely static site.<\/li>\n\n\n\n<li><strong>Works offline<\/strong>\u00a0once the model is downloaded.<\/li>\n\n\n\n<li><strong>No backend.<\/strong>\u00a0Everything is client-side TypeScript bundled by Vite \u2014 the site is still plain HTML\/JS\/CSS served from cheap hosting.<\/li>\n<\/ul>\n\n\n\n<p>Being honest about the trade-offs:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>It only works on\u00a0<strong>Chrome desktop<\/strong>\u00a0today \u2014 mobile, Safari and Firefox need a fallback.<\/li>\n\n\n\n<li>Gemini Nano is\u00a0<strong>small<\/strong>: you can&#8217;t expect GPT-level reasoning. You have to design around it.<\/li>\n\n\n\n<li>It&#8217;s experimental, so APIs may still evolve.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Success case: a bilingual AI chat on alangaelrojas.com<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"716\" height=\"222\" src=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205355.png\" alt=\"\" class=\"wp-image-268\" srcset=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205355.png 716w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205355-300x93.png 300w\" sizes=\"auto, (max-width: 716px) 100vw, 716px\" \/><\/figure>\n\n\n\n<p>Now the part I&#8217;m most proud of \u2014 how this works on my actual website. The key insight:&nbsp;<strong>I don&#8217;t train or fine-tune anything. I use retrieval.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Retrieval instead of training<\/h3>\n\n\n\n<p>Nano is small, so I ground every answer with context:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>A local\u00a0<strong>knowledge base<\/strong>\u00a0written in plain Markdown (<code>src\/knowledge\/{es,en}\/*.md<\/code>) \u2014 one\u00a0<code>##<\/code>\u00a0block per topic, plus chunks auto-generated from my typed content data (experience, projects, certifications, teaching).<\/li>\n\n\n\n<li>A\u00a0<strong>BM25 retriever<\/strong>\u00a0(~150 lines) ranks chunks per question \u2014 accent-normalized, with Spanish\/English stopwords, stemming and title\/tag boosting.<\/li>\n\n\n\n<li>The\u00a0<strong>system prompt<\/strong>\u00a0injects computed facts (total years of experience, years per technology, current role) so answers about dates are always exact.<\/li>\n\n\n\n<li>The top ~4 chunks are injected into the user prompt inside a character budget \u2014 small models do worse with long context, so this matters a lot.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">States and graceful degradation<\/h3>\n\n\n\n<p>The whole experience is state-driven from&nbsp;<code>availability()<\/code>: full AI chat when possible, an explicit &#8220;Activate local AI&#8221; download button when the model isn&#8217;t downloaded yet, and a&nbsp;<strong>basic mode<\/strong>&nbsp;everywhere else \u2014 the same retriever answers with the most relevant chunks plus a contact CTA. Nobody gets a broken experience.<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"454\" class=\"wp-image-269\" style=\"width: 300px;\" src=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205432.png\" alt=\"prompt api chat thinking\" srcset=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205432.png 449w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205432-198x300.png 198w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/td><td class=\"has-text-align-center\" data-align=\"center\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"457\" class=\"wp-image-270\" style=\"width: 300px;\" src=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205451.png\" alt=\"prompt api chat response\" srcset=\"https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205451.png 431w, https:\/\/blog.alangaelrojas.com\/wp-content\/uploads\/2026\/11\/Captura-de-pantalla-2026-11-19-205451-197x300.png 197w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">The UX<\/h3>\n\n\n\n<p>A prompt box in the hero opens a floating chat drawer. When the API is usable, the header CTA even changes from &#8220;Let&#8217;s talk&#8221; to &#8220;Ask my AI&#8221;. Model output is escaped and rendered through a tiny safe-markdown renderer \u2014 never raw&nbsp;<code>innerHTML<\/code>.<\/p>\n\n\n\n<p>The result: visitors can ask &#8220;how many years of Kotlin experience does he have?&#8221; or &#8220;has he led teams?&#8221; and get a grounded, streamed answer \u2014 computed&nbsp;<strong>entirely on their machine<\/strong>, in both Spanish and English.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Things I learned building this<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Retrieval quality > model quality.<\/strong>\u00a0Most wrong answers came from bad chunks, not bad generation. Investing in BM25 tuning paid off more than prompt tweaks.<\/li>\n\n\n\n<li><strong>Design for the fallback first.<\/strong>\u00a0Most visitors won&#8217;t have the model \u2014 &#8220;basic mode&#8221; is the experience for the majority.<\/li>\n\n\n\n<li><strong>Chunk the streaming defensively.<\/strong>\u00a0Handle cumulative chunks and aborted reads from day one.<\/li>\n\n\n\n<li><strong>Small model, small context.<\/strong>\u00a0A tight prompt budget beats a verbose prompt.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Final thoughts<\/h2>\n\n\n\n<p>The Prompt API is still experimental, but it already enables something that felt impossible a year ago: a privacy-friendly AI feature on a static site with zero backend and zero cost. If you have a personal site or a small product where a &#8220;lite&#8221; assistant adds value, it&#8217;s absolutely worth a weekend of exploration.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Useful links<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Chrome built-in AI \/ Prompt API docs:\u00a0<a href=\"https:\/\/developer.chrome.com\/docs\/ai\/prompt-api\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.chrome.com\/docs\/ai\/prompt-api<\/a><\/li>\n\n\n\n<li>Try the chat live:\u00a0<a href=\"https:\/\/alangaelrojas.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/alangaelrojas.com<\/a><\/li>\n\n\n\n<li>The full implementation (open source):\u00a0<a href=\"https:\/\/github.com\/alangaelrojas\/alangaelrojas.com\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/github.com\/alangaelrojas\/alangaelrojas.com<\/a><\/li>\n\n\n\n<li>Enable it locally:\u00a0<code>chrome:\/\/flags\/#prompt-api-for-gemini-nano<\/code>\u00a0and\u00a0<code>#optimization-guide-on-device-model<\/code><\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How I Added a Local AI Chat to My Website (No Backend Required)<\/p>\n","protected":false},"author":1,"featured_media":267,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-266","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/posts\/266","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/comments?post=266"}],"version-history":[{"count":1,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":271,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/posts\/266\/revisions\/271"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/media\/267"}],"wp:attachment":[{"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/media?parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/categories?post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alangaelrojas.com\/index.php\/wp-json\/wp\/v2\/tags?post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}