Skip to content
UneeqUneeqUneeq Docs

Generate a role-play scenario with AI

POST
/external/v1/organization/{organizationID}/immersive-training/generate
curl --request POST \
--url "$UNEEQ_API_URL/external/v1/organization/$UNEEQ_ORG_ID/immersive-training/generate" \
--header "Authorization: Bearer $UNEEQ_API_KEY" \
--header "Content-Type: application/json" \
--data '{
"learning_domain_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"scenario_context": "A long-standing customer is unhappy that their renewal price has gone up by 12%. They are considering a competitor and want the account manager to justify the increase or offer a discount.",
"documentation_text": "Renewal policy: price increases above 10% require a value review. Account managers may offer up to 5% loyalty discount on multi-year renewals.",
"scenario_name": "Renewal price objection",
"locales": "en-US",
"time_limit_minutes": 15,
"is_published": true,
"tags": [
"7c9e6679-7425-40de-944b-e07fc1f90ae7"
]
}'

Runs the whole “Generate with AI” authoring wizard in one call and saves the result as a role-play scenario. You describe the situation in scenario_context (and optionally paste reference material into documentation_text); the platform writes the character, the system prompt, participant instructions, a scenario name and a set of assessments.

Two modes, chosen by user_email alone:

  • Org-wide role play (user_email omitted or empty): a ROLE_PLAY scenario in the organization library. is_published, tags and endorsement_threshold apply.
  • Private practice scenario (user_email set): a PRACTICE scenario owned by that member and visible only to them. The member must be an active member of the organization, and the organization must have practice mode enabled (otherwise 400 “practice mode is not enabled for this organization”). Practice scenarios are always published and cannot carry tags or an endorsement threshold: sending a non-empty tags, any endorsement_threshold or is_published: true with user_email is rejected with 400.

What gets generated and saved:

  • The scenario name is scenario_name when it is not blank (trimmed; longer than 255 characters is rejected with 400), otherwise the generated title, shortened at a word boundary to at most 255 characters.
  • When persona_config_id is omitted, a digital human available to the organization is picked to match the generated character’s gender; if none matches, any available one is used.
  • The generated assessments are created in the organization’s shared assessment library and attached to the scenario as active, unweighted assessments.
  • A non-empty documentation_text is attached to the scenario as a supporting document named scenario-documentation.txt; if it is too long for the model it is summarized before generation.
  • The generator never asks follow-up questions. If it cannot produce a complete scenario from the brief, the call fails with 500 and asks for more detail in scenario_context.

Timing and cost: the call runs several AI model requests (two stages of two parallel requests, then a prompt summary, plus summarization requests when documentation_text is too long for the model) and holds the connection until the scenario is saved, which typically takes tens of seconds. There is no server-side deadline beyond each model request’s own timeout, so use a generous client timeout. Every call is billed AI usage; a request rejected by validation (any 4xx before generation starts) makes no model call. Repeating a call creates another scenario; the endpoint is not idempotent. The supporting document is saved after the scenario itself, so a 500 “unable to create immersive training” can leave the scenario saved without its scenario-documentation.txt; list the scenarios before retrying.

After the response, speech-recognition hints and runtime configuration for the scenario are prepared in the background.

The response carries only the new scenario’s id and a link that starts its role play; read the scenario through the get endpoint (an org-wide one; practice scenarios are not readable through the API).

For a private practice scenario the returned link opens only for the owning member, and the scenario cannot be read or deleted through the API afterwards, so keep the returned id if you need it. Generated assessments are added to the shared assessment library on every call without being matched against existing entries, so repeated calls build up near-duplicate assessments there.

organizationID
required
string

ID of the organization the API key belongs to, for example org_HYPCX67vaupjhdTn.

Example

org_HYPCX67vaupjhdTn
Media typeapplication/json

Brief for an AI-generated scenario. user_email selects between an org-wide role play and a member’s private practice scenario.

object
user_email

Email of an active member of the organization (matched case-insensitively). When set, the scenario is that member’s private PRACTICE scenario; when omitted or empty, an org-wide ROLE_PLAY scenario.

string format: email
<= 254 characters
learning_domain_id
required

Learning domain of the organization the scenario belongs to; its guidance shapes the generated prompt. Must be a lowercase UUID.

string format: uuid
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
scenario_context
required

The situation to role-play, in plain language. The generator invents anything it leaves out.

string
>= 1 characters <= 50000 characters
documentation_text

Optional reference material (policies, product facts). Summarized if too long for the model, and attached to the scenario as a supporting document.

string
<= 50000 characters
persona_config_id

Digital human to use. Omit to have one picked from those available to the organization. Must be a lowercase UUID.

string format: uuid
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
scenario_name

Scenario name. Omit, or send only whitespace, to use the generated title. Surrounding whitespace is trimmed.

string
<= 255 characters
locales

Deprecated and ignored. Every scenario offers every supported language. Still validated, so an unsupported locale is rejected with validation_failed; omit it.

string
<= 50 characters
time_limit_minutes

Session time limit in minutes. Omit for no limit.

