Skip to content

Enhanced Chat Stream

POST
/api/chat/enhanced/stream

Enhanced chat with Server-Sent Events (SSE) streaming

Streams AI responses in real-time using Server-Sent Events format. Each chunk contains partial content, metadata, and progress information. Enables progressive rendering of AI responses in the frontend with typing indicators and real-time updates.

Args: request: FastAPI request object request_data: Enhanced chat request with message, agent, persona, etc. backend: Backend service instance (injected)

Returns: StreamingResponse: SSE stream of chat response chunks

Raises: HTTPException: 503 if enhanced chat service unavailable HTTPException: 500 if streaming fails

Example Request: POST /chat/enhanced/stream { “message”: “Tell me about the magic system”, “thread_id”: “thread_abc123”, “persona”: “lore_scholar”, “stance”: “analytical” }

Example SSE Response Stream: data: {“type”: “chunk”, “content”: “The magic”, “index”: 0}

data: {"type": "chunk", "content": " system is", "index": 1}

data: {"type": "chunk", "content": " a rich and intricate...", "index": 2}

data: {"type": "complete"}
EnhancedChatRequest

Enhanced chat interaction request model with advanced features.

Request model for advanced chat interactions supporting conversation threading, agent selection, persona/stance control, and targeted RAG document pinning. Uses IshvanaBaseModel for automatic snake_case → camelCase JSON conversion.

Fields: message: User’s chat message content project_id: Project context identifier (default: “my-project”) conversation_id: Existing thread ID to continue conversation (optional) agent_type: Preferred agent specialization (default: “general”) use_rag: Whether to use RAG for context retrieval (default: True) temperature: LLM temperature for creativity (default: 0.7, range: 0.0-2.0) max_tokens: Maximum tokens in AI response (default: 2048) search_results_count: Number of RAG results to retrieve (default: 10) persona: AI persona to adopt (e.g., ‘Lore Scholar’, ‘Creative Editor’) stance: Response stance (e.g., ‘brainstorming’, ‘critical’, ‘analytical’) pinned_document_ids: Specific documents to prioritize in RAG search requested_at: Timestamp when request was created (auto-generated)

Persona Examples: - ‘Lore Scholar’: Deep lore expert, analytical and precise - ‘Creative Editor’: Collaborative writing partner, supportive and creative - ‘World Historian’: Detail-oriented worldbuilding assistant - ‘Technical Writer’: Documentation and structure expert

Stance Examples: - ‘brainstorming’: Exploratory, idea-generating, open-ended - ‘critical’: Analytical, evaluative, constructive feedback - ‘analytical’: Detailed analysis, structured thinking - ‘supportive’: Encouraging, collaborative, affirming

Used By: - POST /api/chat/enhanced endpoint - Enhanced chat UI with persona/stance controls - Threaded conversation management - Targeted RAG document exploration - Dynamic AI voice adjustment

object
message
required
Message

User message

string
projectId
Any of:
string
threadId
Any of:
string
conversationId
Any of:
string
agentType
Agenttype

Preferred agent type

string
default: general
agent
Any of:
string
projectType
Any of:
string
workflowType
Any of:
string
useRag
Userag

Use RAG for context

boolean
default: true
temperature
Temperature

LLM temperature

number
default: 0.7
maxTokens
Maxtokens

Maximum tokens

integer
default: 2048
searchResultsCount
Searchresultscount

RAG search results

integer
default: 10
persona
Any of:
string
stance
Any of:
string
pinnedDocumentIds
Any of:
Array<string>
images
Any of:
Array<object>
ImageAttachment

Base64-encoded image attached to a chat message.

object
mediaType
required
Mediatype

MIME type (image/png, image/jpeg, image/gif, image/webp)

string
data
required
Data

Base64-encoded image data

string
context
Any of:
AgentChatContext

Ambient author context attached to a freeform agent request.

object
activeUrl
Any of:
string
pageTitle
Any of:
string
pageContentExcerpt
Any of:
string
activeDocumentTitle
Any of:
string
activeDocumentExcerpt
Any of:
string
writersRoom
Writersroom

Writers’ Room multi-agent mode

boolean
skipUserPersist
Skipuserpersist

Skip user message persistence (used by WR to avoid duplicates)

boolean
requestedAt
Requestedat

Enhanced chat request timestamp

string format: date-time

Successful Response

Validation Error

HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
input
Input
ctx
Context
object