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

# Training Data

> Add knowledge and context to your bots

## Add Training Content

```javascript theme={null}
const result = await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'Our company offers 24/7 customer support at support@example.com',
  type: 'text'
});

if (result.err) {
  console.error('Error:', result.err);
} else {
  console.log('Training added:', result.response.id);
}
```

### Parameters

| Parameter | Type            | Required | Description                                                                |
| --------- | --------------- | -------- | -------------------------------------------------------------------------- |
| `bot_id`  | string          | Yes      | Bot ID to train                                                            |
| `source`  | string \| array | Yes      | Training content (string for `text`/`website`, array for `file`/`webpage`) |
| `type`    | string          | No       | `text`, `website`, `file`, or `webpage` (default: `text`)                  |

### Response

Training is queued and returns status:

```javascript theme={null}
{
  err: null,
  response: {
    id: 'source_xyz789',
    bot_id: 'bot_abc123',
    source: 'Our company offers 24/7 customer support...',
    type: 'text',
    status: 'processing', // 'processing', 'success', or 'failed'
    tokens: 150,
    created_at: '2025-01-01T12:00:00Z'
  }
}
```

For `file`, `website`, and `webpage` types, an additional `links` field is included:

```javascript theme={null}
{
  err: null,
  response: {
    id: 'source_xyz789',
    bot_id: 'bot_abc123',
    source: ['https://example.com/page1', 'https://example.com/page2'],
    type: 'webpage',
    status: 'processing',
    tokens: 0, // Populated after processing
    links: ['https://example.com/page1', 'https://example.com/page2'],
    created_at: '2025-01-01T12:00:00Z'
  }
}
```

## Training from Text

```javascript theme={null}
const result = await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'We are open Monday-Friday 9am-5pm EST',
  type: 'text'
});

console.log('Status:', result.response.status); // 'processing'
console.log('Tokens:', result.response.tokens);
```

## Training from Website

```javascript theme={null}
const result = await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'https://example.com',
  type: 'website'
});

console.log('Status:', result.response.status); // 'processing'
console.log('Links:', result.response.links); // Crawled pages
```

## Training from Files

```javascript theme={null}
const result = await client.startTraining({
  bot_id: 'bot_abc123',
  source: ['file1.pdf', 'file2.docx'],
  type: 'file'
});

console.log('Status:', result.response.status); // 'processing'
console.log('Links:', result.response.links);
```

## Training from Webpages

```javascript theme={null}
const result = await client.startTraining({
  bot_id: 'bot_abc123',
  source: [
    'https://example.com/page1',
    'https://example.com/page2',
    'https://example.com/page3'
  ],
  type: 'webpage'
});

console.log('Status:', result.response.status); // 'processing'
console.log('Links:', result.response.links);
```

## Get Training Item

```javascript theme={null}
const result = await client.fetchTraining({
  bot_id: 'bot_abc123',
  source_id: 'source_xyz789'
});

if (result.err) {
  console.error('Error:', result.err);
} else {
  console.log('Training item:', result.response);
}
```

## List All Training Data

```javascript theme={null}
const result = await client.fetchTrainings({
  bot_id: 'bot_abc123',
  page: 1,
  per_page: 10
});

if (result.err) {
  console.error('Error:', result.err);
} else {
  console.log('Training items:', result.response);
}
```

### Response

```javascript theme={null}
{
  err: null,
  response: [
    {
      id: 'training_1',
      content: 'We offer 24/7 support',
      created_at: '2025-01-01T12:00:00Z'
    },
    {
      id: 'training_2',
      content: 'Free shipping on orders over $50',
      created_at: '2025-01-01T12:05:00Z'
    }
  ]
}
```

## Update Training Data

```javascript theme={null}
const result = await client.updateTraining({
  bot_id: 'bot_abc123',
  source_id: 'source_xyz789',
  source: 'Updated content here',
  type: 'text'
});

if (result.err) {
  console.error('Error:', result.err);
} else {
  console.log('Status:', result.response.status); // 'processing'
  console.log('Tokens:', result.response.tokens);
}
```

Update returns the same format as `startTraining`, including status, tokens, and links (for `file`, `website`, `webpage` types).

## Delete Training Data

```javascript theme={null}
const result = await client.deleteTraining({
  bot_id: 'bot_abc123',
  source_id: 'source_xyz789'
});

if (result.err) {
  console.error('Error:', result.err);
} else {
  console.log('Training deleted successfully');
}
```

## Best Practices

### 1. Choose the Right Type

```javascript theme={null}
// Text content
await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'Returns are accepted within 30 days of purchase',
  type: 'text'
});

// Website (crawls entire site)
await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'https://docs.example.com',
  type: 'website'
});

// Specific webpages (array of URLs)
await client.startTraining({
  bot_id: 'bot_abc123',
  source: ['https://example.com/faq', 'https://example.com/pricing'],
  type: 'webpage'
});

// Files (PDFs, DOCX, etc.)
await client.startTraining({
  bot_id: 'bot_abc123',
  source: ['manual.pdf', 'guide.docx'],
  type: 'file'
});
```

### 2. Check Training Status

```javascript theme={null}
// Start training
const training = await client.startTraining({
  bot_id: 'bot_abc123',
  source: 'https://example.com',
  type: 'website'
});

// Check status later
const status = await client.fetchTraining({
  bot_id: 'bot_abc123',
  source_id: training.response.id
});

if (status.response.status === 'success') {
  console.log('Training completed!');
  console.log('Total tokens:', status.response.tokens);
  console.log('Pages crawled:', status.response.links.length);
} else if (status.response.status === 'failed') {
  console.error('Training failed');
}
```

### 3. Monitor Token Usage

```javascript theme={null}
// Fetch all training to see token usage
const trainings = await client.fetchTrainings({
  bot_id: 'bot_abc123',
  page: 1,
  per_page: 100
});

const totalTokens = trainings.response.reduce((sum, item) => {
  return sum + (item.tokens || 0);
}, 0);

console.log('Total tokens used:', totalTokens);
```

## Training Limits by Plan

| Plan        | Training Size |
| ----------- | ------------- |
| **Free**    | 500 KB        |
| **Starter** | 20 MB         |
| **Pro**     | 30 MB         |
| **Scale**   | Custom        |

## Complete Example

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

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

async function setupBot() {
  // Create bot
  const bot = await client.createBot({
    name: 'Support Bot',
    model: 'gpt-5-mini',
    instruction: 'You are a helpful support assistant.'
  });

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

  // Add training data
  const trainingContent = [
    'Company name: TechCorp',
    'Support email: support@techcorp.com',
    'Business hours: Mon-Fri 9am-5pm EST',
    'Phone: (555) 123-4567',
    'Returns accepted within 30 days',
    'Free shipping on orders over $50'
  ];

  for (const source of trainingContent) {
    await client.startTraining({
      bot_id: bot.response.id,
      source,
      type: 'text'
    });
  }

  console.log('Bot trained successfully!');

  // Test the bot
  const response = await client.chat({
    bot_id: bot.response.id,
    message: 'What are your business hours?'
  });

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

setupBot();
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Chat API" icon="messages" href="/sdk/core/chat-api">
    Chat with your trained bot
  </Card>

  <Card title="API Reference" icon="code" href="/sdk/core/api-reference">
    Complete API documentation
  </Card>
</CardGroup>
