← Blog

How to Make the Chatbot: A Practical Build Plan

2026-09-10 · 5 min read · SubToAPI Team

How to Make the Chatbot: A Practical Build Plan

If you're searching "how to make the chatbot," you probably don't want a toy demo — you want something that answers real questions, handles multi-turn conversations, and can eventually be embedded in a product. The short answer: pick a language model, connect it to a backend that manages conversation state, expose it through an API, and put a UI in front of it. The rest of this article walks through each of those steps with working code.

You don't need to train a model from scratch. Modern chatbots are built on top of existing large language models (Claude, GPT, Llama, etc.) accessed through an API. Your job as the builder is architecture, not machine learning research: message handling, context management, tool integrations, and reliability.

Step 1: Decide What Kind of Chatbot You're Building

Before writing code, answer three questions:

These decisions shape everything downstream. A support bot needs retrieval over your documentation; an action-taking bot needs tool/function calling; a simple FAQ bot might not need either.

Step 2: Choose How You'll Access a Language Model

You have three realistic paths:

  1. Direct API access from the model provider (Anthropic, OpenAI, etc.), with your own billing and rate limits.
  2. A managed layer like SubToAPI that turns your existing Claude access into a standard HTTPS API with API keys, streaming, and usage metadata — useful if you want to skip separate enterprise billing setup and get a dashboard for team usage.
  3. Self-hosted open models, which requires GPU infrastructure and ongoing maintenance — usually not worth it unless you have specific data-residency requirements.

For most builders, option 1 or 2 is the right call. The code below uses a generic REST pattern that applies to either.

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet",
    "max_tokens": 500,
    "messages": [
      {"role": "user", "content": "What'\''s the return policy?"}
    ]
  }'

If you're evaluating providers, check the quickstart docs for a minimal end-to-end example and the messages reference for the full request/response shape.

Step 3: Design Conversation State

A chatbot isn't a single API call — it's a running conversation. Each request needs the full message history, because these APIs are stateless by default.

const messages = [];

async function sendMessage(userInput) {
  messages.push({ role: "user", content: userInput });

  const res = await fetch("https://api.subtoapi.app/v1/messages", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      model: "claude-3-5-sonnet",
      max_tokens: 500,
      messages,
    }),
  });

  const data = await res.json();
  const reply = data.content[0].text;
  messages.push({ role: "assistant", content: reply });
  return reply;
}

For anything beyond a demo, store this history in a database keyed by user or session ID, not in memory. Trim old messages or summarize them once you approach the model's context window, otherwise costs and latency creep up.

Step 4: Add System Instructions and Guardrails

A system prompt sets tone, scope, and boundaries. Keep it specific:

{
  "model": "claude-3-5-sonnet",
  "system": "You are a support assistant for Acme Cloud. Only answer questions about billing, account settings, and API usage. If asked anything else, say you can't help with that.",
  "messages": [...]
}

Vague system prompts ("be helpful and friendly") produce inconsistent behavior. Narrow, concrete instructions produce a chatbot that actually stays on task.

Step 5: Stream Responses for a Better UX

Waiting several seconds for a full response feels slow. Streaming sends tokens as they're generated, so the user sees the reply forming in real time — the standard pattern for chat interfaces.

const res = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    model: "claude-3-5-sonnet",
    max_tokens: 500,
    stream: true,
    messages,
  }),
});

const reader = res.body.getReader();
// read chunks and append to the UI as they arrive

Details on event formats are in the streaming docs.

Step 6: Give It Tools If It Needs to Act

If your chatbot should look up order status, check inventory, or run a calculation, use tool calling instead of trying to get the model to guess. You define a tool schema, the model decides when to call it, and your backend executes the actual logic and returns the result.

{
  "tools": [
    {
      "name": "get_order_status",
      "description": "Look up the status of a customer order by ID",
      "input_schema": {
        "type": "object",
        "properties": {
          "order_id": { "type": "string" }
        },
        "required": ["order_id"]
      }
    }
  ]
}

This is what separates a chatbot that only talks from one that actually does things. See the tools guide for the full request/response cycle.

Step 7: Ship It Behind Your Own API Key

Once the logic works, wrap it behind an application-level API key rather than exposing the model provider's raw key in client code. This gives you rate limiting, per-team usage tracking, and the ability to rotate keys without redeploying your app. SubToAPI issues these as sub_live_... keys with usage metadata per request, which is useful once more than one person or service is calling your chatbot. Start with a free trial and check pricing if you're scaling to a team.

Step 8: Test With Real Conversations, Not Just Happy Paths

Before launch, run through:

A chatbot that only works on clean, single-turn questions will break in production within a day.

questions

Do I need to train my own AI model to make a chatbot? No. Almost all chatbots today call an existing language model through an API and add conversation logic, system prompts, and optional tools around it.

What's the minimum I need to launch a working chatbot? An API key for a language model, a backend that stores message history per user, and a simple frontend or chat widget to send and display messages.

Should my chatbot use streaming responses? Yes, for any user-facing chat interface. Streaming reduces perceived latency significantly and is standard practice — see the streaming docs for implementation details.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →