Edu SDKEdu SDK

Error handling

InvalidInputError, content extraction errors, and what the SDK does not wrap.

edu-sdk validates options with Zod before calling the model. Bad options throw InvalidInputError, which extends EduSDKError.

File extraction failures throw UnsupportedContentError (unknown type) or ContentExtractionError (empty / unreadable file). Both also extend EduSDKError.

import {
  createQuiz,
  InvalidInputError,
  UnsupportedContentError,
  ContentExtractionError,
} from "edu-sdk";

try {
  const quiz = await createQuiz({
    model: "google/gemini-3.6-flash",
    content,
    count: 10,
  });
} catch (error) {
  if (error instanceof InvalidInputError) {
    // Empty content, count of 0, invalid difficulty, numOfOptions < 2, ...
    console.error(error.message);
  } else if (
    error instanceof UnsupportedContentError ||
    error instanceof ContentExtractionError
  ) {
    console.error(error.message);
  } else {
    throw error;
  }
}

Invalid input examples

  • empty content
  • count of 0 or a non-integer
  • difficulty other than "easy" | "medium" | "hard"
  • numOfOptions less than 2
  • duplicate types in createLearningSet include

Study sessions

createStudySession() also throws InvalidInputError when:

  • durationMinutes is outside 5–240
  • block durations sum to a value more than ±5 minutes from durationMinutes
  • a block’s materialKey references a material that was not allocated
  • the plan has no blocks
  • every block is a break
  • normalizing durations would make a block shorter than 1 minute

Content extraction errors

ErrorWhen
UnsupportedContentErrorUnknown MIME and no usable filename extension
ContentExtractionErrorEmpty bytes, empty extracted text, or unscannable PDF

What the SDK does not wrap

Model, network, rate-limit, and generation failures come from the AI SDK. They are not wrapped in EduSDKError. See Models & providers.

On this page