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


---

# 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/examples/languagemodel-api.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.
