# X.AI Integration

### [XAI Integration](https://x.ai/)

The [XAI](https://x.ai/) integration empowers your Rapidbott chatbot with dynamic AI capabilities, enabling personalized, context-aware responses and advanced automation.&#x20;

#### **Step 1: Create Your XAI API Key** <a href="#step-1-create-your-inlinecard-api-key" id="step-1-create-your-inlinecard-api-key"></a>

To start using the **XAI** integration, you first need to create an API key. In your browser navigate to the **XAI** platform and within your account you can follow the instructions in the image below to generate your unique API key.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FUYOlkKzB5IW1gTdQRhon%2FUntitled.png?alt=media&#x26;token=ff6ee64b-2ec2-4978-b0c8-74bd32ea22a0" alt=""><figcaption></figcaption></figure>

**Step 2: Copy Your API Key and Wait for Provisioning**

Once you’ve generated the API key, copy it and wait until the provisioning process is completed. This may take a few moments. Ensure that the status indicates the key is ready to use before proceeding.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FCh31CwGWtr7NKPi08Vb8%2FUntitled.png?alt=media&#x26;token=ab950ea6-c0e6-4f3e-af77-ef1d08708073" alt=""><figcaption></figcaption></figure>

**Step 3: Configure the API Key in Rapidbott**

* Go to the **Integrations** section in your Rapidbott dashboard.
* Navigate to **XAI** and paste the copied **API key** into the designated field.
* Click **Save** and confirm that the status changes to “Verified.”

Once verified, you’re all set to start using **XAI** in your chatbot flows.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FuyQCoxyzrTop2XQNA2jp%2Fimage.png?alt=media&#x26;token=0a925a7e-4b87-43d7-a752-9bbafd6d3f08" alt=""><figcaption></figcaption></figure>

**Using XAI in Your Flows**

To incorporate **XAI** in your chatbot workflows:

1. Open your bot in **Rapidbott**.
2. Navigate to an **Action Node** in your flow.
3. Select **Integrations** and choose.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FXFb7wrsyqGoiwOIc0NGC%2Fimage.png?alt=media&#x26;token=5ec5aee6-3411-4950-9661-ad77db2a451a" alt=""><figcaption></figcaption></figure>

From here, you can configure the **XAI** integration to perform various actions, including Chat Completions.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FplniCwtlYApBGznSYN2k%2Fimage.png?alt=media&#x26;token=9da72c9f-6fe7-4b06-a9fc-28b93baa5951" alt=""><figcaption></figcaption></figure>

#### **Key Features and Configuration Options** <a href="#key-features-and-configuration-options" id="key-features-and-configuration-options"></a>

**Chat Completion**

This feature allows you to interact with **XAI** to generate dynamic responses for user interactions. Below are the configuration fields and their descriptions:

**Input Parameters**

&#x20;

&#x20;

**System Message:**\
This optional field provides context about your business or bot. For example, if you're creating a restaurant chatbot you can use something similar to this:\
`System: You are a Rapidbott steak restaurant helpful assistant. You will handle customer support, guide users, and book reservations. The restaurant operates from 9 am to 8 pm Monday to Saturday. No pets are allowed. Always offer the coupon code if applicable.`

* This helps the AI generate responses aligned with your business rules.

**Message:**\
This is the main user input or prompt for which you want the AI to generate a response. For example:\
`User: How I can make a reservation?`&#x20;

* You can use the system field `{{last_text_input}}` to dynamically pass user input.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FXOIWITVGaSrJz3eF4V8P%2Fimage.png?alt=media&#x26;token=4501b3bf-e2d3-4538-9f8b-640f690bb9e6" alt=""><figcaption></figcaption></figure>

**System JSON Field ({{XAi}}):**\
This field tracks the entire conversation history, including system setup and user interactions. The JSON is limited to 20,000 characters. Older entries will be deleted once this limit is reached.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fec9CRxR7E5wk7cwLDjZv%2Fimage.png?alt=media&#x26;token=156ffcce-0227-459f-8785-55daeedb2e1d" alt=""><figcaption></figcaption></figure>

**Model**

Select the AI model to use. By default, the system uses **grok-beta**.

**Max Tokens**

Limits the number of tokens consumed during a task. This is useful for controlling response length and token usage.

**Temperature**

Controls the randomness of responses.

* Higher values (e.g., 1.0) produce more creative answers.
* Lower values (e.g., 0.2) result in more deterministic answers.

**Presence Penalty**

Encourages the AI to generate unique phrases. Higher values reduce repetition.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FCPILga05WWDcTjhZbblM%2FUntitled.png?alt=media&#x26;token=fb033c68-0de5-4d2a-9e4e-cc2ee420573e" alt=""><figcaption></figcaption></figure>

**Frequency Penalty**

Controls how much to penalize new tokens based on their frequency in the text so far.

* **Default Value:** `0`
* **Behavior:**
  * A higher value discourages the AI from repeating lines or phrases verbatim.
  * A value of `0` allows responses to have natural repetitions.

**Recommendation:** Adjust this if you want less repetitive responses.

&#x20;

**Stop Sequences**

Defines up to 4 sequences where the AI will stop generating tokens.

**Number of Completions**

Specifies how many responses the AI should generate for a single prompt.

* **Default Value:** `1`
* **Caution:** Setting a higher value will consume more tokens and API quota.

Best used when you want multiple variations of the response for comparison.

**Example Usage:** Generate 3 options to pick the most suitable reply for a customer query.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FlCMCehKLUTPQ89gi9x96%2FUntitled.png?alt=media&#x26;token=0f05ad67-d5de-4618-80f0-3d1fa9d2617d" alt=""><figcaption></figcaption></figure>

**Testing the Configuration**

1. Make a test request.
2. Map the assistant's response to a **Custom User Field** (e.g., a text field).
3. Save your configuration.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2Fu6OqOSnkJTgRq17BZYe5%2Fimage.png?alt=media&#x26;token=fcb01576-2152-4b50-83bf-34b379af802e" alt=""><figcaption></figcaption></figure>

**Sample Response:**

json

&#x20;

`{`

&#x20; `"id": "3b52aa21-8cba-4499-9732-2133d4bbe1f2",`

&#x20; `"object": "chat.completion",`

&#x20; `"created": 1732584765,`

&#x20; `"model": "grok-beta",`

&#x20; `"choices": [`

&#x20;   `{`

&#x20;     `"index": 0,`

&#x20;     `"message": {`

&#x20;       `"role": "assistant",`

&#x20;       `"content": "To make a reservation at our steak restaurant, please provide me with the following details: - Date and Time for your reservation - The number of people in your party - Your name - A contact number or email address for confirmation. Once I have this information, I can check availability and proceed with booking your reservation."`

&#x20;     `},`

&#x20;     `"finish_reason": "stop"`

&#x20;   `}`

&#x20; `],`

&#x20; `"usage": {`

&#x20;   `"prompt_tokens": 78,`

&#x20;   `"completion_tokens": 139,`

&#x20;   `"total_tokens": 217`

&#x20; `}`

`}`

&#x20;

&#x20;**Building a Chatbot Flow**

Once the **XAI** integration is configured, you can build advanced chatbot flows. For example:

1. Add a **Text Question Node** to send the **XAI** response and capture the user input.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FnZytAHcgLO275E8zyu1z%2Fimage.png?alt=media&#x26;token=5917e107-0e72-4876-bd1c-314bc1b1b47f" alt=""><figcaption></figcaption></figure>

2. Use the `</>` symbol to search for the Custom User Field that stores the **XAI** response.

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FAmOPzgWTD3MAQsByBnJd%2Fimage.png?alt=media&#x26;token=90ed2a7a-b5be-482e-abc0-0a65a2604e7b" alt=""><figcaption></figcaption></figure>

This flow is an example of a simple flow that can be used as a standard response. You can use your creativity to create flows according to your use case:

<figure><img src="https://2144409983-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHbDmB8MlZRo4hzrDiO0X%2Fuploads%2FfNMuSMq1sejo3icTuQPO%2FUntitled.png?alt=media&#x26;token=56f221c8-4d95-4b90-945f-6662cb7dac88" alt=""><figcaption></figcaption></figure>

#### **Creative Use Cases** <a href="#creative-use-cases" id="creative-use-cases"></a>

This integration can be tailored to your business needs. For instance:

* Automating restaurant bookings.
* Answering FAQs with dynamic, context-aware responses.
* Offering personalized recommendations based on user input.

By leveraging **XAI’s** capabilities, you can build efficient, intuitive, and highly responsive chatbot experiences for your users.


---

# 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.rapidbott.com/help-center/artificial-intelligencs/x.ai-integration.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.
