# Welcome

Power up your web apps with local AI.

Meet AiBrow, which enables on-device AI in your browser. Private, Fast and Free. It's Open Source and supports Llama, Gemini, Phi and many other models.

The AiBrow API follows the current proposals for the browser machine learning APIs, namely the

* [Prompt API](https://github.com/explainers-by-googlers/prompt-api?tab=readme-ov-file#stakeholder-feedback)
* [Writing assistance API](https://github.com/webmachinelearning/writing-assistance-apis)&#x20;
* [Translation API](https://github.com/webmachinelearning/translation-api)

These are currently being developed & trialled in [Google Chrome](https://developer.chrome.com/docs/ai/built-in), but AiBrow extends this base feature set with new capabilities. This means you can use AI in the browser using a number of different implementations...

1. Using the in-browser APIs when available
2. Using the [AiBrow extension](/aibrow-extension/getting-started), which uses native llama.cpp
3. Using web APIs such as WebGPU and WASM

Each method has its own advantages and limitations as well as performance considerations to take into account ([Feature comparison](/aibrow-web-api/feature-comparison)). You can use the [AiBrow Web API](/aibrow-web-api/getting-started) to check on-device support and access each of these APIs as needed.

### Quick Start

Install the dependencies:

```bash
npm install @aibrow/web
```

You can use the languageModel API to have a conversation with the AI, using whichever backend you choose.

```javascript
import AI from '@aibrow/web'

// WebGPU
const webGpu = await AI.AIBrowWeb.LanguageModel.create()
console.log(await webGpu.prompt('Write a short poem about the weather'))

// Llama.cpp
const ext = await AI.AIBrow.LanguageModel.create()
console.log(await ext.prompt('Write a short poem about the weather'))

// Chrome AI
const browser = await AI.Browser.LanguageModel.create()
console.log(await browser.prompt('Write a short poem about the weather'))
```

😃 Take a look at the [examples to get started](broken://pages/T5k1hHrhhnulko5JYtku)

📔 [Check out the API reference](/api-reference/aibrow) to see everything that AiBrow supports

👾 The AiBrow extension is on [GitHub](https://github.com/axonzeta/aibrow) if you want to contribute or chat

🧪 Try out some of the [AiBrow demos](https://aibrow.ai/demo.html)


# Getting started

The API allows you to make the best use of the device's hardware to run local AI in the browser in the most performant way possible. It's based around the [Chrome built-in AI APIs](https://developer.chrome.com/docs/ai/built-in-apis), but adds support for new features such as custom/HuggingFace models, grammar schemas, JSON output, LoRa Adapters, embeddings, and a fallback to a self-hosted or public server for lower-powered devices.

{% hint style="info" %}
Take a look at the [Feature comparison](/aibrow-web-api/feature-comparison) table for each implementation
{% endhint %}

## AiBrow extension using llama.cpp natively

Using the AiBrow extension gives the best on-device performance with the broadest feature-set. It's a browser extension that leverages the powerful [llama.cpp](https://github.com/ggerganov/llama.cpp) and can give great performance on all kinds of desktop computers either leveraging the GPU or CPU. Downloaded models are stored in a common repository meaning models only need to be downloaded once. You can use models provided by AiBrow, or any GGUF model hosted on [HuggingFace](https://huggingface.co/).

```javascript
import AI from '@aibrow/web'

const { ready, extension, helper } = await AI.AIBrow.capabilities()
if (ready) {
  const session = await AI.AIBrow.LanguageModel.create()
  console.log(await session.prompt('Write a short poem about the weather'))
} else {
  // Here are some tips to help users install the AiBrow extension & helper https://docs.aibrow.ai/guides/helping-users-install-aibrow
  console.log(`Extension is not fully installed. Extension=${extension}. Helper=${helper}`)
}
```

## AiBrow on WebGPU

WebGPU provides a good middle ground for performance and feature set, but it comes with some memory usage restrictions and performance overheads. If you only need to use small models or want to provide a fallback for when the extension isn't installed, this can provide a great solution. Under the hood, it uses [transformers.js](https://github.com/huggingface/transformers.js) from HuggingFace. Models are downloaded through an AiBrow frame, which means models only need to be downloaded once. You can use models provided by AiBrow, or any ONNX model hosted on [HuggingFace](https://huggingface.co/).

```javascript
import AI from '@aibrow/web'

const session = await AI.AIBrowWeb.LanguageModel.create()
console.log(await session.prompt('Write a short poem about the weather'))
```

## Chrome built-in AI

The Chrome built-in AI is a great option for simple tasks such as summarization, writing etc. It has a smaller feature set compared to the AiBrow extension and WebGPU and has reasonable on-device performance.

```javascript
import AI from '@aibrow/web'

if (AI.Browser.LanguageModel) {
  const session = await AI.Browser.LanguageModel.create()
  console.log(await session.prompt('Write a short poem about the weather'))
} else {
  console.log(`Your browser doesn't support on-device AI`)
}
```


# Feature comparison

<table><thead><tr><th width="130">Engine</th><th width="243">Targets</th><th width="146" data-type="checkbox">Custom models</th><th data-type="checkbox">HuggingFace models</th><th width="149" data-type="checkbox">Runs on-device</th><th width="157" data-type="checkbox">Grammar output</th><th width="152" data-type="checkbox">LoRA Adapters</th><th width="133" data-type="checkbox">Embeddings</th><th width="143" data-type="checkbox">GPU Required</th><th data-type="rating" data-max="5">Performance</th></tr></thead><tbody><tr><td>Chrome AI</td><td>Chrome Desktop</td><td>false</td><td>false</td><td>true</td><td>true</td><td>false</td><td>false</td><td>true</td><td>3</td></tr><tr><td>llama.cpp</td><td>Desktop Browsers</td><td>true</td><td>true</td><td>true</td><td>true</td><td>true</td><td>true</td><td>false</td><td>5</td></tr><tr><td>WebGPU</td><td>Desktop &#x26; Android Browsers</td><td>true</td><td>true</td><td>true</td><td>false</td><td>false</td><td>true</td><td>true</td><td>1</td></tr></tbody></table>


# Getting started

## Using AiBrow from a webpage

AiBrow embeds itself into all pages using the `window.aibrow` namespace. If the browser doesn't support on-device AI, AiBrow will also polyfill the relevant APIs (i.e `window.LanguageModel` ). Check out our [developer docs](https://docs.aibrow.ai/) on how to get started!

```javascript
if (window.aibrow) {
  const { helper } = await window.aibrow.capabilities()
  if (helper) {
    const session = await window.aibrow.LanguageModel.create()
    const stream = await sess.promptStreaming('Write a poem about AI in the browser')
    for await (const chunk of stream) {
      console.log(chunk)
    }
  } else {
    console.log('Aibrow helper not installed')
  }
} else {
  console.log('Aibrow not installed')
}
```

### **Typescript types**

Types for `window.aibrow` can be added to your project by using the `npm install --save-dev` [`@aibrow/dom-types`](https://www.npmjs.com/package/@aibrow/dom-types) package. Then, to expose them, place the following either in your `global.d.ts` or the entry point to your code

```typescript
import type AI from "@aibrow/dom-types"

declare global {
  interface Window {
    readonly aibrow: typeof AI;
  }
}
```

## Using AiBrow from another extension

Install the library using `npm install` [`@aibrow/extension`](https://www.npmjs.com/package/@aibrow/extension)

```javascript
import aibrow from '@aibrow/extension'

const { helper, extension } = await aibrow.capabilities()
if (extension) {
  if (helper) {
    const session = await aibrow.LanguageModel.create()
    const stream = await sess.promptStreaming('Write a poem about AI in the browser')
    for await (const chunk of stream) {
      console.log(chunk)
    }
  } else {
    console.log('Aibrow helper not installed')
  }
} else {
  console.log('Aibrow not installed')
}
```


# Web polyfill

Not all browsers support the on-device AI APIs, so when AiBrow is installed and those APIs are unavailable, it automatically polyfills these fields. The API should provide the same level of compatibility as the native built-in APIs, and the user will be guided to complete the extension install at use.

If you want to check if the APIs have been polyfilled, you can check the `aibrow` property on each:

```javascript
window.LanguageModel?.aibrow === true // aibrow has polyfilled window.LanguageModel
window.LanguageDetector?.aibrow === true // aibrow has polyfilled window.LanguageDetector
window.Rewriter?.aibrow === true // aibrow has polyfilled window.Rewriter
window.Summarizer?.aibrow === true // aibrow has polyfilled window.SummarizeruageModel
window.Translator?.aibrow === true // aibrow has polyfilled window.Translator
window.Writer?.aibrow === true // aibrow has polyfilled window.Writer
```


# Helping users install the AiBrow extension

Once you've created a site that uses AiBrow, then you can automatically detect if the extension and on-device helper are installed.

If you find that AiBrow isn't installed, we have some handy links that can help with installing the extension. The AiBrow install page accepts a redirect argument, which, once the extension is installed, will redirect back to your page.

To use this, direct the user to the following URL `https://aibrow.ai/install?redirect_to=your_url`

The flow that users will be taken through is...

1. Install from the Chrome Web Store / Firefox Addon Store to install the extension
2. Once the extension installation is complete, they'll be asked to download the on-device helper
3. After the on-device helper is installed, they'll either be taken to your provided `redirect_to` URL or to the AiBrow examples page

AiBrow has two components, the browser extension and the helper binary. Users will need both installed to use a model. After the browser extension is installed, users are prompted to continue the installation and download the helper binary, but you should still be prepared to handle cases where this has not been completed. AiBrow provides some helper utilities to check the current installation state and direct users to download the helper binary when needed.

## Detection & installation from a webpage

You can detect if AiBrow is installed and help the user install the extension from your website

```javascript
async function checkInstalled () {
  if (!window.aibrow) {
    // The extension is not installed
    console.log(`Install the extension from https://aibrow.ai/install?redirect_to=${window.location.href}`)
    return false
  }
  
  const capabilities = await window.aibrow.capabilities()
  if (!capabilities.helper) {
    // The helper binary is not installed. We can fetch the direct link to the latest
    // version for the current platform
    const helperUrl = await window.aibrow.getHelperDownloadUrl()
    console.log(`Install the helper from ${helperUrl} or https://aibrow.ai/install?redirect_to=${window.location.href}`)
    return false
  }
  
  // We're all installed
  return true
}

checkInstalled()
```

## Detection & installation from an extension

Your extension should pre-bundle the AiBrow library, but it still needs the AiBrow extension and native helper installed. You can help users install from your extension.

```javascript
import aibrow from '@aibrow/extension'

async function checkInstalled () {  
  const capabilities = await aibrow.capabilities()
  if (!capabilities.extension) {
    // The extension is not installed
    console.log('Install the extension from https://chromewebstore.google.com/detail/aibrow/bbkbjiehfkggfkbampigbbakecijicdm')
    return false
  }
  if (!capabilities.helper) {
    // The helper binary is not installed. We can fetch the direct link to the latest
    // version for the current platform
    const helperUrl = await aibrow.getHelperDownloadUrl()
    console.log(`Install the helper from ${helperUrl}`)
    return false
  }
  
  // We're all installed
  return true
}

checkInstalled()
```

## Detect if AiBrow is polyfilling browser AI APIs

If the browser doesn't support native AI APIs, AiBrow will automatically polyfill these. You can detect if this has happened using the `aibrow` property. For example...

```javascript
if (window.LanguageModel && window.LanguageModel.aibrow === true) {
  // AiBrow is polyfilling the window.LanguageModel API
  console.log('You\'re all set to go!')
}
```


# Remove the on-device helper or models

If you want to remove models, the easiest way is to use the AiBrow extensions option page.

1. **Right-click** on the AiBrow extension at the top of your browser window (it may also be under the extensions button). Then click on **Options**
2. Under the **Installed Models** section, press the delete button for any model that you want to remove

If you want to remove the helper and models completely, you can remove the AiBrow data directory. This is located in the following locations:

* **macOS** `~/Library/Application Support/Axonzeta/AiBrow`
* **Windows** `~/AppData/Local/Axonzeta/AiBrow`
* **Linux** `~/.config/Axonzeta/AiBrow`


# Embedding API

AiBrow allows you to create embeddings from any piece of text. These can then be stored and searched over to find similar text to a new input

```javascript
import AI from '@aibrow/web'

// Create the session
const session = await AI.AIBrow.Embedding.create()

// Generate embeddings for known data
const data = {
  '1': 'data1',
  '2': 'data2',
  ...
}
const dataIds = Object.keys(data)
const vectors = await session.get(dataIds.map((id) => data[id]))
const embeddings = dataIds.map((id, index) => ({ id, vector: vectors[index] })

// Sort the list of embeddings by the most similar
const search = await session.get('search data')
const results = session.findSimilar(embeddings, search)
console.log(data[results[0].id])

```


# LanguageDetector API

The language detector API allows you to rewrite some text using the language model.

{% hint style="success" %}
This API is compatible with the [Translation API proposal](https://github.com/WICG/translation-api) shipping with Google Chrome
{% endhint %}

Use the language detector API to detect the language of some text.

```javascript
import AI from '@aibrow/web'
const detector = await AI.AIBrow.LanguageDetector.create()

// Prompt the model
const results = await detector.detect("Hello world")
console.log(`The language is ${results[0].detectedLanguage} with a confidence of ${results[0].confidence}`)

```


# LanguageModel API

The language model API allows you to create a conversation with the language model.

{% hint style="success" %}
This API is compatible with the [Prompt API proposal](https://github.com/explainers-by-googlers/prompt-api) shipping with Google Chrome
{% endhint %}

<pre class="language-javascript"><code class="lang-javascript">import AI from '@aibrow/web'
const session = await AI.AIBrow.LanguageModel.create();

// Prompt the model and wait for the whole result to come back.
const result = await session.prompt("Write me a poem.");
console.log(result);

// Prompt the model and stream the result:
const stream = await session.promptStreaming("Write me an extra-long poem.");
for await (const chunk of stream) {
  console.log(chunk);
<strong>}
</strong></code></pre>

## Continuing a conversation

```javascript
import AI from '@aibrow/web'
const session = await AI.AIBrow.LanguageModel.create();

// Ask the intial question
const result = await session.prompt("Tell me about the weather");
console.log(result);

// Prompt the same session again to continue the same conversation
const result2 = await session.prompt("Can you expand on this?");
console.log(result2);
```

## System prompts & initial prompts

You can use system prompts to customize the behaviour of the model as well as initial prompts from a previous conversation

```javascript
import AI from '@aibrow/web'

const session = await AI.AIBrow.LanguageModel.create({
  initialPrompts: [
    { role: "system", content: "Speak like a pirate" },
    { role: "user", content: "What's your favourite word?" },
    { role: "assistant", content: "Swashbuckling" }
  ]
});

async function randomWord () {
  // Clone the session
  const freshSession = await session.clone()
  return await freshSessiong.prompt("Give me another")
}

// Continue the conversation from the initial prompts
console.log(await randomWord())
console.log(await randomWord())

```

## Demos

[Email subject generator](https://demo.aibrow.ai/demos/languagemodel-email-subject-generator/)

[Spreadsheet autofill](https://demo.aibrow.ai/demos/coremodel-spreadsheet-autofill/)


# Rewriter API

The rewriter API allows you to rewrite some text using the language model.

{% hint style="success" %}
This API is compatible with the [Writing assistance API proposal](https://github.com/WICG/writing-assistance-apis) shipping with Google Chrome
{% endhint %}

Use the rewriter API to change the length of some text, change the formality, rephrase text or change it to use simpler words and concepts (i.e. explain like I'm 5)

<pre class="language-javascript"><code class="lang-javascript">import AI from '@aibrow/web'

<strong>const rewriter = await AI.AIBrow.Rewriter.create({
</strong>  tone: "more-formal",
  length: "as-is"
})

// Prompt the model and wait for the whole result to come back.
const result = await rewriter.rewrite("An article comparing Vim vs Emacs as the best text editor")

// Prompt the model and stream the result:
const stream = await rewriter.rewriteStreaming("An article comparing Vim vs Emacs as the best text editor")
for await (const chunk of stream) {
  console.log(chunk)
}
</code></pre>


# Summarizer API

The summarizer API allows you to summarize some text using the language model.

{% hint style="success" %}
This API is compatible with the [Writing assistance API proposal](https://github.com/WICG/writing-assistance-apis) shipping with Google Chrome
{% endhint %}

Use the summarizer API to summarize meeting transcripts, give a sentence or paragraph-sized summary of product reviews, summarize long articles or generate article titles.

```javascript
import AI from '@aibrow/web'

const summarizer = await AI.AIBrow.Summarizer.create({
  type: "tl;dr",
  length: "short"
})

// Prompt the model and wait for the whole result to come back.
const result = await summarizer.summarize("An article comparing Vim vs Emacs as the best text editor")

// Prompt the model and stream the result:
const stream = await summarizer.summarizeStreaming("An article comparing Vim vs Emacs as the best text editor")
for await (const chunk of stream) {
  console.log(chunk)
}
```

## Demos

[Email subject generator](https://demo.aibrow.ai/demos/summarizer-email-subject-generator/)

[Support ticket autofill](https://demo.aibrow.ai/demos/summarizer-support-ticket-autofill/)


# Translator API

The translation API allows you to rewrite some text in a different language

{% hint style="success" %}
This API is compatible with the [Translation API proposal](https://github.com/WICG/translation-api) shipping with Google Chrome
{% endhint %}

Use the translation API to translate a block of text

```javascript
import AI from '@aibrow/web'

const translator = await AI.AIBrow.Translator.create({
  sourceLanguage: 'en',
  targetLanguage: 'es'
});

// Prompt the model and wait for the whole result to come back.
const result = await translator.translate("If you don't build your dream, someone else will hire you to help them build theirs.");
console.log(result);

// Prompt the model and stream the result:
const stream = await translator.translateStreaming("If you don't build your dream, someone else will hire you to help them build theirs.");
for await (const chunk of stream) {
  console.log(chunk);
}
```


# Writer API

The writer API allows you to generate some text using the language model.

{% hint style="success" %}
This API is compatible with the [Writing assistance API proposal](https://github.com/WICG/writing-assistance-apis) shipping with Google Chrome
{% endhint %}

Use the writer API to generate textual explanations of structured data, expand pro/con lists, break through writer's block and create a first draft of blog articles.

```javascript
import AI from '@aibrow/web'

const writer = await AI.AIBrow.Rriter.create({
  tone: "formal",
  length: "medium"
})

// Prompt the model and wait for the whole result to come back.
const result = await writer.write("An article comparing Vim vs Emacs as the best text editor")

// Prompt the model and stream the result:
const stream = await writer.writeStreaming("An article comparing Vim vs Emacs as the best text editor")
for await (const chunk of stream) {
  console.log(chunk)
}
```


# Using different models

Unlike the built-in AI APIs, AIBrow has support for multiple models. It ships with a default model, but you can request that your page use a different model. When a model is downloaded, it becomes available to all sites on the machine, meaning it only needs to be downloaded once.

Specifying a model can be useful if a specific model provides better responses to the types of prompts you're using.

{% hint style="success" %}
Look at the current list of [supported models](/api-reference/models), or [request more](https://github.com/axonzeta/aibrow/issues)!
{% endhint %}

## Use a different model

All the top-level AiBrow APIs support requesting a model through the create call.

```javascript
import AI from '@aibrow/web'

// All the top-level APIs support the model field, such as
//   * AI.AIBrow.LanguageModel({ ... })
//   * window.aibrow.LanguageModel({ ... })
//   * AI.AIBrow.Summarizer.create({ ... })
//   * window.aibrow.Summarizer.create({ ... })
//   * AI.AIBrow.Writer.create({ ... })
//   * window.aibrow.Writer.create({ ... })
const session = await AI.AIBrow.LanguageModel.create({
  model: "phi-3-5-mini-instruct-q4-k-m"
})

const stream = await session.promptStreaming("write a long poem");
for await (const chunk of stream) {
  console.log(chunk)
}
```


# Model download feedback

AiBrow ships with a default model, so after installation everything is ready to go. AiBrow also shows the download progress in the extension and as a popup when a model is being downloaded.

There are instances where you might want to show the download progress on your website so the user is informed about the download and install progress. All the top-level APIs in AiBrow support emitting the download progress during the create call.

```javascript
import AI from '@aibrow/web'

const session = await ai.LanguageModel.create({
  monitor(m) {
    m.addEventListener("downloadprogress", e => {
      console.log(`Downloaded ${e.loaded} of ${e.total} bytes.`);
    })
  }
})
```


# Getting JSON output

AiBrow supports defining grammar on the `LanguageModel` API. This allows you to constrain the output as needed. [Grammar support](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md) is provided by `llama-cpp` .

{% hint style="info" %}
Learn more about [how to use Grammar](https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md)
{% endhint %}

Constraining the output allows you to confidently parse the output and work on it. This is an excellent way to chain prompts together and make full use of the language model. Here's how you can extract some data from some text as a JSON structure...

```javascript
import AI from '@aibrow/web'

const session = await AI.LanguageModel.create()
// We want to extract some data from this text
const prompt = "Extract data from the following text: John Doe is an innovative software developer with a passion for creating intuitive user experiences. Based in the heart of England, John has spent the past decade refining his craft, working with both startups and established tech companies. His deep commitment to quality and creativity is evident in the numerous award-winning apps he has developed, which continue to enrich the digital lives of users worldwide. Beyond his technical skills, John is admired for his collaborative spirit and mentorship, always eager to share his knowledge and inspire the next generation of tech enthusiasts."

// Define the type of object we want returned
const grammar = {
  "type": "object",
  "properties": {
    "first_name": {
      "type": "string"
    },
    "last_name": {
      "type": "string"
    },
    "country": {
      "type": "string"
    }
  }
}

// Prompt the model
const stream = await session.promptStreaming(prompt, { responseConstraint: grammar })
let output = ''
for await (const chunk of stream) {
  console.log(chunk)
  output += chunk
}

console.log(JSON.parse(output))
// { "first_name": "John", "last_name": "Doe", "country": "England" }
```


# Tool calling

AiBrow supports tool calling; you need to ensure you use a model and prompt that both support tool calling

```javascript
const session = await aibrow.LanguageModel.create({
  model: "https://huggingface.co/unsloth/Qwen3-8B-GGUF/resolve/main/Qwen3-8B-UD-Q4_K_XL.gguf",
  tools: [
    {
      name: "getWeather",
      description: "Get the weather in a location.",
      inputSchema: {
        type: "object",
        properties: {
          location: {
            type: "string",
            description: "The city to check for the weather condition.",
          },
        },
        required: ["location"],
      },
      async execute({ location }) {
        // Mock a http weather call
        await new Promise((resolve) => setTimeout(resolve,1000))
        return JSON.stringify({
          location,
          forecast: "Sunny, with a low chance of rain in the afternoon"
        })
      }
    }
  ]
})

await session.prompt("What is the weather in London?");
```


# AI

```javascript
import AI from '@aibrow/web'
```

## Properties

### AIBrow

[`AIBrow`](/api-reference/ai/aibrow)

The AiBrow llama.cpp extension implementation of AiBrow

### Browser

[`BrowserAI`](/api-reference/ai/browserai)

The browsers implementation of the AI APIs

### AIBrowWeb

[`AIBrowWeb`](/api-reference/ai/aibrowweb)

The AiBrow WebGPU & WASM implementation of AiBrow


# AIBrow

```javascript
import AI from '@aibrow/web'
console.log(AI.AIBrow)
```

The AIBrow llama.cpp extension implementation of AiBrow

## Properties

## Embedding

[`Embedding`](/api-reference/aibrow/embedding)

### LanguageDetector

[`LanguageDetector`](#languagedetector)

### LanguageModel

[`LanguageModel`](/api-reference/aibrow/languagemodel)

### Rewriter

[`Rewriter`](/api-reference/aibrow/rewriter)

### Summarizer

[`Summarizer`](/api-reference/aibrow/summarizer)

### Translator

[`Translator`](/api-reference/aibrow/translator)

### Writer

[`Writer`](/api-reference/aibrow/writer)

***

## Methods

### capabilities

`async capabilities() => { ready: boolean, helper: boolean, extension: boolean }`

Get the capabilities of the on-device language ai.

### getHelperDownloadUrl

`async getHelperDownloadUrl() => string`

Returns a link to download the AiBrow helper for this platform. This call relies on the network to fetch the latest request, so it should only be used as needed.


# BrowserAI

```javascript
import AI from '@aibrow/web'
console.log(AI.Browser)
```

The browsers AI implementation

## Properties

### LanguageDetector

`LanguageDetector`

### LanguageModel

`LanguageModel`

### Rewriter

`Rewriter`

### Summarizer

`Summarizer`

### Translator

`Translator`

### Writer

`Writer`


# AIBrowWeb

```javascript
import AI from '@aibrow/web'
console.log(AI.AIBrowWeb)
```

The AIBrow WebGPU & WASM implementation of AiBrow

## Properties

## Embedding

[`Embedding`](/api-reference/aibrow/embedding)

### LanguageDetector

[`LanguageDetector`](#languagedetector)

### LanguageModel

[`LanguageModel`](/api-reference/aibrow/languagemodel)

### Rewriter

[`Rewriter`](/api-reference/aibrow/rewriter)

### Summarizer

[`Summarizer`](/api-reference/aibrow/summarizer)

### Translator

[`Translator`](/api-reference/aibrow/translator)

### Writer

[`Writer`](/api-reference/aibrow/writer)

***

## Methods

### capabilities

`async capabilities() => { ready: boolean }`

Get the capabilities of the web ai.


# AiBrow

The AiBrow API is implemented by a number of different backends. These could be:

* [llama.cpp through the AiBrow extension](/api-reference/ai/aibrow)
* [WebGPU & WASM in the browser](/api-reference/ai/aibrowweb)
* [The Chrome Prompt API in the browser](/api-reference/ai/browserai)

##


# Embedding

{% hint style="info" %}
Only available on the <mark style="background-color:green;">extension</mark> & <mark style="background-color:purple;">web</mark> implementations
{% endhint %}

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                             |
| ---------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                             |
| ---------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Embedding`](/api-reference/aibrow/embedding)

Creates a new embedding session

| Options (optional)                                                                             |
| ---------------------------------------------------------------------------------------------- |
| **options** `optional` [`EmbeddingCreateOptions`](/api-reference/types/embeddingcreateoptions) |

Returns a new Embedding session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention

`boolean`

### contextSize

`number`

***

## Methods

### get

`async (input, options) => number[] | number[][]`

Creates a new vector from the provided input

| Input                                                  |
| ------------------------------------------------------ |
| A `string` or `strings[]` to generate a vector(s) from |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns the vector or vectors from the language model

### calculateCosineSimilarity

`(vectorA, vectorB) => number`

Calculates the cosine similarity between two embeddings. Only compare embeddings created by the same model

| vectorA                        |
| ------------------------------ |
| A `number[]` vector to compare |

| vectorB                        |
| ------------------------------ |
| A `number[]` vector to compare |

Returns a value between 0 and 1 representing the similarity. 1 being the most similar

### findSimilar

`(embeddings, target) => any[]`

Finds and sorts similar vectors

| embeddings                                                                          |
| ----------------------------------------------------------------------------------- |
| An `Array<{ id: any, vector: number[] }>` array of objects, each with id and vector |

| target                                          |
| ----------------------------------------------- |
| A `number[]` vector to use as the search target |

Returns a list of ids, sorted by the most similar to the least similar


# LanguageDetector

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                           |
| ------------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageDetectorCreateOptions`](/api-reference/types/languagedetectorcreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                           |
| ------------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageDetectorCreateOptions`](/api-reference/types/languagedetectorcreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`LanguageDetector`](/api-reference/aibrow/languagedetector)&#x20;

Creates a new embedding session

| Options (optional)                                                                                           |
| ------------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageDetectorCreateOptions`](/api-reference/types/languagedetectorcreateoptions) |

Returns a new LanguageDetector session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputQuota

`number`&#x20;

### expectedInputLanguages

`string[]`&#x20;

***

## Methods

### detect

`async (input, options) =>` [`LanguageDetectorDetectResult`](/api-reference/types/languagedetectordetectresult)`[]`

This prompts the language model to detect which language is being used in the input text

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns an array of detection results from the language model

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# LanguageModel

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                     |
| ------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageModelCreateOptions`](/api-reference/types/languagemodelcreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                                     |
| ------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageModelCreateOptions`](/api-reference/types/languagemodelcreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`LanguageModel`](/api-reference/aibrow/languagemodel)&#x20;

Creates a new embedding session

| Options (optional)                                                                                     |
| ------------------------------------------------------------------------------------------------------ |
| **options** `optional` [`LanguageModelCreateOptions`](/api-reference/types/languagemodelcreateoptions) |

Returns a new LanguageModel session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputUsage

`number`&#x20;

### inputQuota

`number`&#x20;

### topK

`number`&#x20;

### topP <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

### temperature

`number`&#x20;

### repeatPenalty <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

***

## Methods

### prompt

`async (input, options) => string`

See [promptStreaming](#promptstreaming)

### promptStreaming

`(input, options) => ReadableStream`

This prompts the language model with a continuation of the conversation. Internally, the input is appended to the set of messages in the language model's context window. Older messages outside of the language model's context window are automatically discarded.

<table><thead><tr><th>Input</th></tr></thead><tbody><tr><td><p>Either a <code>string</code>, single prompt or array of prompts such as</p><pre class="language-javascript"><code class="lang-javascript">[
  { content: "The prompt content", role: "user" },
  { content: "The prompt content", role: "assistant" }
]
</code></pre></td></tr></tbody></table>

| Options (optional)                       |
| ---------------------------------------- |
| **signal** `optional AbortSignal`        |
| **responseConstrains** `optional object` |

Returns a readable stream that updates each time new tokens are available from the language model

### append

`async (input) =>` `void`

Appends a message to the conversation without prompting the model

| Input      |
| ---------- |
| A `string` |

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# Rewriter

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                           |
| -------------------------------------------------------------------------------------------- |
| **options** `optional` [`RewriterCreateOptions`](/api-reference/types/rewritercreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                           |
| -------------------------------------------------------------------------------------------- |
| **options** `optional` [`RewriterCreateOptions`](/api-reference/types/rewritercreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Rewriter`](/api-reference/aibrow/rewriter)&#x20;

Creates a new embedding session

| Options (optional)                                                                           |
| -------------------------------------------------------------------------------------------- |
| **options** `optional` [`RewriterCreateOptions`](/api-reference/types/rewritercreateoptions) |

Returns a new Rewriter session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputQuota

`number`&#x20;

### repeatPenalty <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

### sharedContext

`string`&#x20;

### tone

[`RewriterTone`](/api-reference/types/rewritertone)&#x20;

### format

[`RewriterFormat` ](/api-reference/types/rewriterformat)

### length

[`RewriterLength` ](/api-reference/types/rewriterlength)

### expectedInputLanguages

`string[]`&#x20;

### expectedContextLanguages

`string[]`&#x20;

***

## Methods

### rewrite

`async (input, options) => string`

See [rewriteStreaming](#rewritestreaming)

### rewriteStreaming

`(input, options) => ReadableStream`

This prompts the model to rewrite the given input and session options.

| Input                                    |
| ---------------------------------------- |
| A `string`containing the text to rewrite |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |
| **context** `optional string`     |

Returns a readable stream that updates each time new tokens are available from the language model

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# Summarizer

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                               |
| ------------------------------------------------------------------------------------------------ |
| **options** `optional` [`SummarizerCreateOptions`](/api-reference/types/summarizercreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                               |
| ------------------------------------------------------------------------------------------------ |
| **options** `optional` [`SummarizerCreateOptions`](/api-reference/types/summarizercreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Summarizer`](/api-reference/aibrow/summarizer)

Creates a new embedding session

| Options (optional)                                                                               |
| ------------------------------------------------------------------------------------------------ |
| **options** `optional` [`SummarizerCreateOptions`](/api-reference/types/summarizercreateoptions) |

Returns a new Summarizer session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputQuota

`number`&#x20;

### repeatPenalty <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

### sharedContext

`string`&#x20;

### format

&#x20;[`SummarizerFormat`](/api-reference/types/summarizerformat)

### length

&#x20;[`SummarizerLength`](/api-reference/types/summarizerlength)&#x20;

### type

&#x20;[`SummarizerType`](/api-reference/types/summarizertype)&#x20;

### expectedInputLanguages

`string[]`&#x20;

### expectedContextLanguages

`string[]`&#x20;

***

## Methods

### summarize

`async (input, options) => string`

See [summarizeStreaming](#summarizestreaming)

### summarizeStreaming

`(input, options) => ReadableStream`

This prompts the model to rewrite the given input and session options.

| Input                                    |
| ---------------------------------------- |
| A `string`containing the text to rewrite |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |
| **context** `optional string`     |

Returns a readable stream that updates each time new tokens are available from the language model

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# Translator

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                    |
| ------------------------------------------------------------------------------------- |
| **options** [`TranslatorCreateOptions`](/api-reference/types/translatorcreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                    |
| ------------------------------------------------------------------------------------- |
| **options** [`TranslatorCreateOptions`](/api-reference/types/translatorcreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Translator`](/api-reference/aibrow/translator)

Creates a new embedding session

| Options (optional)                                                                    |
| ------------------------------------------------------------------------------------- |
| **options** [`TranslatorCreateOptions`](/api-reference/types/translatorcreateoptions) |

Returns a new Translator session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputQuota

`number`&#x20;

### repeatPenalty <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

### sourceLanguage

`string`&#x20;

### targetLanguage

`string`&#x20;

***

## Methods

### translate

`async (input, options) => string`

See [translateStreaming](#translatestreaming)

### translateStreaming

`(input, options) => ReadableStream`

This prompts the language model to translate the provided text. The returned stream should contain the translation

| Input                       |
| --------------------------- |
| A `string` to be translated |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns a readable stream that updates each time new tokens are available from the language model

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# Writer

## Static Methods

### <mark style="background-color:red;">static</mark> availability

`static async availability(options) =>`  [`AIModelAvailability`](/api-reference/types/aimodelavailability)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                       |
| ---------------------------------------------------------------------------------------- |
| **options** `optional` [`WriterCreateOptions`](/api-reference/types/writercreateoptions) |

Returns the availability

### <mark style="background-color:red;">static</mark> compatibility <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`static async compatibility(options) =>`  [`AIModelCoreCompatibility`](/api-reference/types/aimodelcorecompatibility)&#x20;

Get the availability of the on-device language model.

| Options (optional)                                                                       |
| ---------------------------------------------------------------------------------------- |
| **options** `optional` [`WriterCreateOptions`](/api-reference/types/writercreateoptions) |

Returns the compatibility

### <mark style="background-color:red;">static</mark> create

`static async create(options) =>` [`Writer`](/api-reference/aibrow/writer)&#x20;

Creates a new embedding session

| Options (optional)                                                                       |
| ---------------------------------------------------------------------------------------- |
| **options** `optional` [`WriterCreateOptions`](/api-reference/types/writercreateoptions) |

Returns a new Writer session that can be prompted with the pre-provided configuration

***

## Properties

### gpuEngine <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelGpuEngine`](/api-reference/types/aimodelgpuengine)&#x20;

### dtype <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

[`AIModelDtype`](/api-reference/types/aimodeldtype)&#x20;

### flashAttention <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`boolean`

### contextSize

`number`&#x20;

### inputQuota

`number`&#x20;

### repeatPenalty <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>

`number`&#x20;

### sharedContext

`string`&#x20;

### tone

[`WriterTone`](/api-reference/types/writertone)&#x20;

### format

[`WriterFormat` ](/api-reference/types/writerformat)

### length

[`WriterLength` ](/api-reference/types/writerlength)

### expectedInputLanguages

`string[]`&#x20;

### expectedContextLanguages

`string[]`&#x20;

***

## Methods

### write

`async (input, options) => string`

See [writeStreaming](#writestreaming)

### writeStreaming

`(input, options) => ReadableStream`

This prompts the model to rewrite the given input and session options.

| Input                                    |
| ---------------------------------------- |
| A `string`containing the text to rewrite |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |
| **context** `optional string`     |

Returns a readable stream that updates each time new tokens are available from the language model

### measureInputUsage

`async (input, options) =>` `number`

Measures the prompt usage of the input

| Input      |
| ---------- |
| A `string` |

| Options (optional)                |
| --------------------------------- |
| **signal** `optional AbortSignal` |

Returns prompt usage based on the input


# Types


# AIModelAvailability

A string enum that's used to indicate the availability of some functionality.

`unavailable`

`downloadable`

`downloading`

`available`


# AIModelCoreCompatibility

```typescript
score: number
  gpuEngines: AIModelGpuEngine[]
  flashAttention: boolean
  contextSize: AIModelManifestConfigRange
  
  
```

An object with the following properties

| Options                                                                                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| **score** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `number`                                                                |
| **gpuEngines** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> [`AICapabilityGpuEngine[]`](/api-reference/types/aimodelgpuengine) |
| **flashAttention** <mark style="background-color:purple;">web</mark> `boolean`                                                                                                             |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `number`                                                          |


# AIModelDtype

{% hint style="info" %}
Only available on the <mark style="background-color:purple;">web</mark> implementation
{% endhint %}

`auto`

`fp32`

`fp16`

`q8`

`int8`

`uint8`

`q4`

`bnb4`

`q4f16`


# AIModelGpuEngine

{% hint style="info" %}
Only available on the <mark style="background-color:green;">extension</mark> & <mark style="background-color:purple;">web</mark> implementations
{% endhint %}

A string enum that's used to indicate the availability of the GPU engine

`metal` <mark style="background-color:green;">extension</mark> <mark style="color:orange;">macOS</mark>

`cuda` <mark style="background-color:green;">extension</mark> <mark style="color:orange;">Windows, Linux</mark>

`vulkan` <mark style="background-color:green;">extension</mark> <mark style="color:orange;">Windows, Linux</mark>

`cpu` <mark style="background-color:green;">extension</mark>

`webgpu` <mark style="background-color:purple;">web</mark>

`wasm` <mark style="background-color:purple;">web</mark>


# AICreateMonitor

```typescript
(m: EventTarget) => void
```

A function which is passed an event target allowing it to monitor the creation progress. The monitor is normally updated when the model needs to be downloaded.

### The `downloadprogress` event

#### loaded `number`

The number of bytes downloaded so far

#### total `number`

The total number of bytes to download

#### model `string`

The id of the model that's being downloaded

## Usage

{% tabs %}
{% tab title="JavaScript" %}

```javascript
window.ai.languageModel.create({
  monitor: (m) => {
    m.addEventListener('downloadprogress', ({ loaded, total, model }) => {
      console.log(`${model} = `${Math.round(loaded / total * 100)}`)
    })
  }
})
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
window.ai.languageModel.create({
  monitor: (m: EventTarget) => {
    m.addEventListener('downloadprogress', ({ loaded, total, model }) => {
      console.log(`${model} = `${Math.round(loaded / total * 100)}`)
    })
  }
})
```

{% endtab %}
{% endtabs %}


# EmbeddingCreateOptions

An object with the following properties

| Options                                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **model** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional string`                                                               |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine) |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                         |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                           |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                     |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                         |
| **signal** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional AbortSignal`                                                         |
| **monitor** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)          |


# LanguageDetectorCreateOptions

An object with the following properties

| Options                                                                                                                                                                                            |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **model** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional string`                                                               |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine) |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                         |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                           |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                     |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                         |
| **signal** `optional AbortSignal`                                                                                                                                                                  |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                   |
| **expectedInputLanguages** `optional` `string[]`                                                                                                                                                   |


# LanguageDetectorDetectResult

An object containing information about a language detection.

## Properties

### detectedLanguage

`string`

The language code of the detected language, e.g. `en`, `es` or `fr`

### confidence

`number`

A number between 0 and 1. 1 indicating high confidence, 0 no confidence


# LanguageModelCreateOptions

An object with the following properties

| Options                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>model</strong> <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> <code>optional string</code><br>The id of the model to use, undefined to use the default. The extension version also accepts a direct link to a HuggingFace GGUF file. The web version also accepts the repo & name of a HuggingFace ONNX repo.</p> |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine)                                                                                                                                                                                     |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                                                                                                                                                                                                             |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                               |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                                                                                                                                                                                                         |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                             |
| **signal** `optional AbortSignal`                                                                                                                                                                                                                                                                                                                                                      |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                                                                                                                                                                                                       |
| **initialPrompts** `optional` `LanguageModelInitialPrompts[]`                                                                                                                                                                                                                                                                                                                          |
| **topK** `optional number`                                                                                                                                                                                                                                                                                                                                                             |
| **topP** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>   `optional number`                                                                                                                                                                                                                                                  |
| **repeatPenalty** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark>   `optional number`                                                                                                                                                                                                                                         |
| **temperature**   `optional number`                                                                                                                                                                                                                                                                                                                                                    |
| **expectedInputs**  `optional LanguageModelExpectedInput[]`                                                                                                                                                                                                                                                                                                                            |


# RewriterCreateOptions

An object with the following properties

| Options                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>model</strong> <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> <code>optional string</code><br>The id of the model to use, undefined to use the default. The extension version also accepts a direct link to a HuggingFace GGUF file. The web version also accepts the repo & name of a HuggingFace ONNX repo.</p> |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine)                                                                                                                                                                                     |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                                                                                                                                                                                                             |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                               |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                                                                                                                                                                                                         |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                             |
| **signal** `optional AbortSignal`                                                                                                                                                                                                                                                                                                                                                      |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                                                                                                                                                                                                       |
| **tone** `optional` [`RewriterTone`](/api-reference/types/rewritertone)                                                                                                                                                                                                                                                                                                                |
| **format** `optional` [`RewriterFormat`](/api-reference/types/rewriterformat)                                                                                                                                                                                                                                                                                                          |
| **length** `optional` [`RewriterLength`](/api-reference/types/rewriterlength)                                                                                                                                                                                                                                                                                                          |
| **expectedInputLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                         |
| **expectedContextLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                       |
| **outputLanguage** `optional string`                                                                                                                                                                                                                                                                                                                                                   |
| **sharedContext** `optional string`                                                                                                                                                                                                                                                                                                                                                    |


# RewriterFormat

A string enum that's used to indicate the rewriter format

`as-is`

`plain-text`

`markdown`


# RewriterLength

A string enum that's used to indicate the rewriter length

`as-is`

`shorter`

`longer`


# RewriterTone

A string enum that's used to indicate the rewriter tone

`as-is`

`more-formal`

`more-casual`


# SummarizerCreateOptions

An object with the following properties

| Options                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>model</strong> <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> <code>optional string</code><br>The id of the model to use, undefined to use the default. The extension version also accepts a direct link to a HuggingFace GGUF file. The web version also accepts the repo & name of a HuggingFace ONNX repo.</p> |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine)                                                                                                                                                                                     |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                                                                                                                                                                                                             |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                               |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                                                                                                                                                                                                         |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                             |
| **signal** `optional AbortSignal`                                                                                                                                                                                                                                                                                                                                                      |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                                                                                                                                                                                                       |
| **format** `optional` [`SummarierFormat`](/api-reference/types/summarizerformat)                                                                                                                                                                                                                                                                                                       |
| **length** `optional` [`SummarizerLength`](/api-reference/types/summarizerlength)                                                                                                                                                                                                                                                                                                      |
| **type** `optional` [`SummarizerType`](/api-reference/types/summarizertype)                                                                                                                                                                                                                                                                                                            |
| **expectedInputLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                         |
| **expectedContextLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                       |
| **outputLanguage** `optional string`                                                                                                                                                                                                                                                                                                                                                   |
| **sharedContext** `optional string`                                                                                                                                                                                                                                                                                                                                                    |


# SummarizerFormat

A string enum that's used to indicate the summarizer format

`plain-text`

`markdown`


# SummarizerLength

A string enum that's used to indicate the summarizer length

`short`

`medium`

`long`


# SummarizerType

A string enum that's used to indicate the summarizer type

`tl;dr`

`key-points`

`teaser`

`headline`


# TranslatorCreateOptions

An object with the following properties

| Options                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>model</strong> <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> <code>optional string</code><br>The id of the model to use, undefined to use the default. The extension version also accepts a direct link to a HuggingFace GGUF file. The web version also accepts the repo & name of a HuggingFace ONNX repo.</p> |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine)                                                                                                                                                                                     |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                                                                                                                                                                                                             |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                               |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                                                                                                                                                                                                         |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                             |
| **signal** `optional AbortSignal`                                                                                                                                                                                                                                                                                                                                                      |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                                                                                                                                                                                                       |
| **sourceLanguage**  `string`                                                                                                                                                                                                                                                                                                                                                           |
| **targetLanguage**  `string`                                                                                                                                                                                                                                                                                                                                                           |


# WriterCreateOptions

An object with the following properties

| Options                                                                                                                                                                                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p><strong>model</strong> <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> <code>optional string</code><br>The id of the model to use, undefined to use the default. The extension version also accepts a direct link to a HuggingFace GGUF file. The web version also accepts the repo & name of a HuggingFace ONNX repo.</p> |
| **gpuEngine** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional` [`AICapabilityGpuEngine`](/api-reference/types/aimodelgpuengine)                                                                                                                                                                                     |
| **dtype** <mark style="background-color:purple;">web</mark> `optional` [`AIModelDtype`](/api-reference/types/aimodeldtype)                                                                                                                                                                                                                                                             |
| **maxTokens** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                               |
| **flashAttention** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional boolean`                                                                                                                                                                                                                                         |
| **contextSize** <mark style="background-color:green;">extension</mark> <mark style="background-color:purple;">web</mark> `optional number`                                                                                                                                                                                                                                             |
| **signal** `optional AbortSignal`                                                                                                                                                                                                                                                                                                                                                      |
| **monitor** `optional` [`AICreateMonitor`](/api-reference/types/aicreatemonitor)                                                                                                                                                                                                                                                                                                       |
| **tone** `optional` [`WriterTone`](/api-reference/types/writertone)                                                                                                                                                                                                                                                                                                                    |
| **format** `optional` [`WriterFormat`](/api-reference/types/writerformat)                                                                                                                                                                                                                                                                                                              |
| **length** `optional` [`WriterLength`](/api-reference/types/writerlength)                                                                                                                                                                                                                                                                                                              |
| **expectedInputLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                         |
| **expectedContextLanguages** `optional string[]`                                                                                                                                                                                                                                                                                                                                       |
| **outputLanguage** `optional string`                                                                                                                                                                                                                                                                                                                                                   |
| **sharedContext** `optional string`                                                                                                                                                                                                                                                                                                                                                    |


# WriterFormat

A string enum that's used to indicate the writer format

`plain-text`

`markdown`


# WriterLength

A string enum that's used to indicate the writer length

`short`

`medium`

`long`


# WriterTone

A string enum that's used to indicate the writer tone

`formal`

`neutral`

`casual`


# Models

## List of available Models

AiBrow supports different models according to the local AI runtime being used. For Chrome AI, only the in-build Gemini Nano is available, whereas in both the WebGPU and Extension runtimes, a number of open weight models are all available.

This page currently describes the models available for the llama.cpp web extension runtime.

### Pre quantized models

The following models are available pre-quantized to q4-k-m. \
\
Use the model's **id** when calling the [**create** **function**](/examples/using-different-models) to use the selected model . AiBrow will present a permission popup for the first use of a model on each specific web domain. \
\
The model will automatically be downloaded if it's not currently present on the user's machine. Models are only downloaded once since they do not change. A new model version will have a new **id**.

### Language Models

| Name                        | id                                 |
| --------------------------- | ---------------------------------- |
| SmolLM2 1.7B Instruct       | smollm2-1-7b-instruct-q4-k-m       |
| SmolLM2 360M Instruct       | smollm2-360m-instruct-q4-k-m       |
| Gemma 2 2b Instruct         | gemma-2-2b-instruct-q4-k-m         |
| Gemma 2b Instruct           | gemma-2b-instruct-q4-k-m           |
| Llama 3.2 3B Instruct       | llama-3-2-3b-instruct-q4-k-m       |
| Llama 3.2 1B Instruct       | llama-3-2-1b-instruct-q4-k-m       |
| Qwen2.5 1.5b Instruct       | qwen2-5-1-5b-instruct-q4-k-m       |
| Qwen2.5 Coder 1.5B Instruct | qwen2-5-coder-1-5b-instruct-q4-k-m |
| Phi 3.5 Mini Instruct       | phi-3-5-mini-instruct-q4-k-m       |
| Granite 3.0 2b Instruct     | granite-3-0-2b-instruct-q4-k-m     |
| NuExtract v1.5              | nuextract-v1-5-q4-k-m              |

### Embedding Models

| Name                        | Id                         |
| --------------------------- | -------------------------- |
| Nomic Embed Text v1.5 q8\_0 | nomic-embed-text-v1-5-q8-0 |
| all-MiniLM-L6-v2            | all-minilm-l6-v2-q8-0      |

### Defaults

The current default models are **SmolLM2 1.7B Instruct** for language and translation, with **Nomic Embed Text** for embeddings.&#x20;

When using the APIs, it is best to specify your model id explicitly on each create function to ensure consistency if these defaults should change in the future.

### Hugging Face models

You can use any model that is openly available on Hugging Face by giving its URL, for example, "<https://huggingface.co/bartowski/gemma-2-2b-jpn-it-GGUF/resolve/main/gemma-2-2b-jpn-it-Q4_K_M.gguf>" would specify the quantized GGUF model for Gemma 2 JPN model.


