> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Basic Bot Example

> Build a simple AI agent from scratch

## Overview

Create a basic AI agent using the BoostGPT Core SDK in under 5 minutes.

## Prerequisites

```bash theme={null}
npm install boostgpt
```

## Complete Example

```javascript theme={null}
import { BoostGPT } from 'boostgpt';

// Initialize client
const client = new BoostGPT({
  key: process.env.BOOSTGPT_API_KEY,
  project_id: process.env.BOOSTGPT_PROJECT_ID
});

async function main() {
  // 1. Create a bot
  console.log('Creating bot...');
  const botResult = await client.createBot({
    name: 'Customer Support Assistant',
    model: 'gpt-5.6-luna',
    instruction: 'You are a helpful customer support agent. Be friendly and concise.'
  });

  if (botResult.err) {
    console.error('Error creating bot:', botResult.err);
    return;
  }

  const botId = botResult.response.id;
  console.log('Bot created:', botId);

  // 2. Add training data
  console.log('\nAdding training data...');
  const trainingResult = await client.startTraining({
    bot_id: botId,
    type: 'text',
    source: `
      Q: What are your business hours?
      A: We're open Monday-Friday, 9am-5pm EST.

      Q: How do I reset my password?
      A: Click "Forgot Password" on the login page and follow the instructions.

      Q: What's your return policy?
      A: We accept returns within 30 days of purchase.
    `
  });

  if (trainingResult.err) {
    console.error('Error adding training:', trainingResult.err);
    return;
  }

  console.log('Training queued:', trainingResult.response.id);

  // Wait for training to process
  console.log('Waiting for training to complete...');
  await new Promise(resolve => setTimeout(resolve, 3000));

  // 3. Chat with bot
  console.log('\nTesting bot...');
  const chatResult = await client.chat({
    bot_id: botId,
    message: 'What are your business hours?',
    chat_id: 'user-123'
  });

  if (chatResult.err) {
    console.error('Error chatting:', chatResult.err);
    return;
  }

  console.log('Bot response:', chatResult.response);
}

main();
```

## Step-by-Step Breakdown

### 1. Initialize Client

```javascript theme={null}
import { BoostGPT } from 'boostgpt';

const client = new BoostGPT({
  key: process.env.BOOSTGPT_API_KEY,
  project_id: process.env.BOOSTGPT_PROJECT_ID
});
```

Get your API key from: **Dashboard -> Settings -> API Keys**

### 2. Create Bot

```javascript theme={null}
const botResult = await client.createBot({
  name: 'Customer Support Assistant',
  model: 'gpt-5.6-luna',
  instruction: 'You are a helpful customer support agent.'
});

const botId = botResult.response.id;
```

### 3. Add Training Data

```javascript theme={null}
await client.startTraining({
  bot_id: botId,
  type: 'text',
  source: 'Your training content here...'
});
```

### 4. Chat with Bot

```javascript theme={null}
const chatResult = await client.chat({
  bot_id: botId,
  message: 'User question',
  chat_id: 'user-123'
});

console.log(chatResult.response);
```

## Running the Example

```bash theme={null}
# Set API key
export BOOSTGPT_API_KEY=your_api_key

# Run
node basic-bot.js
```

**Output:**

```text theme={null}
Creating bot...
Bot created: bot_abc123

Adding training data...
Training queued: source_xyz789
Waiting for training to complete...

Testing bot...
Bot response: We're open Monday-Friday, 9am-5pm EST.
```

## Adding More Features

### Stream Responses

```javascript theme={null}
const chatResult = await client.chat({
  bot_id: botId,
  message: 'Tell me about your services',
  stream: true
});

// Handle streaming
for await (const chunk of chatResult.response) {
  process.stdout.write(chunk);
}
```

### Multiple Training Sources

```javascript theme={null}
// Add FAQ
await client.startTraining({
  bot_id: botId,
  type: 'text',
  source: 'FAQ content...'
});

// Add from website
await client.startTraining({
  bot_id: botId,
  type: 'website',
  source: 'https://example.com'
});

// Add files
await client.startTraining({
  bot_id: botId,
  type: 'file',
  source: ['manual.pdf', 'guide.docx']
});
```

### Custom Model Settings

```javascript theme={null}
const chatResult = await client.chat({
  bot_id: botId,
  message: 'Question',
  model: 'gpt-5.6-luna',  // Override model
  max_reply_tokens: 500,   // Limit response length
  reasoning_mode: 'agent'  // Autonomous multi-step reasoning
});
```

## Error Handling

Always handle errors:

```javascript theme={null}
const result = await client.createBot({
  name: 'My Bot',
  model: 'gpt-5.6-luna'
});

if (result.err) {
  console.error('Error:', result.err);
  // Handle error
  return;
}

// Use result.response
const botId = result.response.id;
```

## Next Steps

> [card] [Multi-Channel Bot](/docs/examples/multi-channel.md)
>
> Deploy bot to multiple platforms

> [card] [With Integrations](/docs/examples/with-integrations.md)
>
> Add custom tools and integrations

> [card] [SDK Reference](/docs/sdk/core/overview.md)
>
> Full SDK documentation

> [card] [API Reference](/docs/api-reference/introduction.md)
>
> REST API documentation


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.