How to Create a Claude Chatbot: A Step-by-Step Guide
Creating a Claude chatbot means connecting a frontend (a chat UI, a Slack bot, a support widget) to Claude's messages API, then managing the conversation state, system prompt, and response streaming so it feels like a real assistant instead of a one-off API call. The whole process breaks down into five steps: get API access, design the system prompt, send and receive messages, keep conversation history, and deploy it somewhere people can use it.
This guide walks through each step with working code, using patterns that apply whether you're calling Claude directly through Anthropic or through a proxy like SubToAPI that wraps your existing Claude access in a standard HTTPS API.
Step 1: Get API Access
You need a way to send HTTP requests to Claude and get responses back. There are two common paths:
- Direct Anthropic API access — requires an Anthropic API key and billing tied to their console.
- A wrapped API — if you already pay for Claude through a subscription and want a normal REST API with a key, streaming, and usage tracking without separate API billing, a service like SubToAPI turns that access into an endpoint you call with
sub_live_...keys.
Either way, you'll end up making POST requests to a /messages endpoint with a model name, a system prompt, and a list of messages. If you're using SubToAPI, sign up at /signup, grab your key from the dashboard, and check /docs/quickstart for the exact request shape.
Step 2: Design the System Prompt
The system prompt is what turns "an API that talks" into "a chatbot with a purpose." It should define:
- Role — what the bot is for (support agent, coding assistant, internal tool)
- Tone — formal, casual, terse, verbose
- Boundaries — what it should refuse or defer on
- Output format — plain text, markdown, JSON for structured replies
A minimal example:
You are a support assistant for Acme SaaS. Answer questions about
billing, plans, and account settings. Keep answers under 4 sentences.
If asked about something outside Acme's product, say you don't know
and offer to connect the user with a human.
Keep it specific. Vague system prompts produce generic, rambling answers — precise ones produce a chatbot that behaves consistently across thousands of conversations.
Step 3: Send and Receive Messages
Here's a basic request/response cycle using curl against SubToAPI's endpoint. The same shape works with Anthropic's own API with a different base URL and key.
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4",
"max_tokens": 512,
"system": "You are a support assistant for Acme SaaS.",
"messages": [
{ "role": "user", "content": "How do I cancel my subscription?" }
]
}'
The response includes the assistant's reply as content blocks along with token usage. Full request/response details are in /docs/messages.
For a chatbot, you almost always want streaming instead of waiting for the full response — it's the difference between a UI that feels alive and one that feels frozen for a few seconds. Here's a JavaScript example:
const response = 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-sonnet-4",
max_tokens: 512,
stream: true,
system: "You are a support assistant for Acme SaaS.",
messages: [{ role: "user", content: "How do I cancel my subscription?" }],
}),
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
process.stdout.write(decoder.decode(value));
}
Details on event types and parsing the stream are in /docs/streaming.
Step 4: Keep Conversation History
Claude's API is stateless — every request needs the full conversation history, not just the latest message. Your chatbot needs to maintain a messages array and append to it as the conversation grows:
let history = [];
function addUserMessage(text) {
history.push({ role: "user", content: text });
}
function addAssistantMessage(text) {
history.push({ role: "assistant", content: text });
}
On each turn, send the entire history array in the request. Watch two things as conversations grow:
- Token limits — long histories cost more and eventually hit context limits. Trim or summarize older turns once you pass a reasonable length.
- Storage — for a production chatbot, persist history per user/session in a database rather than in memory, so conversations survive server restarts.
Step 5: Add Tools (Optional but Powerful)
If your chatbot needs to look things up, check an order status, or run a calculation instead of just generating text, use tool use (function calling). You define a tool schema, Claude decides when to call it, your code executes the actual logic, and you feed the result back in the next message. This is what turns a chatbot from "answers questions from training data" into "takes real actions." See /docs/tools for the request format and a worked example.
Step 6: Deploy It
Once the request/response loop, history, and system prompt are solid, wire it into wherever users need it:
- A web widget calling your backend, which calls Claude
- A Slack or Discord bot using their respective event APIs
- An internal tool behind your existing auth
Never call the Claude API directly from client-side JavaScript — your API key would be exposed. Always route through your own backend, which then calls Claude (or SubToAPI) with the key stored server-side.
For teams building multiple chatbots or giving different environments their own keys, a dashboard with per-key usage and rate limits saves a lot of manual tracking — check /pricing for how SubToAPI's Solo, Team, and Scale plans handle multiple keys and seats.
Questions
Do I need to train a model to create a Claude chatbot? No. You don't train or fine-tune anything — you send messages to Claude's existing model via API calls, and the system prompt plus conversation history shape its behavior.
How much does it cost to run a Claude chatbot? Cost depends on token usage per conversation and your access method — direct API billing per token, or a flat subscription like SubToAPI's plans starting at €9/month. Longer histories and bigger models cost more per message.
Can I add memory so the chatbot remembers past conversations? Yes, but you have to build it — store conversation history in a database keyed by user ID, and either replay relevant history each request or summarize older turns to stay within context limits.