Skip to main content

Add Training Content

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

ParameterTypeRequiredDescription
bot_idstringYesBot ID to train
sourcestring | arrayYesTraining content (string for text/website, array for file/webpage)
typestringNotext, website, file, or webpage (default: text)

Response

Training is queued and returns status:
{
  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:
{
  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

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

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

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

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

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

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

{
  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

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

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

// 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

// 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

// 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

PlanTraining Size
Free500 KB
Starter20 MB
Pro30 MB
ScaleCustom

Complete Example

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