integer
>= 1 <= 120
is_published

Org-wide only. Publish the scenario to learners immediately. Must not be true for a practice scenario, which is always published.

boolean
tags

Org-wide only. Ids (lowercase UUIDs) of the organization’s tags to put on the scenario. An empty array is accepted for a practice scenario.

Array<string>
<= 50 items
endorsement_threshold

Org-wide only. Score a learner must reach to be endorsed. Omit for no endorsement.

integer
>= 1 <= 100

Example

{
"learning_domain_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"scenario_context": "A long-standing customer is unhappy that their renewal price has gone up by 12%. They are considering a competitor and want the account manager to justify the increase or offer a discount.",
"documentation_text": "Renewal policy: price increases above 10% require a value review. Account managers may offer up to 5% loyalty discount on multi-year renewals.",
"scenario_name": "Renewal price objection",
"locales": "en-US",
"time_limit_minutes": 15,
"is_published": true,
"tags": [
"7c9e6679-7425-40de-944b-e07fc1f90ae7"
]
}

The scenario was generated and saved.

Media typeapplication/json

The scenario created by the generate endpoint.

object
id
required

Id of the new scenario.

string format: uuid
role_play_url

Link that opens the scenario’s role play in the app. Absent when the deployment has no app address configured.

string format: uri

Example generated

{
"id": "2489E9AD-2EE2-8E00-8EC9-32D5F69181C0",
"role_play_url": "https://example.com"
}

The request was rejected before or during generation:

  • Malformed JSON, a wrong field type, an unknown field, or an empty body (error_code invalid_request_body).
  • A field failed validation, for example a missing scenario_context, a malformed user_email, more than 50 tags, or a tag, learning_domain_id or persona_config_id that is not a lowercase UUID (error_code validation_failed, message names the field).
  • locales names an unsupported locale (error_code validation_failed, message “unsupported language locales: …”).
  • Practice mode is not enabled for the organization, or a practice request carries tags, endorsement_threshold or is_published: true (no error_code).
  • The context or documentation is too large for the AI model (error_code prompt_too_large or documents_too_large).
Media typeapplication/json

The body of an error returned by an endpoint.

object
message
required

Human-readable explanation of what went wrong.

string
error_code

Stable machine-readable cause. Present only for errors that have one.

string

Example generated

{
"message": "example",
"error_code": "example"
}

The Authorization header is missing, or the API key is not valid for this organization. A key check that fails on the server is also reported as 401.

Media typeapplication/json

The body of an error returned before the request reaches an endpoint (authentication and rate limiting).

object
error
required

Human-readable explanation of what went wrong.

string

Example generated

{
"error": "example"
}

A referenced resource is not available to the organization:

  • user_email is not an active member of the organization (error_code user_not_in_org).
  • A tag id does not belong to the organization (error_code validation_failed, message “tag is not available to this organization: ”).
  • The learning domain does not exist in the organization (“learning domain not found”, no error_code).
  • persona_config_id is not available to the organization, or no digital human is available at all (no error_code).
Media typeapplication/json

The body of an error returned by an endpoint.

object
message
required

Human-readable explanation of what went wrong.

string
error_code

Stable machine-readable cause. Present only for errors that have one.

string

Example generated

{
"message": "example",
"error_code": "example"
}

The request body is larger than 512 KiB (error_code invalid_request_body, message “request body is too large”).

Media typeapplication/json

The body of an error returned by an endpoint.

object
message
required

Human-readable explanation of what went wrong.

string
error_code

Stable machine-readable cause. Present only for errors that have one.

string

Example generated

{
"message": "example",
"error_code": "example"
}

The API key has sent too many requests. Wait for the number of seconds in Retry-After, then retry.

Media typeapplication/json

The body of an error returned before the request reaches an endpoint (authentication and rate limiting).

object
error
required

Human-readable explanation of what went wrong.

string

Example generated

{
"error": "example"
}
Retry-After
integer
>= 1

Seconds to wait before retrying.

Generation or saving failed, for example an AI model error or no AI model configured for a generation step (“unable to quick-generate training fields”), a generator that could not complete the scenario (“unable to generate a scenario from the supplied context — add more detail to scenario_context and retry”), no derivable name (“… supply scenario_name and retry”), or a failed save (“unable to create immersive training”). No error_code is set. Retrying may succeed.

Media typeapplication/json

The body of an error returned by an endpoint.

object
message
required

Human-readable explanation of what went wrong.

string
error_code

Stable machine-readable cause. Present only for errors that have one.

string

Example generated

{
"message": "example",
"error_code": "example"
}

Only while sizing a non-blank documentation_text for the model: no AI model is configured for that step (“no LLM routing is configured for this operation”) or every configured one is deactivated (“every LLM profile configured for this operation is deactivated”). The same problem in a later generation step answers 500 instead. No error_code is set.

Media typeapplication/json

The body of an error returned by an endpoint.

object
message
required

Human-readable explanation of what went wrong.

string
error_code

Stable machine-readable cause. Present only for errors that have one.

string

Example generated

{
"message": "example",
"error_code": "example"
}