# AI form

## Installation

The AI form is already included with the chathive SDK. If you haven't installed it into your application, first follow the [SDK installation guide](/sdk/getting-started.md).

## Setup <a href="#installation" id="installation"></a>

To setup the AI form, call the constructor to initialise your AI form. There are many options you can pass to the constructor. See the [configuration documentation](/sdk/ai-form/configuration.md) for more details.&#x20;

```typescript
const aiForm = new Chathive.AIForm({ apiKey: "YOUR_API_KEY" });
```

{% hint style="info" %}
**Good to know:** For single-page apps, ensure this is executed after the SDK has fully loaded.
{% endhint %}

After initializing your AI form, you can embed it into your application. Ensure this is done after the `selector` element has rendered. The `selector` is a required parameter and uses `document.querySelector` to locate the HTML tag where you want to embed the form.

{% code overflow="wrap" %}

```typescript
aiForm.embed({ selector: "#embed" })
    .then(() => console.log("AI form is embedded"));
```

{% endcode %}


---

# 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://developers.chathive.app/sdk/ai-form.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.
