Deploy an AI Chatbot on Your NextJS Website using FREE tools
Zero-Cost AI Support Agent: RAG-Enabled Deployment with Hexabot and OpenRouter
Current Situation Analysis
The gap between a functional AI prototype and a production-grade customer support agent remains a significant bottleneck for engineering teams. While large language models (LLMs) are accessible, deploying a bot that accurately reflects proprietary knowledge without hallucination requires a robust Retrieval-Augmented Generation (RAG) pipeline, persistent state management, and reliable hosting.
Many organizations fall into the "Prototype Trap," where internal demos succeed but fail to translate to live environments due to infrastructure costs, vendor lock-in, or the complexity of integrating vector databases with workflow orchestration. Traditional chatbot SaaS solutions often charge premium rates for RAG capabilities and limit customization, forcing teams to choose between cost and control.
However, the emergence of composable, free-tier infrastructure and open-source orchestration tools has shifted this paradigm. By leveraging a stack centered on Hexabot for workflow management, OpenRouter for inference, and Railway for hosting with Postgres, teams can now deploy RAG-enabled support agents with zero marginal cost. This approach eliminates credit card requirements for initial deployment while providing full control over the knowledge base and model selection.
WOW Moment: Key Findings
The following comparison highlights the operational and economic advantages of a composable free-tier stack versus legacy SaaS alternatives. This data demonstrates that zero-cost deployment does not require sacrificing critical capabilities like RAG or data ownership.
| Approach | Monthly Cost | RAG Implementation | Vendor Lock-in | Deployment Flexibility |
|---|---|---|---|---|
| Legacy SaaS Chatbot | $50 β $500+ | Proprietary/Restricted | High | Low (Platform-bound) |
| Composable Free Stack | $0 (Free Tiers) | Full Control via RAG | None | High (Railway/GitHub) |
Why this matters: This finding enables startups and SMBs to implement enterprise-grade support infrastructure without upfront capital. The composable stack allows teams to iterate on RAG strategies, swap models via OpenRouter, and scale on Railway without renegotiating contracts or migrating data. The ability to use free models for inference during development and low-traffic phases drastically reduces the barrier to entry for AI-driven customer support.
Core Solution
This section outlines the technical implementation of a RAG-enabled support agent using Hexabot, OpenRouter, and Railway. The architecture prioritizes modularity, cost efficiency, and knowledge accuracy.
Architecture Overview
The system comprises four primary layers:
- Orchestration Layer: Hexabot manages conversation flows, intent classification, and state persistence.
- Inference Layer: OpenRouter provides access to multiple LLMs, including free-tier models, via a unified API.
- Knowledge Layer: RAG pipeline ingests website content, chunks it, generates embeddings, and stores vectors in Postgres for retrieval.
- Infrastructure Layer: Railway hosts the application and manages the Postgres database, ensuring persistence and scalability.
Step-by-Step Implementation
1. Initialize Hexabot Project Start by scaffolding the project using the Hexabot CLI. This creates a structured environment for defining workflows and configurations.
npm create hexabot@latest support-agent
cd support-agent
2. Configure OpenRouter Integration OpenRouter acts as the inference provider. Configure the API key and select a model. For cost-free experimentation, free-tier models are available.
// config/llm-provider.ts
export const openRouterConfig = {
provider: 'openrouter',
apiKey: process.env.OPENROUTER_API_KEY,
defaultModel: 'meta-llama/llama-3-8b-instruct:free',
fallbackModel: 'google/gemma-2-9b-it:free',
timeout: 15000,
};
3. Define Support Workflow Use Hexabot's flow builder to create the conversation logic. This example demonstrates intent classification and RAG retrieval.
// flows/support-flow.ts
import { FlowBuilder, NodeType } from '@hexabot/core';
export const buildSupportFlow = () => {
const flow = new FlowBuilder('customer_support_v2');
// Intent Classification Node
flow.addNode({
id: 'classify_intent',
type: NodeType.AI_CLASSIFIER,
config: {
provider: 'openrouter',
categories: ['billing', 'technical', 'account', 'general'],
confidenceThreshold: 0.75,
},
});
// RAG Retrieval Node
flow.addNode({
id: 'knowledge_retrieval',
type: NodeType.RETRIEVAL,
config: {
source: 'website_docs',
topK: 3,
embeddingModel: 'text-embedding-3-small',
chunkOverlap: 50,
},
});
// Response Generation Node
flow.addNode({
id: 'generate_response',
type: NodeType.LLM_GENERATION,
config: {
provider: 'openrouter',
model: 'meta-llama/llama-3-8b-instruct:free',
systemPrompt: 'You are a helpful support agent. Use the retrieved context to answer questions. If unsure, escalate to a human.',
},
});
// Connect Nodes
flow.addEdge('classify_intent', 'knowledge_retrieval');
flow.addEdge('knowledge_retrieval', 'generate_response');
return flow.build();
};
4. Implement RAG Pipeline
Hexabot handles RAG ingestion by processing source content into chunks, generating embeddings, and storing them in the vector store. Ensure your Postgres instance has the pgvector extension enabled for efficient similarity search.
// services/rag-ingestion.ts
export const ingestKnowledgeBase = async (sourcePath: string) => {
const documents = await loadDocuments(sourcePath);
const chunks = await chunkDocuments(documents, {
strategy: 'semantic',
maxSize: 512,
overlap: 50,
});
const embeddings = await generateEmbeddings(chunks, 'text-embedding-3-small');
await storeVectors(embeddings, 'support_knowledge');
console.log(`Ingested ${chunks.length} chunks into vector store.`);
};
5. Deploy to Railway Push the code to GitHub and connect the repository to Railway. Railway will automatically detect the Node.js project and provision a Postgres database.
railway login
railway init
railway up
Set environment variables in Railway:
OPENROUTER_API_KEYDATABASE_URL(auto-provisioned)HEXABOT_SECRET
6. Embed Chat Widget Generate a secure widget token and embed the script on your website. Hexabot provides a lightweight widget that connects to your deployed agent.
<script src="https://cdn.hexabot.io/widget/latest.js"></script>
<script>
HexabotWidget.init({
endpoint: 'https://your-railway-app.railway.app/api/chat',
token: 'your_secure_widget_token',
theme: 'light',
});
</script>
Architecture Decisions and Rationale
- Hexabot for Orchestration: Hexabot provides a visual workflow builder and robust state management, reducing the complexity of building custom conversation logic. Its CLI and plugin ecosystem support rapid iteration.
- OpenRouter for Inference: OpenRouter aggregates multiple LLM providers, allowing seamless model switching and access to free-tier models. This flexibility is crucial for cost management and performance tuning.
- Railway for Hosting: Railway offers a streamlined deployment experience with built-in Postgres support. The free tier is sufficient for low-to-medium traffic applications, and scaling is straightforward.
- RAG with pgvector: Storing embeddings in Postgres with
pgvectorleverages existing database infrastructure, reducing operational overhead. Semantic chunking ensures high retrieval accuracy.
Pitfall Guide
Avoid these common mistakes to ensure a reliable and cost-effective deployment.
| Pitfall | Explanation | Fix |
|---|---|---|
| Hallucination in RAG | The model generates responses not grounded in retrieved context, leading to inaccurate answers. | Implement strict prompt templates that enforce context usage. Add a fallback mechanism to escalate to a human if confidence is low. |
| Free Tier Rate Limits | OpenRouter free models may have rate limits or throttling, causing latency or failures during peak traffic. | Implement caching for frequent queries. Use fallback models or queue requests during high load. Monitor usage via OpenRouter dashboard. |
| Inefficient RAG Chunking | Chunks that are too large or small reduce retrieval accuracy, causing irrelevant context injection. | Use semantic chunking with appropriate overlap. Experiment with chunk sizes (e.g., 256β512 tokens) and evaluate retrieval metrics. |
| Security Vulnerabilities | Exposing API keys or widget tokens in frontend code can lead to unauthorized access or abuse. | Use backend proxies for API calls. Generate short-lived, scoped widget tokens. Validate all inputs in the workflow. |
| Database Persistence Issues | Forgetting to provision persistent storage on Railway can result in data loss during redeployments. | Ensure Railway Postgres add-on is configured with persistent volumes. Regularly back up the database. |
| Workflow Loops | Infinite loops in the visual builder can cause the bot to get stuck, consuming resources and frustrating users. | Implement timeout nodes and exit conditions. Use Hexabot's loop detection features to prevent cycles. |
| Context Window Overflow | Injecting too much RAG context exceeds the model's context window, causing truncation or errors. | Limit topK retrieval results. Summarize long contexts before injection. Monitor token usage and adjust chunk sizes. |
Production Bundle
This section provides actionable resources for deploying and managing your AI support agent.
Action Checklist
- Initialize Hexabot project using CLI and configure OpenRouter API key.
- Provision Railway Postgres instance with
pgvectorextension enabled. - Define support workflow with intent classification and RAG retrieval nodes.
- Ingest knowledge base using semantic chunking and store embeddings in Postgres.
- Test workflow locally using
hexabot devand validate RAG accuracy. - Deploy to Railway, set environment variables, and verify health endpoint.
- Generate secure widget token and embed script on production website.
- Monitor performance metrics and adjust RAG parameters based on user feedback.
Decision Matrix
Use this matrix to select the appropriate approach based on your requirements.
| Scenario | Recommended Approach | Why | Cost Impact |
|---|---|---|---|
| MVP / Low Traffic | OpenRouter Free Models + Railway Free Tier | Zero cost, sufficient for testing and validation | $0 |
| High Reliability | OpenRouter Paid Models + Railway Hobby | Better uptime, faster inference, dedicated resources | ~$5β10/mo |
| Complex Multi-Agent | Hexabot Enterprise or Custom LangChain | Advanced orchestration, multi-agent collaboration | Variable |
| Data Privacy Focus | Self-Hosted LLM + Local Postgres | Full data control, compliance with strict regulations | Infrastructure costs |
Configuration Template
Copy this template for environment variables and configuration files.
# .env.example
DATABASE_URL=postgresql://user:pass@host:5432/hexabot_db
OPENROUTER_API_KEY=sk-or-xxxx
HEXABOT_SECRET=your_jwt_secret
RAG_CHUNK_SIZE=512
RAG_OVERLAP=50
WIDGET_TOKEN=your_widget_token
# railway.json
{
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"startCommand": "hexabot start",
"healthcheckPath": "/health"
}
}
Quick Start Guide
Get your AI support agent running in under 5 minutes.
- Scaffold Project: Run
npm create hexabot@latest support-botand navigate to the directory. - Connect LLM: Execute
hexabot connect openrouterand provide your API key. - Add Knowledge: Run
hexabot rag add ./docsto ingest your website content. - Deploy: Use
railway initandrailway upto deploy to Railway with Postgres. - Embed: Copy the widget script from Hexabot dashboard and paste it into your website's HTML.
This guide provides a complete path from zero to a production-ready AI support agent, leveraging free tools and best practices for RAG, deployment, and security. By following this approach, you can deliver accurate, cost-effective customer support without compromising on flexibility or control.
Mid-Year Sale β Unlock Full Article
Base plan from just $4.99/mo or $49/yr
Sign in to read the full article and unlock all tutorials.
Sign In / Register β Start Free Trial7-day free trial Β· Cancel anytime Β· 30-day money-back
