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

# Generating Materials

> Use AI to generate study materials from topics

## Overview

The StudyFetch API allows you to generate various types of study materials using AI. You can:

* Generate outlines for structured learning
* Create comprehensive study notes
* Build topic overviews
* Generate concise summaries
* Customize content length and education level
* Organize generated materials into folders

## Generate Material

Generate study materials from a topic. This method returns immediately with the material ID while generation happens asynchronously.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const material = await client.v1.materials.generate({
    name: 'Photosynthesis Study Notes',
    topic: 'Photosynthesis in plants',
    type: 'notes',
    context: 'Focus on light and dark reactions, chloroplast structure',
    level: 'college',
    length: 'medium',
    folderId: 'folder_123abc'
  });

  console.log('Material ID:', material._id);
  console.log('Status:', material.status); // 'processing'
  ```

  ```python Python theme={null}
  material = client.v1.materials.generate(
      name="Photosynthesis Study Notes",
      topic="Photosynthesis in plants",
      type="notes",
      context="Focus on light and dark reactions, chloroplast structure",
      level="college",
      length="medium",
      folder_id="folder_123abc"
  )

  print(f"Material ID: {material._id}")
  print(f"Status: {material.status}")  # 'processing'
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.models.v1.materials.MaterialGenerateParams;
  import com.studyfetch.javasdk.models.v1.materials.GeneratedMaterialResponse;

  MaterialGenerateParams params = MaterialGenerateParams.builder()
      .name("Photosynthesis Study Notes")
      .topic("Photosynthesis in plants")
      .type(MaterialGenerateParams.Type.NOTES)
      .context("Focus on light and dark reactions, chloroplast structure")
      .level(MaterialGenerateParams.Level.COLLEGE)
      .length(MaterialGenerateParams.Length.MEDIUM)
      .folderId("folder_123abc")
      .build();

  GeneratedMaterialResponse material = client.v1().materials().generate(params);

  System.out.println("Material ID: " + material._id());
  System.out.println("Status: " + material.status()); // 'processing'

  // Access references if any were added
  if (material.references().isPresent() && !material.references().get().isEmpty()) {
      System.out.println("References:");
      for (var reference : material.references().get()) {
          System.out.println("  - " + reference.title() + ": " + reference.url().orElse(""));
      }
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Materials;
  using System;
  using System.Threading.Tasks;

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

          var material = await client.V1.Materials.Generate(new()
          {
              Name = "Photosynthesis Study Notes",
              Topic = "Photosynthesis in plants",
              Type = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Type.Notes,
              Context = "Focus on light and dark reactions, chloroplast structure",
              Level = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Level.College,
              Length = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Length.Medium,
              FolderID = "folder_123abc"
          });

          Console.WriteLine($"Material ID: {material._ID}");
          Console.WriteLine($"Status: {material.Status}"); // 'processing'
      }
  }
  ```
</CodeGroup>

### Generate Parameters

<ParamField body="name" type="string" required>
  Name for the generated material
</ParamField>

<ParamField body="topic" type="string" required>
  Topic or context to generate material from
</ParamField>

<ParamField body="type" type="string" required>
  Type of material to generate:

  * `outline` - Structured hierarchical breakdown
  * `overview` - High-level introduction to topic
  * `notes` - Detailed study notes with explanations
  * `summary` - Concise summary of key points
</ParamField>

<ParamField body="context" type="string">
  Additional context or details about the topic
</ParamField>

<ParamField body="folderId" type="string">
  Target folder ID to organize the material
</ParamField>

<ParamField body="length" type="string" default="medium">
  Length of the generated content:

  * `short` - Brief content (1-2 pages)
  * `medium` - Standard length (3-5 pages)
  * `long` - Comprehensive content (6+ pages)
</ParamField>

<ParamField body="level" type="string" default="college">
  Target education level:

  * `high_school` - Basic concepts, simpler language
  * `college` - Standard academic level
  * `professional` - Advanced, technical content
</ParamField>

### Response

```json theme={null}
{
  "_id": "material_789ghi",
  "name": "Photosynthesis Study Notes",
  "type": "notes",
  "contentType": "generated",
  "topic": "Photosynthesis in plants",
  "generationType": "notes",
  "status": "processing",
  "content": null,
  "wordCount": 0,
  "organizationId": "org_456def",
  "folderId": "folder_123abc",
  "level": "college",
  "length": "medium",
  "references": [],
  "createdAt": "2024-01-20T14:30:00Z",
  "updatedAt": "2024-01-20T14:30:00Z"
}
```

## Generate and Process Material

Generate materials and wait for processing to complete. This method polls until the material is ready or times out.

<CodeGroup>
  ```javascript JavaScript theme={null}
  const material = await client.v1.materials.generateAndProcess({
    name: 'Complete Biology Notes',
    topic: 'Cell division and mitosis',
    type: 'notes',
    level: 'college',
    length: 'long',
    pollIntervalMs: 2000,  // Check every 2 seconds
    timeoutMs: 300000      // Wait up to 5 minutes
  });

  console.log('Material ready!');
  console.log('Word count:', material.metadata);
  console.log('Content preview:', material.content.text);
  ```

  ```python Python theme={null}
  material = client.v1.materials.generate_and_process(
      name="Complete Biology Notes",
      topic="Cell division and mitosis",
      type="notes",
      level="college",
      length="long",
      poll_interval_ms=2000,  # Check every 2 seconds
      timeout_ms=300000       # Wait up to 5 minutes
  )

  print("Material ready!")
  print(f"Word count: {material.word_count}")
  print(f"Content preview: {material.content[:200]}")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.models.v1.materials.MaterialGenerateAndProcessParams;

  MaterialGenerateAndProcessParams params = 
      MaterialGenerateAndProcessParams.builder()
          .name("Complete Biology Notes")
          .topic("Cell division and mitosis")
          .type(MaterialGenerateAndProcessParams.Type.NOTES)
          .level(MaterialGenerateAndProcessParams.Level.COLLEGE)
          .length(MaterialGenerateAndProcessParams.Length.LONG)
          .pollIntervalMs(2000.0)  // Check every 2 seconds
          .timeoutMs(300000.0)     // Wait up to 5 minutes
          .build();

  GeneratedMaterialResponse material = client.v1().materials()
      .generateAndProcess(params);

  System.out.println("Material ready!");
  System.out.println("Material ID: " + material._id());
  System.out.println("Material Name: " + material.name());

  // Access references if any were added
  if (material.references().isPresent() && !material.references().get().isEmpty()) {
      System.out.println("References:");
      for (var reference : material.references().get()) {
          System.out.println("  - " + reference.title() + ": " + reference.url().orElse(""));
      }
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Materials;
  using System;
  using System.Threading.Tasks;

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

          var material = await client.V1.Materials.GenerateAndProcess(new()
          {
              Name = "Complete Biology Notes",
              Topic = "Cell division and mitosis",
              Type = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Type.Notes,
              Level = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Level.College,
              Length = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Length.Long,
              PollIntervalMs = 2000,  // Check every 2 seconds
              TimeoutMs = 300000      // Wait up to 5 minutes
          });

          Console.WriteLine("Material ready!");
          Console.WriteLine($"Material ID: {material._ID}");
          Console.WriteLine($"Material Name: {material.Name}");
      }
  }
  ```
</CodeGroup>

### Generate and Process Parameters

All parameters from `generate()` plus:

<ParamField body="pollIntervalMs" type="integer" default="2000">
  Polling interval in milliseconds to check if material is ready
</ParamField>

<ParamField body="timeoutMs" type="integer" default="300000">
  Maximum time to wait for processing in milliseconds (default: 5 minutes)
</ParamField>

### Response

```json theme={null}
{
  "_id": "material_789ghi",
  "name": "Complete Biology Notes",
  "type": "notes",
  "contentType": "generated",
  "topic": "Cell division and mitosis",
  "generationType": "notes",
  "status": "completed",
  "content": "# Cell Division and Mitosis\n\n## Introduction\n\nCell division is a fundamental process...",
  "wordCount": 2450,
  "organizationId": "org_456def",
  "folderId": null,
  "level": "college",
  "length": "long",
  "references": [],
  "createdAt": "2024-01-20T14:30:00Z",
  "updatedAt": "2024-01-20T14:31:45Z"
}
```

## Complete Workflow Example

Here's a complete example of generating and organizing study materials for a course:

<CodeGroup>
  ```javascript JavaScript theme={null}
  // 1. Create a folder for the course
  const courseFolder = await client.v1.folders.create({
    name: 'Biology 101 - Spring 2024'
  });

  // 2. Generate course outline
  const outline = await client.v1.materials.generateAndProcess({
    name: 'Biology 101 Course Outline',
    topic: 'Introduction to Biology for first-year students',
    type: 'outline',
    folderId: courseFolder._id,
    level: 'college',
    length: 'long'
  });

  console.log('Course outline generated:', outline.name);

  // 3. Generate chapter materials
  const chapters = [
    { name: 'Cell Biology', topic: 'Cell structure, organelles, and functions' },
    { name: 'Genetics', topic: 'DNA, RNA, heredity, and gene expression' },
    { name: 'Evolution', topic: 'Natural selection, speciation, and evidence' }
  ];

  const chapterMaterials = await Promise.all(
    chapters.map(chapter => 
      client.v1.materials.generate({
        name: `${chapter.name} - Study Notes`,
        topic: chapter.topic,
        type: 'notes',
        folderId: courseFolder._id,
        level: 'college',
        length: 'medium',
        context: 'Include diagrams descriptions and key terminology'
      })
    )
  );

  console.log(`Generated ${chapterMaterials.length} chapter materials`);

  // 4. Generate quick summaries for review
  const summaries = await Promise.all(
    chapters.map(chapter =>
      client.v1.materials.generateAndProcess({
        name: `${chapter.name} - Quick Review`,
        topic: chapter.topic,
        type: 'summary',
        folderId: courseFolder._id,
        level: 'college',
        length: 'short'
      })
    )
  );

  // 5. List all materials in the folder
  const allMaterials = await client.v1.materials.list({
    folderId: courseFolder._id
  });

  console.log('\nCourse materials:');
  allMaterials.materials?.forEach(material => {
    console.log(`- ${material.name} (${material.contentType})`);
  });
  ```

  ```python Python theme={null}
  # 1. Create a folder for the course
  course_folder = client.v1.folders.create(
      name="Biology 101 - Spring 2024"
  )

  # 2. Generate course outline
  outline = client.v1.materials.generate_and_process(
      name="Biology 101 Course Outline",
      topic="Introduction to Biology for first-year students",
      type="outline",
      folder_id=course_folder._id,
      level="college",
      length="long"
  )

  print(f"Course outline generated: {outline.name}")

  # 3. Generate chapter materials
  chapters = [
      {"name": "Cell Biology", "topic": "Cell structure, organelles, and functions"},
      {"name": "Genetics", "topic": "DNA, RNA, heredity, and gene expression"},
      {"name": "Evolution", "topic": "Natural selection, speciation, and evidence"}
  ]

  chapter_materials = []
  for chapter in chapters:
      material = client.v1.materials.generate(
          name=f"{chapter['name']} - Study Notes",
          topic=chapter["topic"],
          type="notes",
          folder_id=course_folder._id,
          level="college",
          length="medium",
          context="Include diagrams descriptions and key terminology"
      )
      chapter_materials.append(material)

  print(f"Generated {len(chapter_materials)} chapter materials")

  # 4. Generate quick summaries for review
  summaries = []
  for chapter in chapters:
      summary = client.v1.materials.generate_and_process(
          name=f"{chapter['name']} - Quick Review",
          topic=chapter["topic"],
          type="summary",
          folder_id=course_folder._id,
          level="college",
          length="short"
      )
      summaries.append(summary)

  # 5. List all materials in the folder
  all_materials = client.v1.materials.list(
      folder_id=course_folder._id
  )

  print("\nCourse materials:")
  for material in all_materials:
      material_type = material.generation_type or material.content_type
      print(f"- {material.name} ({material_type})")
  ```

  ```java Java theme={null}
  import com.studyfetch.javasdk.client.StudyfetchSdkClient;
  import com.studyfetch.javasdk.client.okhttp.StudyfetchSdkOkHttpClient;
  import com.studyfetch.javasdk.models.v1.materials.*;
  import com.studyfetch.javasdk.models.v1.folders.*;
  import java.util.List;
  import java.util.ArrayList;
  import java.util.Collections;

  // 1. Create a folder for the course
  FolderCreateResponse courseFolder = client.v1().folders().create(
      FolderCreateParams.builder()
          .name("Biology 101 - Spring 2024")
          .build()
  );

  // 2. Generate course outline
  MaterialGenerateAndProcessParams outlineParams = 
      MaterialGenerateAndProcessParams.builder()
          .name("Biology 101 Course Outline")
          .topic("Introduction to Biology for first-year students")
          .type(MaterialGenerateAndProcessParams.Type.OUTLINE)
          .folderId(courseFolder._id())
          .level(MaterialGenerateAndProcessParams.Level.COLLEGE)
          .length(MaterialGenerateAndProcessParams.Length.LONG)
          .build();

  GeneratedMaterialResponse outline = client.v1().materials()
      .generateAndProcess(outlineParams);

  System.out.println("Course outline generated: " + outline.name());

  // 3. Generate chapter materials
  class Chapter {
      String name;
      String topic;
      
      Chapter(String name, String topic) {
          this.name = name;
          this.topic = topic;
      }
  }

  List<Chapter> chapters = List.of(
      new Chapter("Cell Biology", "Cell structure, organelles, and functions"),
      new Chapter("Genetics", "DNA, RNA, heredity, and gene expression"),
      new Chapter("Evolution", "Natural selection, speciation, and evidence")
  );

  List<GeneratedMaterialResponse> chapterMaterials = new ArrayList<>();
  for (Chapter chapter : chapters) {
      MaterialGenerateParams params = MaterialGenerateParams.builder()
          .name(chapter.name + " - Study Notes")
          .topic(chapter.topic)
          .type(MaterialGenerateParams.Type.NOTES)
          .folderId(courseFolder._id())
          .level(MaterialGenerateParams.Level.COLLEGE)
          .length(MaterialGenerateParams.Length.MEDIUM)
          .context("Include diagrams descriptions and key terminology")
          .build();
      
      GeneratedMaterialResponse material = client.v1().materials().generate(params);
      chapterMaterials.add(material);
  }

  System.out.println("Generated " + chapterMaterials.size() + " chapter materials");

  // 4. Generate quick summaries for review
  List<GeneratedMaterialResponse> summaries = new ArrayList<>();
  for (Chapter chapter : chapters) {
      MaterialGenerateAndProcessParams summaryParams = 
          MaterialGenerateAndProcessParams.builder()
              .name(chapter.name + " - Quick Review")
              .topic(chapter.topic)
              .type(MaterialGenerateAndProcessParams.Type.SUMMARY)
              .folderId(courseFolder._id())
              .level(MaterialGenerateAndProcessParams.Level.COLLEGE)
              .length(MaterialGenerateAndProcessParams.Length.SHORT)
              .build();
      
      GeneratedMaterialResponse summary = client.v1().materials()
          .generateAndProcess(summaryParams);
      summaries.add(summary);
  }

  // 5. List all materials in the folder
  MaterialListParams listParams = MaterialListParams.builder()
      .folderId(courseFolder._id())
      .build();
  MaterialListResponse allMaterials = client.v1().materials().list(listParams);

  System.out.println("\nCourse materials:");
  for (MaterialResponse material : allMaterials.materials().orElse(Collections.emptyList())) {
      System.out.println("- " + material.name() + " (" + material.contentType() + ")");
  }
  ```

  ```csharp C# theme={null}
  using StudyfetchSDK;
  using StudyfetchSDK.Models.V1.Folders;
  using StudyfetchSDK.Models.V1.Materials;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;

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

          // 1. Create a folder for the course
          var courseFolder = await client.V1.Folders.Create(new()
          {
              Name = "Biology 101 - Spring 2024"
          });

          // 2. Generate course outline
          var outline = await client.V1.Materials.GenerateAndProcess(new()
          {
              Name = "Biology 101 Course Outline",
              Topic = "Introduction to Biology for first-year students",
              Type = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Type.Outline,
              FolderID = courseFolder._ID,
              Level = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Level.College,
              Length = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Length.Long
          });

          Console.WriteLine($"Course outline generated: {outline.Name}");

          // 3. Generate chapter materials
          var chapters = new[]
          {
              new { Name = "Cell Biology", Topic = "Cell structure, organelles, and functions" },
              new { Name = "Genetics", Topic = "DNA, RNA, heredity, and gene expression" },
              new { Name = "Evolution", Topic = "Natural selection, speciation, and evidence" }
          };

          var chapterMaterials = new List<MaterialGenerateResponse>();
          foreach (var chapter in chapters)
          {
              var material = await client.V1.Materials.Generate(new()
              {
                  Name = $"{chapter.Name} - Study Notes",
                  Topic = chapter.Topic,
                  Type = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Type.Notes,
                  FolderID = courseFolder._ID,
                  Level = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Level.College,
                  Length = StudyfetchSDK.Models.V1.Materials.MaterialGenerateParamsProperties.Length.Medium,
                  Context = "Include diagrams descriptions and key terminology"
              });
              chapterMaterials.Add(material);
          }

          Console.WriteLine($"Generated {chapterMaterials.Count} chapter materials");

          // 4. Generate quick summaries for review
          var summaries = new List<MaterialGenerateAndProcessResponse>();
          foreach (var chapter in chapters)
          {
              var summary = await client.V1.Materials.GenerateAndProcess(new()
              {
                  Name = $"{chapter.Name} - Quick Review",
                  Topic = chapter.Topic,
                  Type = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Type.Summary,
                  FolderID = courseFolder._ID,
                  Level = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Level.College,
                  Length = StudyfetchSDK.Models.V1.Materials.MaterialGenerateAndProcessParamsProperties.Length.Short
              });
              summaries.Add(summary);
          }

          // 5. List all materials in the folder
          var allMaterials = await client.V1.Materials.List(new()
          {
              FolderID = courseFolder._ID
          });

          Console.WriteLine("\nCourse materials:");
          foreach (var material in allMaterials.Materials ?? [])
          {
              Console.WriteLine($"- {material.Name} ({material.ContentType})");
          }
      }
  }
  ```
</CodeGroup>
