Skip to content
StudyFetch API

API Documentation

Data Analyst

Overview

The Data Analyst component is an AI-powered chatbot designed specifically for educators. It provides insights into student engagement, performance metrics, and learning patterns. Educators can ask natural-language questions about their students' study habits, identify areas where students may need additional support, and receive recommendations to improve learning outcomes.

The analyst answers from your organization's StudyFetch usage data: the usage events your learners generate in embedded components. It writes and runs analysis code against that data, so answers can include calculations and charts. Materials are optional and only serve as background reference.

Use config.groupIds to limit the analyst to specific classes or cohorts. The groupIds you pass when generating an embed don't restrict what the analyst can see.

Creating a Data Analyst Component

JavaScript

import StudyfetchSDK from '@studyfetch/sdk';

const client = new StudyfetchSDK({
  apiKey: 'your-api-key',
  baseURL: 'https://studyfetchapi.com',
});

const dataAnalystComponent = await client.v1.components.create({
  name: 'Student Performance Analyst',
  type: 'data_analyst',
  config: {
    model: 'gpt-4.1-2025-04-14',
    groupIds: ['class-101', 'class-102'], // Only analyze these classes
    materials: ['mat-123'],               // Optional reference material
    enableWebSearch: false,
    maxSteps: 5,
  },
});

console.log('Data Analyst component created:', dataAnalystComponent._id, dataAnalystComponent.componentId);

Python

from studyfetch_sdk import StudyfetchSDK

client = StudyfetchSDK(
    api_key="your-api-key",
    base_url="https://studyfetchapi.com",
)

data_analyst_component = client.v1.components.create(
    name="Student Performance Analyst",
    type="data_analyst",
    config={
        "model": "gpt-4.1-2025-04-14",
        "group_ids": ["class-101", "class-102"],  # Only analyze these classes
        "materials": ["mat-123"],                 # Optional reference material
        "enable_web_search": False,
        "max_steps": 5,
    },
)

print(f"Data Analyst component created: {data_analyst_component.api_id} {data_analyst_component.component_id}")

Java

import com.studyfetch.javasdk.client.StudyfetchSdkClient;
import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
import com.studyfetch.javasdk.models.v1.components.ComponentResponse;
import com.studyfetch.javasdk.models.v1.components.ComponentCreateParams;
import java.util.List;

public class CreateDataAnalystComponent {
    public static void main(String[] args) {
        StudyfetchSdkClient client = StudyfetchSdkOkHttpClient.builder()
            .fromEnv()
            .baseUrl("https://studyfetchapi.com")
            .build();

        ComponentCreateParams params = ComponentCreateParams.builder()
            .name("Student Performance Analyst")
            .type(ComponentCreateParams.Type.DATA_ANALYST)
            .config(ComponentCreateParams.Config.DataAnalystConfigDto.builder()
                .model("gpt-4.1-2025-04-14")
                .groupIds(List.of("class-101", "class-102")) // Only analyze these classes
                .materials(List.of("mat-123"))               // Optional reference material
                .enableWebSearch(false)
                .maxSteps(5)
                .build())
            .build();

        ComponentResponse component = client.v1().components().create(params);
        System.out.println("Data Analyst component created: " + component._id());
    }
}

C#

using StudyfetchSDK;
using StudyfetchSDK.Models.V1.Components;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

public class CreateDataAnalystComponent
{
    public static async Task CreateDataAnalyst()
    {
        var client = new StudyfetchSDKClient()
        {
            APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
            BaseUrl = new Uri("https://studyfetchapi.com")
        };

        var dataAnalystComponent = await client.V1.Components.Create(new()
        {
            Name = "Student Performance Analyst",
            Type = StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.Type.DataAnalyst,
            Config = new StudyfetchSDK.Models.V1.Components.ComponentCreateParamsProperties.ConfigProperties.DataAnalystConfigDto()
            {
                Model = "gpt-4.1-2025-04-14",
                GroupIDs = new List<string> { "class-101", "class-102" }, // Only analyze these classes
                Materials = new List<string> { "mat-123" },               // Optional reference material
                EnableWebSearch = false,
                MaxSteps = 5,
            }
        });

        Console.WriteLine($"Data Analyst component created: {dataAnalystComponent._ID}");
    }
}

Configuration Parameters

name

string · required

Name of the data analyst component

type

string · required

Must be "data_analyst" (with an underscore)

config

object · required

Data analyst configuration object. Unknown keys are rejected with 400.

Configuration Properties

These properties go inside config.

model

string · required

Model key for analysis, such as gpt-4.1-2025-04-14 or gemini-2.5-flash. The key is checked when a question is asked, not when the component is created, so an unrecognized key makes requests fail.

groupIds

array

Group or class IDs to analyze. When set, the analyst only sees usage from learners in these groups. When omitted, it analyzes your whole organization.

materials

array

Optional material IDs the analyst can search for background, such as a syllabus or course guide

folders

array

Optional folder IDs the analyst can search for background

enableRAGSearch

boolean · default: true

Search materials and folders when answering

enableWebSearch

boolean · default: true

Allow web searches. In the embed, the educator's web search toggle decides per message; its starting state comes from features.enableWebSearch, which defaults to off.

enableComponentCreation

boolean · default: true

Allow the analyst to create study components during the conversation

maxSteps

number · default: 3

Maximum tool-call steps per answer

systemPrompt

string

Accepted and stored, but the analyst currently always uses its own built-in instructions.

temperature

number

Accepted and stored, but the analyst currently uses a fixed temperature.

maxTokens

number

Accepted and stored, but the analyst currently uses a fixed output limit.

enableHistory

boolean

