> For the complete documentation index, see [llms.txt](https://docs.aibrow.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.aibrow.ai/examples/languagemodel-api.md).

# 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/)
