Quickstart Guide

Get up and running with StudyFetch in just 5 minutes. You’ll learn how to:
1

Create or Upload Material

Create text-based materials or upload files (PDFs, documents, etc.) to build your knowledge base
2

Create Component

Create an AI component (chat, flashcards, tests, etc.) that uses your materials
3

Embed Component

Generate an embed URL and add it to your website with a simple iframe

Prerequisites

Before you begin, make sure you have:
  • An API key (get one from your console)
  • Your preferred development environment set up:
    • JavaScript: Node.js 16+ installed
    • Python: Python 3.7+ installed
    • Java: Java 8+ and Maven/Gradle
Material Processing Time: When you upload or create materials, they need time to process before they can be used in components. Attempting to create a component immediately after uploading materials will fail. Always check that materials have status: 'active' before using them. The examples below include proper waiting logic.

Language-Specific Quickstart

Install the SDK

npm install @studyfetch/sdk

Initialize the Client

import StudyfetchSDK from '@studyfetch/sdk';
import fs from 'fs';
import path from 'path';

const client = new StudyfetchSDK({
  apiKey: process.env.STUDYFETCH_API_KEY,
  baseURL: 'https://studyfetchapi.com',
});

Step 1: Create or Upload Study Materials

// Option 1: Create a text-based material
const textMaterial = await client.v1.materials.create({
  content: {
    type: 'text',
    text: 'Chapter 1: Introduction to Biology\n\nBiology is the study of life...'
  },
  name: 'Biology Chapter 1 - Introduction',
  folderId: 'optional-folder-id' // Optional: organize in folders
});

// Option 2: Upload a PDF file
const fileBuffer = await fs.promises.readFile(
  path.join(process.cwd(), 'biology-textbook.pdf'),
);
const file = new File([fileBuffer], 'biology-textbook.pdf', {
  type: 'application/pdf',
});

const uploadedMaterial = await client.v1.materials.upload.uploadFile({
  file,
  name: 'Biology Textbook',
  folderId: 'optional-folder-id' // Optional: organize in folders
});

// Option 3: Upload material from a URL
const urlMaterial = await client.v1.materials.upload.uploadFromURL({
  url: 'https://example.com/biology-notes.pdf',
  name: 'Online Biology Notes',
  folderId: 'optional-folder-id' // Optional: organize in folders
});

console.log('Materials created:', {
  text: textMaterial._id,
  uploaded: uploadedMaterial._id,
  url: urlMaterial._id
});

Step 2: Create a Chat Component

Important: Materials need time to process after upload. If you create a material and immediately try to use it in a component, the component creation will fail. Always ensure materials have status: 'active' before using them. For production applications, implement a polling mechanism to check material status.
// Wait for materials to finish processing
// In production, implement proper polling with exponential backoff
let materialStatus = 'processing';
while (materialStatus !== 'active') {
  const material = await client.v1.materials.retrieve(textMaterial._id);
  materialStatus = material.status;
  if (materialStatus === 'error') {
    throw new Error('Material processing failed');
  }
  if (materialStatus === 'processing') {
    await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
  }
}

const chatComponent = await client.v1.components.create({
  name: 'Biology Study Assistant',
  type: 'chat',
  config: {
    model: 'gpt-4o-mini-2024-07-18',
    materials: [textMaterial._id, uploadedMaterial._id], // Use any material IDs
    temperature: 0.7,
    enableWebSearch: true
  }
});

console.log('Chat component created:', chatComponent._id);

Step 3: Embed the Chat Component

// Basic embed with minimal configuration
const basicEmbed = await client.v1.components.generateEmbed(chatComponent._id, {
  userId: 'student-123'
});

// Advanced embed with all available options
const advancedEmbed = await client.v1.components.generateEmbed(chatComponent._id, {
  // User tracking (optional)
  userId: 'student-123',
  groupIds: ['class-101', 'biology-spring-2024'],
  
  // Display dimensions
  width: '100%',
  height: '600px',
  
  // Chat-specific features
  features: {
    enableWebSearch: true,        // Allow users to search the web
    enableHistory: true,          // View and continue previous conversations
    enableVoice: true,           // Voice input with microphone
    enableFollowUps: true,       // AI-suggested follow-up questions
    enableComponentCreation: true, // AI can create flashcards, tests, etc.
    placeholderText: 'Ask your Biology tutor anything...'
  }
});

console.log('Basic Embed URL:', basicEmbed.embedUrl);
console.log('Advanced Embed URL:', advancedEmbed.embedUrl);

// Note: Theme and branding are configured at the organization level
// StudyFetch branding is automatically hidden for all embeds

Complete Example

import StudyfetchSDK from '@studyfetch/sdk';
import fs from 'fs';

async function createStudyAssistant() {
  const client = new StudyfetchSDK({
    apiKey: process.env.STUDYFETCH_API_KEY,
    baseURL: 'https://studyfetchapi.com',
  });

  // 1. Create or upload materials
  const materials = [];
  
  // Create text material
  const textMaterial = await client.v1.materials.create({
    content: {
      type: 'text',
      text: 'Course introduction and key concepts...'
    },
    name: 'Course Introduction'
  });
  materials.push(textMaterial._id);
  
  // Upload PDF file
  const fileBuffer = await fs.promises.readFile(
    path.join(process.cwd(), 'course-content.pdf'),
  );
  const file = new File([fileBuffer], 'course-content.pdf', {
    type: 'application/pdf',
  });
  
  const uploadedMaterial = await client.v1.materials.upload.uploadFile({
    file,
    name: 'Course Materials',
  });
  materials.push(uploadedMaterial._id);

  // IMPORTANT: Wait for materials to finish processing
  // Materials need time to process. Using them immediately will cause component creation to fail.
  for (const materialId of materials) {
    let materialStatus = 'processing';
    while (materialStatus !== 'active') {
      const material = await client.v1.materials.retrieve(materialId);
      materialStatus = material.status;
      if (materialStatus === 'error') {
        throw new Error(`Material ${materialId} processing failed`);
      }
      if (materialStatus === 'processing') {
        await new Promise(resolve => setTimeout(resolve, 2000)); // Wait 2 seconds
      }
    }
  }

  // 2. Create chat assistant
  const chatComponent = await client.v1.components.create({
    name: 'Course Assistant',
    type: 'chat',
    config: {
      model: 'gpt-4o-mini-2024-07-18',
      materials: materials,
      temperature: 0.7,
      enableWebSearch: true
    }
  });

  // 3. Generate embed URL
  const embed = await client.v1.components.generateEmbed(chatComponent._id, {
    userId: 'student-123',
    groupIds: ['course-101'],
    width: '100%',
    height: '600px',
    features: {
      enableWebSearch: true,
      enableHistory: true,
      enableVoice: true,
      enableFollowUps: true,
      enableComponentCreation: true,
      placeholderText: 'Ask me anything about the course materials...'
    }
  });

  console.log('Study assistant created!');
  console.log('Embed URL:', embed.embedUrl);
  console.log('Component ID:', chatComponent._id);
  
  return { chatComponent, embed };
}

createStudyAssistant();

Embedding Components

After creating components, embed them in your application:
<iframe
  src="YOUR_EMBED_URL"
  width="100%"
  height="600px"
  frameborder="0"
  allow="microphone"
></iframe>

What’s Next?

Now that you’ve created your first components, explore more features:

Learn More About Components

Advanced Features

  • Embedding Components - Integrate into your app
  • Analytics API - Track usage and performance (see REST API tab)

Resources

  • REST API Reference - Complete API documentation (see REST API tab)

Need Help?