Prompt
How do I add a chatbot API to my app without training a model?
Latest observation
You can add a chatbot to your app without training your own model by using an existing AI API (hosted model) and wrapping it in your app’s backend.
Typical approach
1. Pick an API provider
Common options:
- OpenAI API
- Anthropic API
- Google Gemini API
- Azure OpenAI
- Cohere
- Open-source hosted providers like Groq, Together, Fireworks
These give you access to a pretrained model, so you don’t need to train anything.
2. Build a small backend
Don’t call the AI API directly from your frontend if you can avoid it, because that exposes your secret API key.
Your backend should:
- receive user messages from your app
- send them to the chatbot API
- return the AI response to the client
3. Send conversation context
To make it feel like a real chatbot, include:
- system instructions
- conversation history
- optional user profile or app data
Example structure:
{
"messages": [
{"role": "system", "content": "You are a helpful support assistant."},
{"role": "user", "content": "How do I reset my password?"}
]
}
4. Add optional app data
If you want the bot to answer based on your own content, you can use:
- retrieval-augmented generation (RAG)
- a vector database
- document search
- function calling / tool use
This lets the chatbot use your data without model training.
Simple example
Backend example in Node.js
import express from "express";
import OpenAI from "openai";
const app = express();
app.use(express.json());
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
app.post("/chat", async (req, res) => {
const { message, history = [] } = req.body;
const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
...history,
{ role: "user", content: message }
]
});
res.json({ reply: response.choices[0].message.content });
});
app.listen(3000, () => console.log("Server running on port 3000"));
Frontend call
const res = await fetch("/chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: "Hello!" })
});
const data = await res.json();
console.log(data.reply);
What to watch out for
- API key security: keep keys on the server
- costs: chat APIs are usually pay-per-token
- latency: responses may take a second or two
- moderation/safety: add guardrails if your app needs them
- conversation memory: store history in your database if needed
If you want your bot to use your own docs
Use one of these:
- upload docs into a vector database
- search relevant passages first
- include those passages in the prompt
- or use a provider’s built-in file search / retrieval tools
This is usually better than fine-tuning for support bots and knowledge assistants.
Recommended architecture
Frontend → Your backend → AI API → Your backend → Frontend
If you want, I can show you:
- a React + Node chatbot example
- a Python/FastAPI version
- how to connect it to your own documents without training the model