> For the complete documentation index, see [llms.txt](https://docs.flock.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flock.io/flock-products/ai-marketplace/quickstart/model-api-guide.md).

# Model API guide

Model Guide for you to implement FLock model

## Pre-requirement

### Manual creation via website

* Generate API Key via [Getting started Manual creation](/flock-products/ai-marketplace/quickstart/getting-started-manual-creation.md#acquiring-the-api-key)
* Create Model via [Guideline Manual](/flock-products/ai-marketplace/quickstart/guideline-manual.md#model-customisation)

## Technology Stack

* TypeScript
* JavaScript

### API Call example

{% openapi src="/files/HzQjrXbSg6zuB7V3ac3M" path="/chat/conversational\_rag\_chat" method="post" %}
[openapi.json](https://742781353-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1RpcbvTSHzzPwOSUvgKU%2Fuploads%2Fd7duzxHXRu3ZnLBllCJP%2Fopenapi.json?alt=media\&token=3e2b3b87-7de2-4e11-9ce6-021eac3a97e2)
{% endopenapi %}

## How it Works

### Setup

#### Package installation

```bash
npm install --save axios dotenv
# or
yarn add axios dotenv
# or 
pnpm add axios dotenv
```

### `.env`

* Create an `.env` file in the root directory or in your existing env file, add the followings:

```
// Some code
FLOCK_BOT_API_KEY= "<your_wallet_address_from_api_generation>"
FLOCK_BOT_ENDPOINT="https://rag-chat-ml-backend-prod.flock.io"
```

### Step by Step guide

* Create a `flockModel.ts`
* Create a `async/await` function `flockModel` wrapping the API call
  * use `axios.post` method for request
  * We will pass two parameters
    * `question`
    * `knowledge_source_id`
  * get the response of the call
  * We chose to use `try/catch` to handle any error during the call to debug the process.

<pre class="language-tsx"><code class="lang-tsx">import axios from "axios";
import * as dotenv from "dotenv";

// Load environment variables from .env file
dotenv.config({ path: "./.env" }); // Make sure the path is correct

async function main(prompt: string) {
  console.log("Prompt:", prompt);

  try {
    // Construct the request payload
    const payload = {
      question: prompt,
      chat_history: [],
      knowledge_source_id: "&#x3C;model_id>", // replace with your model id
    };

    // Set the headers
    const headers = {
      "x-api-key": process.env.FLOCK_BOT_API_KEY, // Ensure API key is set in .env
    };

    // Send POST request using axios
<strong>    const response = await axios.post(
</strong>      `${endpoint}/chat/conversational_rag_chat`,
      payload,
      {
        headers,
      }
    );


    // Output the response data
    console.log(response.data);
  } catch (error) {
    console.error("Error:", error);
  }
}

// Example call to the main function
main("Can you figure out how to make a chatbot?");
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flock.io/flock-products/ai-marketplace/quickstart/model-api-guide.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
