AI

Generate questions

Generates practice questions on a topic, using the school daily AI allowance.

POSThttps://api.klasstack.com/v1/ai/questions/generate

  • ai:write
  • Billable
  • Idempotency-Key required
  • Test key: example response

Authorizations

  • Authorizationstringheaderrequired

    Your secret key as a bearer token, in the form Bearer ks_live_sk_... or Bearer ks_test_sk_.... Keep it on your server. A test key gets the documented example and touches no school data.

Headers

  • idempotency-keystringheaderrequired

    A key of your own that makes this write safe to retry: the same key returns the first response instead of writing again.

Body

application/json

  • countinteger

  • topicstring

  • subjectstring

  • difficultystring

  • gradeLevelstring

  • questionTypesstring[]

  • questionBankIdinteger

Response

200, application/json

  • dataobjectrequired

    Show child attributes
    • questionBankIdnumberrequired

    • questionsobject[]required

      Show child attributes of each item
      • questionTypestringrequired

      • promptstringrequired

      • pointsnumberrequired

      • optionsarray or nullrequired

      • correctOptionIdsarray or nullrequired

      • correctTextobject or nullrequired

        Show child attributes
        • matchstringrequired

        • valuestringrequired

      • markingGuideobject or nullrequired

        Show child attributes
        • modelAnswerstring or nullrequired

        • keyPointsobject[]required

          Show child attributes of each item
          • pointstringrequired

          • marksnumberrequired

      • keyConfidencestringrequired

    • skippednumberrequired

      Drafts the model returned that failed validation.

  • metaobjectrequired

    Show child attributes
    • request_idstringrequired

      Also returned in the X-Request-ID header.

    • paginationobject

      Show child attributes
      • limitintegerrequired

        Required range: x <= 100

      • has_morebooleanrequired

      • next_cursorstring or nullrequired

        Send this back as cursor for the next page. Opaque: never parse it.

Errors

  • 400invalid_parameterA request parameter is invalid; `field` names it. A write sent without an Idempotency-Key is refused this way with `field` set to `Idempotency-Key`.
  • 401invalid_api_keyNo key was presented, or the key is not valid.
  • 402insufficient_balanceThe school's service wallet cannot cover this call.
  • 403insufficient_scopeThe app does not hold the scope this endpoint needs.
  • 404endpoint_not_exposedThis endpoint is not part of the API.
  • 422ai_output_emptyThe model answered but nothing usable came back. Nothing was saved; retry or adjust the brief.
  • 422ai_generation_failedThe generation ran and ended in an error. Nothing was saved; retry later.
  • 429rate_limitedThe rate limit was reached. Retry after the Retry-After header says.
  • 429ai_budget_exhaustedThe school's shared daily AI allowance is used up. Retry-After is the seconds until it resets.
  • 429ai_generation_in_progressThis app already has the maximum number of AI generations running. Retry after Retry-After.
  • 503platform_unavailableThe API is not available for this school right now.

What each code means, and what to do about it, is in the errors guide.

Webhook events

This call triggers no webhook event.