Seed an empty AI chat session pinned to a campaign + sequence node to draft email content with the framework LLM.
campaign_sequence_nodes row). Each session owns:
messages — the chat transcriptskeleton — the structural framework (hook, value prop, CTA, …) the conversation has converged ondraft_subject / draft_body — the current email draft, using %variable% template syntaxgenerated_examples — per-lead AI-written sample emails derived from the skeletontask_status — busy-flag while a /turn or /generate-examples Trigger.dev task is in flightrunAiChatTurn build up the skeleton and draft, and generateAiChatExamples produces per-lead samples once a skeleton exists.
/api/campaigns/ai-chat-sessions with the list verb. See List campaign AI chat sessions to enumerate sessions for a campaign.POST /api/campaigns/ai-chat-sessions with { campaign_id, node_id } — creates an empty sessionPOST /api/campaigns/ai-chat-sessions/{id}/turn with a chat message — iteratively build up skeleton and draft_*GET /api/campaigns/ai-chat-sessions/{id} until task_status returns to null after each turnskeleton is non-null, call POST .../generate-examples to produce sample emailsdraft_subject / draft_body onto the sequence node via updateCampaignnode_id must reference an existing campaign_sequence_nodes row — the session is FK-linked to it. Deleting the node does not cascade-delete the session.Ownership is checked on POST. The handler explicitly verifies campaign ownership and returns 404 on miss.Idle sessions are safe to create. Creation has no LLM or Trigger.dev side effects — only a DB insert. Burning sessions you never call /turn on costs nothing.Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Minimal payload — the session is created empty (no messages, no skeleton, no draft). Content is built up via subsequent /turn and /generate-examples calls.
Campaign this session belongs to. Must be owned by the caller — ownership is verified before insert.
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$Sequence node (from campaign_sequence_nodes) this session drafts content for.
^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$Session created. Returns the empty session row.
Canonical campaign AI chat session. One session drafts one email (one sequence node) through a back-and-forth chat with the framework LLM.