Generate a role-play scenario with AI
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" ]}'const url = `${process.env.UNEEQ_API_URL}/external/v1/organization/${process.env.UNEEQ_ORG_ID}/immersive-training/generate`;const response = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${process.env.UNEEQ_API_KEY}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ "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" ] }),});console.log(response.status, await response.text());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_emailomitted or empty): aROLE_PLAYscenario in the organization library.is_published,tagsandendorsement_thresholdapply. - Private practice scenario (
user_emailset): aPRACTICEscenario 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-emptytags, anyendorsement_thresholdoris_published: truewithuser_emailis rejected with 400.
What gets generated and saved:
- The scenario name is
scenario_namewhen 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_idis 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_textis attached to the scenario as a supporting document namedscenario-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.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”ID of the organization the API key belongs to, for example org_HYPCX67vaupjhdTn.
Example
org_HYPCX67vaupjhdTnRequest Bodyrequired
Section titled “Request Bodyrequired”Brief for an AI-generated scenario. user_email selects between an org-wide role play and a member’s private practice scenario.
object
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.
Learning domain of the organization the scenario belongs to; its guidance shapes the generated prompt. Must be a lowercase UUID.
The situation to role-play, in plain language. The generator invents anything it leaves out.
Optional reference material (policies, product facts). Summarized if too long for the model, and attached to the scenario as a supporting document.
Digital human to use. Omit to have one picked from those available to the organization. Must be a lowercase UUID.
Scenario name. Omit, or send only whitespace, to use the generated title. Surrounding whitespace is trimmed.
Deprecated and ignored. Every scenario offers every supported language. Still validated, so an unsupported locale is rejected with validation_failed; omit it.
Session time limit in minutes. Omit for no limit.
Org-wide only. Publish the scenario to learners immediately. Must not be true for a practice scenario, which is always published.
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.
Org-wide only. Score a learner must reach to be endorsed. Omit for no endorsement.
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" ]}Responses
Section titled “Responses”The scenario was generated and saved.
The scenario created by the generate endpoint.
object
Id of the new scenario.
Link that opens the scenario’s role play in the app. Absent when the deployment has no app address configured.
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_codeinvalid_request_body). - A field failed validation, for example a missing
scenario_context, a malformeduser_email, more than 50 tags, or a tag,learning_domain_idorpersona_config_idthat is not a lowercase UUID (error_codevalidation_failed, message names the field). localesnames an unsupported locale (error_codevalidation_failed, message “unsupported language locales: …”).- Practice mode is not enabled for the organization, or a practice request carries
tags,endorsement_thresholdoris_published: true(noerror_code). - The context or documentation is too large for the AI model (
error_codeprompt_too_largeordocuments_too_large).
The body of an error returned by an endpoint.
object
Human-readable explanation of what went wrong.
Stable machine-readable cause. Present only for errors that have one.
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.
The body of an error returned before the request reaches an endpoint (authentication and rate limiting).
object
Human-readable explanation of what went wrong.
Example generated
{ "error": "example"}A referenced resource is not available to the organization:
user_emailis not an active member of the organization (error_codeuser_not_in_org).- A tag id does not belong to the organization (
error_codevalidation_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_idis not available to the organization, or no digital human is available at all (noerror_code).
The body of an error returned by an endpoint.
object
Human-readable explanation of what went wrong.
Stable machine-readable cause. Present only for errors that have one.
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”).
The body of an error returned by an endpoint.
object
Human-readable explanation of what went wrong.
Stable machine-readable cause. Present only for errors that have one.
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.
The body of an error returned before the request reaches an endpoint (authentication and rate limiting).
object
Human-readable explanation of what went wrong.
Example generated
{ "error": "example"}Headers
Section titled “Headers”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.
The body of an error returned by an endpoint.
object
Human-readable explanation of what went wrong.
Stable machine-readable cause. Present only for errors that have one.
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.
The body of an error returned by an endpoint.
object
Human-readable explanation of what went wrong.
Stable machine-readable cause. Present only for errors that have one.
Example generated
{ "message": "example", "error_code": "example"}