Stored on the component. The embed reads this setting from the embed token; use features.enableHistory.

enableVoice

boolean

Stored on the component. Use features.enableVoice to control the embed.

enableFollowUps

boolean

Stored on the component. Use features.enableFollowUps to control the embed.

Response

{
  "_id": "6650f1c2a9b3e4d5f6a7b8c9",
  "componentId": "data_analyst_V1StGXR8_Z",
  "name": "Student Performance Analyst",
  "type": "data_analyst",
  "status": "active",
  "origin": "api",
  "organization": "64f0a1b2c3d4e5f6a7b8c9d0",
  "materials": ["mat-123"],
  "folders": [],
  "config": {
    "model": "gpt-4.1-2025-04-14",
    "groupIds": ["class-101", "class-102"],
    "materials": ["mat-123"],
    "enableWebSearch": false,
    "maxSteps": 5
  },
  "usageCount": 0,
  "createdAt": "2026-10-06T10:00:00.000Z",
  "updatedAt": "2026-10-06T10:00:00.000Z"
}

Embedding This Component

Once you've created a Data Analyst component, you can embed it on your website using the embedding API. The component must be active.

Generate Embed URL

JavaScript

const embedResponse = await client.v1.components.generateEmbed(dataAnalystComponent._id, {
  // User tracking
  userId: 'educator-456',
  studentName: 'Ms. Rivera',  // Name for display
  sessionId: 'session-789',

  // Data Analyst features
  features: {
    enableBadWordsFilter: true,  // Required by the SDK type; no effect on Data Analyst
    enableHistory: true,
    enableVoice: false,
    enableFollowUps: true,
    placeholderText: 'Ask about your students...',
  },

  // Dimensions
  width: '100%',
  height: '700px',
});

console.log(embedResponse.embedUrl);

Python

embed_response = client.v1.components.generate_embed(
    data_analyst_component.api_id,
    user_id="educator-456",
    student_name="Ms. Rivera",  # Name for display
    session_id="session-789",
    features={
        "enable_bad_words_filter": True,  # Required by the SDK type; no effect on Data Analyst
        "enable_history": True,
        "enable_voice": False,
        "enable_follow_ups": True,
        "placeholder_text": "Ask about your students...",
    },
    width="100%",
    height="700px",
)

print(embed_response.embed_url)

Java

import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedParams;
import com.studyfetch.javasdk.models.v1.components.ComponentGenerateEmbedResponse;

ComponentGenerateEmbedParams params = ComponentGenerateEmbedParams.builder()
    .id(dataAnalystComponent._id())
    // User tracking
    .userId("educator-456")
    .studentName("Ms. Rivera")  // Name for display
    .sessionId("session-789")

    // Data Analyst features
    .features(ComponentGenerateEmbedParams.Features.builder()
        .enableBadWordsFilter(true)  // Required: build() throws without it
        .enableHistory(true)
        .enableVoice(false)
        .enableFollowUps(true)
        .placeholderText("Ask about your students...")
        .build())

    // Dimensions
    .width("100%")
    .height("700px")
    .build();

ComponentGenerateEmbedResponse embedResponse = client.v1().components()
    .generateEmbed(params);

System.out.println(embedResponse.embedUrl());

C#

using StudyfetchSDK;
using StudyfetchSDK.Models.V1.Components;
using StudyfetchSDK.Models.V1.Components.ComponentGenerateEmbedParamsProperties;
using System;
using System.Threading.Tasks;

public class GenerateDataAnalystEmbed
{
    public static async Task GenerateEmbed(string dataAnalystComponentId)
    {
        var client = new StudyfetchSDKClient()
        {
            APIKey = Environment.GetEnvironmentVariable("STUDYFETCH_API_KEY"),
            BaseUrl = new Uri("https://studyfetchapi.com")
        };

        var embedResponse = await client.V1.Components.GenerateEmbed(new()
        {
            ID = dataAnalystComponentId,
            UserID = "educator-456",
            StudentName = "Ms. Rivera",  // Name for display
            SessionID = "session-789",
            Features = new Features(enableBadWordsFilter: true)
            {
                EnableHistory = true,
                EnableVoice = false,
                EnableFollowUps = true,
                PlaceholderText = "Ask about your students..."
            },
            Width = "100%",
            Height = "700px"
        });

        Console.WriteLine($"Embed URL: {embedResponse.EmbedURL}");
        Console.WriteLine($"Token: {embedResponse.Token}");
    }
}

The response contains embedUrl, token, expiresAt, componentId (the component's _id), componentType, and options (width and height, defaulting to 100% and 600px).

Data Analyst-Specific Embedding Features

features.enableHistory

boolean · default: true

Show past conversations and let educators continue them. History is stored per userId.

features.enableVoice

boolean · default: true

Enable voice input. Your iframe needs allow="microphone".

features.enableFollowUps

boolean · default: true

Show suggested follow-up questions after answers

features.enableWebSearch

boolean · default: false

Starting state of the web search toggle

features.enableComponentCreation

boolean · default: true

Allow creating study components from the conversation

features.enableReferenceMode

boolean · default: false

Show reference titles and URLs instead of source content in citations

features.placeholderText

string · default: Ask your AI Assistant about anything

Placeholder text for the input

Embed in Your HTML

Use the embedUrl from the response as the iframe source. The host can differ per organization, so don't build the URL yourself.

<iframe
  src="EMBED_URL_FROM_RESPONSE"
  width="100%"
  height="700px"
  frameborder="0"
  allow="microphone; clipboard-write"
  style="border: 1px solid #e5e5e5; border-radius: 8px;">
</iframe>

The React Native SDK does not include a Data Analyst component; use the iframe embed.