Generation Pipeline
The custom course generation runs through three n8n workflows on worker-1, each handling a distinct stage of the pipeline.
Purpose
Transform user inputs (issue, goal, feel, why) into a personalized hypnotherapy audio session through AI-powered script generation with safety guardrails.
Architecture
All workflows run on n8n worker-1 (Digital Ocean) and are triggered via webhook by the submit-custom-course edge function.
User Input → Health Check → Script Generation → Safety Check → Audio Generation
Stage 1: Health Check
Webhook: /webhook/api/v1/custom-course-health-check
Model: mistral-medium
Purpose: Validate that user inputs are safe and appropriate for hypnotherapy before generating scripts.
What It Checks
- Safety — Flags self-harm, medical conditions, dangerous content
- Clarity — Are the inputs specific enough to generate a good script?
- Rewrite suggestions — If inputs are vague or problematic, suggests improvements
Response Format
{
"success": true,
"blocked": false,
"data": {
"is_safe": true,
"is_clear": true,
"needs_rewrite": false,
"safety_category": "NONE",
"reasoning": "..."
}
}
Fail-Safe
If the health check workflow is unreachable or returns an error, the system defaults to allowing the request through (doesn’t block the user due to workflow issues).
Cost
~$0.0007 per check (~768 input tokens, ~219 output tokens)
Stage 2: Script Generation
Webhook: /webhook/api/v1/custom-script
Model: ft:mistral-medium (fine-tuned on HypnoELP course data)
Purpose: Generate three personalized hypnotherapy scripts using different techniques.
Input
{
"issue": "...",
"goal": "...",
"feel": "...",
"why": "...",
"title": "...",
"scripts": [
{"number": 1, "technique": "REHEARSAL"},
{"number": 2, "technique": "FUTURE_VISUALIZATION"},
{"number": 3, "technique": "EMOTIONAL_LEVERAGE"}
],
"user_id": "..."
}
Output
Three complete hypnotherapy scripts (script1, script2, script3) plus a safety object from the post-generation safety check.
Safety Check (Post-Generation)
After generating scripts, a safety check runs using mistral-small to verify the generated content is appropriate. If any script fails, the entire request is rejected.
Cost
~$0.0026 per generation (~450 input tokens, ~1,200 output tokens)
Stage 3: Audio Generation
Webhook: /webhook/api/v1/custom-audio
Model: ElevenLabs TTS
Purpose: Convert the selected script into a professional hypnotherapy audio file.
Input
{
"text": "full script text",
"voice": "male" | "female",
"title": "session title",
"client_id": "user_id"
}
Output
Audio file URL hosted on Cloudflare R2 (hypnoelp-custom-files bucket).
Voices
- Male and Female options via ElevenLabs TTS
Available Techniques
| Code | Display Name | Style |
|---|---|---|
REHEARSAL |
Mental Rehearsal | Visualize success in specific scenarios |
TRIGGER_NEUTRALIZATION |
Trigger Transformation | Reframe responses to triggers |
POST_HYPNOTIC |
Lasting Suggestions | Post-hypnotic behavioral anchors |
AVERSION |
Gentle Release | Release old patterns through aversion |
FUTURE_VISUALIZATION |
Future Self | Forward-looking visualization |
EMOTIONAL_LEVERAGE |
Deep Motivation | Emotional leverage for change |
Total Cost Per Custom Course
| Stage | Model | Cost |
|---|---|---|
| Health Check | mistral-medium | ~$0.0007 |
| Script Generation | ft:mistral-medium | ~$0.0026 |
| Safety Check | mistral-small | ~$0.0002 |
| Total AI cost | ~$0.004 |
Audio generation cost (ElevenLabs) is separate and varies by script length.
Costs are logged to the custom_course_costs table on the HypnoELP-AI Supabase project (yxudnnytcjuafeclsofg).
Handshakes
| From | To | Protocol |
|---|---|---|
| Edge function | n8n health check | HTTP POST (webhook) |
| Edge function | n8n script generation | HTTP POST (webhook) |
| Edge function | n8n audio generation | HTTP POST (webhook) |
| n8n | Mistral API | HTTP (LLM inference) |
| n8n | ElevenLabs API | HTTP (TTS) |
| n8n | Cloudflare R2 | S3 API (audio storage) |
| n8n | HypnoELP-AI Supabase | REST API (cost logging) |
Dependencies
- n8n (workflow orchestration)
- Mistral API (LLM — small, medium, fine-tuned)
- ElevenLabs API (TTS)
- Cloudflare R2 (audio file storage)
- HypnoELP-AI Supabase (cost logging)
Status
Production. All three stages operational. Fine-tuned Mistral V2 model deployed. V3 retraining pending (4 courses missing from training data).