Examplary
Start for free
Developer docs
Embed sessions

Question generation flow

Using the Examplary question generation flow, you can let users of your application use AI to generate a single question on a specific subject or a set of source materials.

Presets

Presets allow you to pre-configure certain options for the embed session, so that when your users open the embed, they see a tailored experience. Every key within presets is optional, but the presets object itself is required — pass "presets": {} if you don't want to pre-configure anything.

KeyTypeDescription
subjectstringThe subject of the question. Plain text.
studentLevelstringThe difficulty level of the question. Expects a student level ID from /student-levels.
languagestringThe language code for the question (e.g. "en" for English). Defaults to the user's locale.
contextstringAdditional context or instructions for the question generation. Plain text.
sourceMaterialIdsstring[]An array of source material IDs to pre-select for the question.
questionTypestringSpecify the ID of a question type to generate. Will hide the question type selector in the UI.
hideSubjectbooleanWhether to hide the subject field in the question generation UI. Defaults to false.
hideStudentLevelbooleanWhether to hide the student level field in the question generation UI. Defaults to false.
outputFormatstringSpecify the output format for the generated question. Can be either examplary_json, qti_v2p1, qti_v3p0. Defaults to examplary_json. When set to a QTI format, outputs.question will be an XML string instead of a JSON object.

Example

1. Create an Examplary user for your user

To make sure we can save personal preferences and source materials uploaded by the user to their specific account, and can later allow them to reference these personal details, we require creating a user account in your workspace for each of your users.

POST/users
{
  "email": "my-user@example.com",
  "name": "My User"
}

Store the returned user ID in your system to use with any future embed sessions for that user.

2. Create an embed session

Call the Examplary API to create a new embed session. You can configure presets for the question, as well as theme options.

The actor field should contain the ID of the Examplary user account you created for this customer.

You can either specify a returnUrl or an allowedOrigin, based on how you want to be notified when generation is completed.

POST/embed-sessions
{
  "flow": "generate-question",
  "actor": "{userId}",
  "presets": {
    "subject": "Mathematics"
  },
  "theme": {
    "primaryColor": "#4f46e5",
    "locale": "en"
  },
  "metadata": {
    "myUniqueIdentifier": "abc1234"
  },
  "returnUrl": "https://app.example.com",
  "allowedOrigin": "https://app.example.com"
}

The response is the new embed session. Two of its fields matter for the next steps: embedUrl, the page to show your user, which stays valid until the session's expiresAt, and id, to look up the session later.

3. Lead the user to the embed URL

You can either redirect the user directly to the URL, or display it in an iframe.

The latter might be better for the user experience, especially when displayed as a modal. This also allows you to listen to status updates in real time, through the postMessage() API.

const embedUrl = "https://app.examplary.ai/embeds/55S843D7HfNf...";
 
iframe.src = embedUrl;
 
window.addEventListener("message", (event) => {
  // Make sure the message is coming from a trusted origin
  if (event.origin !== new URL(embedUrl).origin) return;
 
  // Handle the message
  const { type, status, outputs } = event.data;
  if (type === "examplary:embed-status-update") {
    if (status === "completed") {
      const question = outputs.question;
      console.log("Question generation completed! Question:", question);
    }
  }
});

If you're using redirects, you can expect a redirect to your specified returnUrl on success, with the embed session ID folded into the query string: ?status=completed&embedId=embed_session_55S8...&question=...

If neither of these options work for you, you may also poll the Examplary API for status updates:

GET /embed-sessions/{id}
{
  "id": "embed_session_55S843D7HfNfs9RY48PoTprXnRcz2...",
  "flow": "generate-question",
  "status": "completed",
  "createdBy": "user_9pQr82jXd0dJ...",
  "outputs": {
    "question": "..."
  }
  // ...other embed session fields omitted
}

outputs.question is a JSON object when using the default examplary_json format, or an XML string when using qti_v2p1 or qti_v3p0.

4. Cleanup

The embed session will expire automatically after 7 days, but because it gives some limited access to your account, you might want to remove it manually:

DELETE /embed-sessions/{embedSessionId}