Overview
The Genie Chat API provides a Server-Sent Events (SSE) streaming interface to the AnythingLLM workspace agent. Unlike the embed API, this proxies to the full workspace agent mode with access to all 28 MCP tools (Directus, Ollama, Stagehand browser automation). Base Path:/api/genie
Key Features:
- Real-time streaming responses (SSE)
- Full MCP tool integration (Directus queries, browser automation, etc.)
- Onboarding gate enforcement (content generation blocked until setup complete)
- Automatic persona context injection from user’s RAG node graph
- Session-based conversation history
POST /api/genie/stream-chat
Stream AI agent responses using AnythingLLM workspace API. Authentication: Directus JWT (Bearer token)Request Parameters
User’s message/prompt to the AI agent. Can include:
- Content generation requests (“Write an Instagram caption about…”)
- Questions (“What are my top performing posts?”)
- Commands (“Schedule a post for tomorrow at 9am”)
Optional session identifier for conversation continuity. If omitted, defaults to
genie-{userId} for user-specific history.Response Format (SSE Stream)
The endpoint returns a Server-Sent Events stream withContent-Type: text/event-stream.
Event Structure:
Event type:
textResponseChunk- Incremental text chunktoolCall- MCP tool invocation notificationerror- Error occurred
Text content (for
textResponseChunk events)true if this is the final event in the streamtrue if an error occurredExample Request (curl)
Example Request (JavaScript Fetch)
Example Request (EventSource - Browser)
For GET-compatible SSE endpoints, use:Onboarding Gate
The endpoint enforces an onboarding completion gate before allowing content generation: FromgenieChat.js:50:
Persona Context Injection
The API automatically enriches user messages with persona node context from the taxonomy graph: FromgenieChat.js:68:
Session Management
Conversations are session-isolated to maintain context across multiple turns: Default Session ID:- User-wide session: Omit
sessionIdfor a single persistent conversation per user - Project-specific sessions: Use custom IDs like
campaign-summer-2026for isolated planning contexts - Ephemeral sessions: Generate random IDs for one-off requests without history pollution
MCP Tool Integration
The agent has access to 28 MCP tools via the AnythingLLM workspace: Available Tool Categories:Directus Tools (Data CRUD)
Directus Tools (Data CRUD)
directus_query_items- Read from any Directus collectiondirectus_create_item- Create recordsdirectus_update_item- Update recordsdirectus_delete_item- Delete records
Ollama Tools (AI Generation)
Ollama Tools (AI Generation)
ollama_generate- Text generation with any local modelollama_chat- Multi-turn chat completions
Stagehand Tools (Browser Automation)
Stagehand Tools (Browser Automation)
stagehand_navigate- Navigate to URLstagehand_extract- Extract page datastagehand_click- Click elementsstagehand_type- Input text
Platform APIs
Platform APIs
instagram_get_insights- Fetch Instagram analyticstiktok_get_videos- List TikTok videosyoutube_get_analytics- YouTube channel stats
Error Handling
Unauthorized (no token):Admin Endpoint: Taxonomy Rebuild
POST /api/genie/taxonomy/rebuild-graph
Apply human-reviewed taxonomy assignments to the knowledge graph and re-upload to AnythingLLM RAG. Authentication: Directus JWT (admin users only) Authorization Check:- Fetches all
taxonomy_review_queueitems withstatus=assigned - Adds
MAPS_TO_CONCEPTedges totaxonomy_graph.json - Saves updated graph
- Re-uploads RAG document to AnythingLLM (persona context)
Configuration
Environment Variables
Workspace Configuration
Ensure the target workspace has:- Agent mode enabled (not chat/query mode)
- MCP servers configured (Directus, Ollama, Stagehand)
- System prompt tuned for creator content generation
- RAG documents loaded (persona nodes, taxonomy graph)
Performance Considerations
Streaming Latency:- First token: 300-800ms (model warm-up + context processing)
- Token throughput: 20-50 tokens/sec (depends on model size)
- Network overhead: Negligible with HTTP/2 + keep-alive
X-Accel-Buffering: no header (line 102).
React Integration Example
Next Steps
Captions API
Non-streaming caption generation endpoint
Queue API
Enqueue long-running AI tasks as background jobs
