DEV Community

KAMAL KISHOR
KAMAL KISHOR

Posted on

Deploying an AI Chatbot Entirely on Free Hosting Platforms

AI chatbots don’t have to cost \$\$ to run. If you’re a solo indie dev, student, or just experimenting, you can actually deploy an AI chatbot end-to-end without spending a rupee/dollar — thanks to free hosting platforms.

In this post, we’ll build and deploy a chatbot using Replit, Hugging Face Spaces, and Vercel — three free (or nearly free) hosting platforms that are developer-friendly.


🧩 The Stack We’ll Use

  • Frontend: Next.js (React-based, free hosting on Vercel)
  • Backend / Bot Logic: Python FastAPI (Replit or Hugging Face Spaces)
  • AI Brain: Open-source LLM (like LLaMA-3, Mistral) or API (like Gemini/OpenAI — with free tier)
  • Vector DB (Optional): FAISS (in-memory, free to run)

⚡ Option 1: Replit (Easiest for Beginners)

Step 1 — Create the Project

  • Go to Replit → New Repl → Choose Python + FastAPI template.

Step 2 — Install Dependencies

pip install fastapi uvicorn openai
Enter fullscreen mode Exit fullscreen mode

Step 3 — Add Bot Code

main.py

from fastapi import FastAPI
import openai

app = FastAPI()

@app.get("/chat")
def chat(query: str):
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",  # Or free-tier Gemini/Open-source model
        messages=[{"role": "user", "content": query}]
    )
    return {"answer": response["choices"][0]["message"]["content"]}
Enter fullscreen mode Exit fullscreen mode

Step 4 — Deploy

  • Hit Run in Replit.
  • Copy the public URL → it becomes your chatbot API.

⚡ Option 2: Hugging Face Spaces (For Open-Source Models)

Step 1 — Create a Space

Step 2 — Add Requirements

requirements.txt

transformers
gradio
Enter fullscreen mode Exit fullscreen mode

Step 3 — Add Bot Code

app.py

import gradio as gr
from transformers import pipeline

chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct")

def respond(message, history):
    result = chatbot(message, max_length=200, do_sample=True)
    return result[0]["generated_text"]

demo = gr.ChatInterface(respond)

demo.launch()
Enter fullscreen mode Exit fullscreen mode

Step 4 — Done 🎉

Your chatbot runs in the cloud with a free GPU/CPU (depending on demand).


⚡ Option 3: Vercel (Best for Frontend + API Routes)

Step 1 — Create Next.js App

npx create-next-app chatbot-vercel
Enter fullscreen mode Exit fullscreen mode

Step 2 — Add API Route

/pages/api/chat.js

export default async function handler(req, res) {
  const { query } = req.body;
  const response = await fetch("https://your-replit-or-hf-api/chat?query=" + query);
  const data = await response.json();
  res.status(200).json({ answer: data.answer });
}
Enter fullscreen mode Exit fullscreen mode

Step 3 — Frontend UI

/pages/index.js

import { useState } from "react";

export default function Home() {
  const [input, setInput] = useState("");
  const [chat, setChat] = useState([]);

  async function sendMessage() {
    const res = await fetch("/api/chat", {
      method: "POST",
      headers: {"Content-Type":"application/json"},
      body: JSON.stringify({ query: input })
    });
    const data = await res.json();
    setChat([...chat, {user: input, bot: data.answer}]);
    setInput("");
  }

  return (
    <div>
      <h1>AI Chatbot</h1>
      <div>
        {chat.map((c, i) => (
          <p key={i}><b>You:</b> {c.user} <br/> <b>Bot:</b> {c.bot}</p>
        ))}
      </div>
      <input value={input} onChange={e => setInput(e.target.value)} />
      <button onClick={sendMessage}>Send</button>
    </div>
  );
}
Enter fullscreen mode Exit fullscreen mode

Step 4 — Deploy to Vercel

  • Push to GitHub → Import repo into Vercel.
  • Free hosting + free SSL + free CDN 🚀

🎯 Which One Should You Choose?

Platform Best For Pros Cons
Replit Beginners, quick backend APIs 1-click deploy, easy Limited compute
Hugging Face Hosting open-source models Free GPU/CPU, Gradio Queues on free tier
Vercel Frontend + serverless functions Scales easily, Next.js ready No GPU for heavy models

✨ Final Thoughts

You don’t need AWS bills to experiment with AI. With Replit, Hugging Face Spaces, and Vercel, you can spin up a full chatbot for \$0 — perfect for prototyping, learning, or showcasing your idea.

Once your project grows, you can always migrate to paid hosting. But as a solo dev or indie hacker in 2025, free platforms are your best friend.


Top comments (0)