# Assisterr SLM Integration

The **Assisterr SLM Integration** allows users to interact with the Small Language Model (SLM) through a set of API endpoints.

> You can check API documenation [here](https://github.com/assister-xyz/slm-integrations).

## Base URL

All requests should be made to the following base URL:

```
https://api.assisterr.ai/
```

## Authentication

To authenticate API requests, you must include your API key in the **X-Api-Key** header for each request.

## Endpoints

### \[POST] /api/v1/slm/{handle\_name}/chat/

**Description:** Sends a query to SLM (Stateful Language Model) and retrieves a response without maintaining any session history.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

| Parameter     | Type   | Required | Description                    |
| ------------- | ------ | -------- | ------------------------------ |
| `handle_name` | string | Yes      | Unique identifier for the slm. |

**Request Body (JSON):**

```json
{
  "query": "Your query here"
}
```

### \[POST] /api/v1/slm/{handle\_name}/chat/stream/

**Description:** Sends a query to SLM and retrieves a streaming response (via SSE), without maintaining any session history.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

| Parameter     | Type   | Required | Description                    |
| ------------- | ------ | -------- | ------------------------------ |
| `handle_name` | string | Yes      | Unique identifier for the slm. |

**Request Body (JSON):**

```json
{
  "query": "Your query here"
}
```

### \[POST] /api/v1/slm/{handle\_name}/session/create/

**Description:** Creates a new session and returns a unique session ID for further interaction with SLM.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

| Parameter     | Type   | Required | Description                    |
| ------------- | ------ | -------- | ------------------------------ |
| `handle_name` | string | Yes      | Unique identifier for the slm. |

**Respponse Body (JSON):**

```json
"1234567891234"
```

### \[POST] /api/v1/slm/{handle\_name}/session/{slm\_session\_id}/chat/

**Description:** Sends a query to SLM within a specific session, receiving a response while maintaining session history.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

<table><thead><tr><th width="195">Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>handle_name</code></td><td>string</td><td>Yes</td><td>Unique identifier for the slm.</td></tr><tr><td><code>slm_session_id</code></td><td>string</td><td>Yes</td><td>Unique session identifier.</td></tr></tbody></table>

**Request Body (JSON):**

```json
{
  "query": "Your query here"
}
```

### \[POST] /api/v1/slm/{handle\_name}/session/{slm\_session\_id}/chat/stream/

**Description:** Sends a query to SLM within a specific session and retrieves a streaming response (via SSE), while maintaining session history for context during the interaction.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

<table><thead><tr><th width="197">Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>handle_name</code></td><td>string</td><td>Yes</td><td>Unique identifier for the SLM.</td></tr><tr><td><code>slm_session_id</code></td><td>string</td><td>Yes</td><td>Unique session identifier.</td></tr></tbody></table>

**Request Body (JSON):**

```json
{
  "query": "Your query here"
}
```

### \[GET] /api/v1/slm/{handle\_name}/session/list/

**Description:** Retrieves a list of all active sessions associated with the given handle name.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

<table><thead><tr><th width="208">Parameter</th><th width="121">Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>handle_name</code></td><td>string</td><td>Yes</td><td>Unique identifier for the SLM.</td></tr><tr><td><code>slm_session_id</code></td><td>string</td><td>Yes</td><td>Unique session identifier.</td></tr></tbody></table>

### \[GET] /api/v1/slm/{handle\_name}/session/{slm\_session\_id}/history/

**Description:** Retrieves the conversation history for a specific session, providing context for the ongoing interactions.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

<table><thead><tr><th width="197">Parameter</th><th width="136">Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>handle_name</code></td><td>string</td><td>Yes</td><td>Unique identifier for the SLM.</td></tr><tr><td><code>slm_session_id</code></td><td>string</td><td>Yes</td><td>Unique session identifier.</td></tr></tbody></table>

### \[DELETE] /api/v1/slm/{handle\_name}/session/{slm\_session\_id}/

**Description:** Deletes an active session identified by the provided session ID, ending any ongoing session-interactions with SLM.

**Headers:**

| Header      | Required | Example Value | Description                 |
| ----------- | -------- | ------------- | --------------------------- |
| `X-Api-Key` | Yes      | `your_token`  | API Key for authentication. |

**Path Parameters:**

<table><thead><tr><th width="215">Parameter</th><th>Type</th><th>Required</th><th>Description</th></tr></thead><tbody><tr><td><code>handle_name</code></td><td>string</td><td>Yes</td><td>Unique identifier for the SLM.</td></tr><tr><td><code>slm_session_id</code></td><td>string</td><td>Yes</td><td>Unique session identifier.</td></tr></tbody></table>

## Example

To obtain your personal token, follow these steps:

1. **Navigate to the AI Lab page**:
   * Go to the AI Lab page.
2. **Click on API button**
   * Click on API Button to obtain your personal token

<figure><img src="/files/8wiGygn4fwchlpmugfo9" alt=""><figcaption><p>API Button</p></figcaption></figure>

3. **Copy your personal token by clicking copy button**

<figure><img src="/files/XeKQpmjHozlQegUXlwsi" alt=""><figcaption><p>Token</p></figcaption></figure>

To obtain the `handle_name`, follow these steps:

1. **Navigate to the SLM page**:
   * Go to the SLM page.
2. **Extract `handle_name`**:
   * Inside the URL, you will find a parameter called `handle_name`.

<figure><img src="/files/mJyXBkuCMqyewyQtqxJW" alt=""><figcaption><p>Handle name</p></figcaption></figure>

### Send a query

Sends a question to Solana Assistant API to get a response.

Example curl

```
curl -X POST "https://api.assisterr.ai/api/v1/slm/solana_assistant/chat/" \
-H "X-Api-Key: <your-token>" \
-H "Content-Type: application/json" \
-d '{
  "query": "What is Solana?"
}'
```

### Create a session

Starts a new session with the Solana Assistant API for tracking conversation.

Example curl

```
curl -X POST "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/create/" \
-H "X-Api-Key: <your-token>" \
-H "Content-Type: application/json"
```

### Send a query using sessions

Sends a query to an active session, maintaining conversation context.

Example curl

```
curl -X POST "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/1234567891234/chat/" 
-H "X-Api-Key: <your-token>" 
-H "Content-Type: application/json" -d '{
  "query": "What is Solana?"
}'
```

Response

```json
{
    "message":"Solana is a blockchain built for mass adoption. It's a high-performance network that is utilized for a range of use cases, including finance, NFTs, payments, and gaming. Solana operates as a single global state machine and is open, interoperable and decentralized.\n\nYou can learn more about Solana from the official Solana documentation: https://docs.solana.com/",
    "message_at":"2024-12-11T19:01:16.972013",
    "is_user":false
}
```

Example curl

```
curl -X POST "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/1234567891234/chat/" 
-H "X-Api-Key: <your-token>" 
-H "Content-Type: application/json" -d '{
  "query": "What was my first question?"
}'
```

Response

```json
{
    "message":"Your first question was \"What is Solana?\"",
    "message_at":"2024-12-11T19:02:18.205151",
    "is_user":false
}
```

### Retrieve list of sessions

Fetches all active sessions for the Solana Assistant.

Example curl

```
curl -X GET "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/list/" 
-H "X-Api-Key: <your-token>" 
-H "Content-Type: application/json"
```

Response

```json
[
    {
        "_id":"session_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"uid",
        "description":"What is Solana?",
        "is_deleted":false,
        "created_at":"2024-12-11T19:00:52.124000",
        "updated_at":"2024-12-11T19:02:18.192000"
    },
    {
        "_id":"session_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"uid",
        "description":"What is Solana?",
        "is_deleted":false,
        "created_at":"2024-12-11T18:32:31.929000",
        "updated_at":"2024-12-11T18:45:03.513000"
    }
]
```

### Retrieve history

Retrieves the history of interactions for a specific session.

Example curl

```
curl -X GET "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/1234567891234/history/" 
-H "X-Api-Key: <your-token>" 
-H "Content-Type: application/json"
```

Response

```json
[
    {
        "_id":"message_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"user_id",
        "is_user":false,
        "slm_session_id":"slm_session_id",
        "ident":"private_api",
        "source":"web",
        "query":"Your first question was \"What is Solana?\"",
        "created_at":"2024-12-11T19:02:18.198000"
    },
    {
        "_id":"message_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"user_id",
        "is_user":true,
        "slm_session_id":"slm_session_id",
        "ident":"public_api",
        "source":"web",
        "query":"What was my first question?",
        "created_at":"2024-12-11T19:02:18.185000"
    },
    {
        "_id":"message_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"user_id",
        "is_user":false,
        "slm_session_id":"slm_session_id",
        "ident":"private_api",
        "source":"web",
        "query":"Solana is a blockchain built for mass adoption. It's a high-performance network that is utilized for a range of use cases, including finance, NFTs, payments, and gaming. Solana operates as a single global state machine and is open, interoperable and decentralized.\n\nYou can learn more about Solana from the official Solana documentation: https://docs.solana.com/",
        "created_at":"2024-12-11T19:01:16.967000"
    },
    {
        "_id":"message_id",
        "slm_agent_id":"slm_agent_id",
        "uid":"user_id",
        "is_user":true,
        "slm_session_id":"slm_session_id",
        "ident":"public_api",
        "source":"web",
        "query":"What is Solana?",
        "created_at":"2024-12-11T19:01:16.957000"
    }
]
```

### Delete session

Deletes an existing session with the Solana Assistant API.

Example curl

```
curl -X DELETE "https://api.assisterr.ai/api/v1/slm/solana_assistant/session/1234567891234/" 
-H "X-Api-Key: <your-token>" 
-H "Content-Type: application/json"
```

Response

```
true
```

## Conclusion

**Assisterr SLM Integration** makes it easy for developers to use the Small Language Model in their applications. With simple API endpoints for querying, session management, and streaming responses, it provides a powerful and straightforward way to enhance app functionality.


---

# 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://assisterr.gitbook.io/assisterr/product-guides/assisterr-slm-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.
