# 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')
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.aibrow.ai/aibrow-extension/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
