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"}Request Body required
Section titled “Request Body required ”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
User message
Preferred agent type
Use RAG for context
LLM temperature
Maximum tokens
RAG search results
Base64-encoded image attached to a chat message.
object
MIME type (image/png, image/jpeg, image/gif, image/webp)
Base64-encoded image data
Ambient author context attached to a freeform agent request.
Writers’ Room multi-agent mode
Skip user message persistence (used by WR to avoid duplicates)
Enhanced chat request timestamp
Responses
Section titled “ Responses ”Successful Response
Validation Error