Claude API Lead Qualification Chatbot Tutorial
What this tutorial covers
If you landed here, you probably want to build a chatbot that talks to inbound website visitors, asks qualifying questions, scores the lead, and hands structured data to your sales team — without hiring an SDR to sit on live chat all day. This tutorial walks through exactly that: a working Claude-powered lead qualification chatbot, from conversation design to the code that extracts structured output and routes qualified leads to your CRM or Slack.
We'll use the Claude API directly for the model logic, and show how to run it through SubToAPI so you get HTTPS endpoints, API keys, and usage tracking without managing your own Claude account infrastructure. Everything below works whether you call Claude directly or through a gateway — the conversation design is the part that actually determines whether your bot qualifies leads well.
Why Claude works well for lead qualification
Lead qualification is a conversational data-extraction problem: you need the model to hold a natural dialogue and reliably pull out structured fields (budget, timeline, company size, decision-making authority) at the end. Claude handles this well because of:
- Long context retention — it tracks what the visitor already said across a multi-turn chat without losing earlier answers.
- Reliable structured output — you can ask it to emit a JSON block alongside its conversational reply, and it follows the format consistently.
- Tool use — you can give it a function like
submit_qualified_leadthat it calls once it has enough information, instead of guessing when to stop asking questions.
Step 1: Define your qualification framework
Before writing code, decide what "qualified" means for your business. A common framework is BANT (Budget, Authority, Need, Timeline). Encode this as a system prompt:
You are a lead qualification assistant for [Company]. Your job is to have a
natural conversation with website visitors and determine:
1. Budget: Do they have budget allocated, and roughly how much?
2. Authority: Are they the decision-maker or do they need approval?
3. Need: What specific problem are they trying to solve?
4. Timeline: When do they want to implement a solution?
Ask one question at a time. Keep responses under 3 sentences. Once you have
enough information on all four points, call the submit_lead tool with your
findings. Do not call the tool prematurely — if a field is unclear, ask a
follow-up question first.
This single prompt is the difference between a bot that feels like a form and one that feels like a conversation.
Step 2: Define the tool for structured extraction
Rather than parsing free text after the fact, use Claude's tool-calling to get clean structured output the moment qualification is complete.
{
"name": "submit_lead",
"description": "Submit a qualified lead once budget, authority, need, and timeline are known.",
"input_schema": {
"type": "object",
"properties": {
"company_size": { "type": "string" },
"budget_range": { "type": "string" },
"is_decision_maker": { "type": "boolean" },
"primary_need": { "type": "string" },
"timeline": { "type": "string" },
"lead_score": { "type": "integer", "minimum": 1, "maximum": 10 }
},
"required": ["budget_range", "is_decision_maker", "primary_need", "timeline", "lead_score"]
}
}
The lead_score field asks the model to self-rate the lead based on the full conversation — a cheap but surprisingly useful signal for prioritizing follow-up.
Step 3: Build the conversation loop
Here's the core request structure using the Claude Messages API through SubToAPI's gateway, which gives you the same request/response shape with your sub_live_... key:
async function sendMessage(messages) {
const res = await fetch("https://api.subtoapi.app/v1/messages", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`
},
body: JSON.stringify({
model: "claude-sonnet-4-5",
max_tokens: 500,
system: SYSTEM_PROMPT,
tools: [submitLeadTool],
messages
})
});
return res.json();
}
Each visitor turn appends to the messages array. When Claude decides it has enough information, the response will contain a tool_use block instead of (or alongside) a text reply. Your server should check for that:
const data = await sendMessage(conversationHistory);
const toolCall = data.content.find(block => block.type === "tool_use");
if (toolCall && toolCall.name === "submit_lead") {
await pushToCRM(toolCall.input);
await notifySlack(toolCall.input);
}
This is a standard tool-use pattern — see the tools documentation for the full request/response shape, including how to send a tool_result back if you need Claude to confirm the submission in its reply to the visitor.
Step 4: Route qualified leads
Once submit_lead fires, you have a clean JSON object. Typical routing logic:
lead_score >= 7→ create a CRM deal and ping the sales Slack channel immediately.lead_score 4–6→ add to a nurture sequence, no immediate alert.lead_score <= 3or missing decision-making authority → log for marketing follow-up only.
Keep this routing logic outside the prompt — let Claude extract data, let your backend decide what to do with it.
Step 5: Stream the conversation for a better UX
Chat widgets feel sluggish without streaming. Add "stream": true to your request and consume server-sent events so the visitor sees Claude's reply forming in real time rather than waiting for the full response. Details on handling SSE chunks are in the streaming guide.
Step 6: Guard against bad data
Two practical additions that make a real difference:
- Re-ask on ambiguous answers. If a visitor says "maybe soon," instruct Claude in the system prompt to ask a clarifying follow-up rather than guessing a timeline.
- Cap the conversation length. Add a hard limit (e.g., 12 turns) after which the bot summarizes what it knows and submits whatever it has, scored accordingly. This avoids endless loops with visitors who won't give a straight answer.
Getting set up
If you don't already have Claude API access configured, sign up for a free trial, grab a sub_live_... key from the dashboard, and follow the quickstart to send your first request. The Messages API reference covers every parameter used above in full detail. Pricing for production use starts at Solo for €9/month, with Team and Scale plans adding seats as your sales team grows — see pricing.
Questions
Does Claude need fine-tuning to qualify leads accurately? No. A well-structured system prompt plus a tool definition for extraction is sufficient for most B2B qualification flows. Fine-tuning isn't necessary or available for this use case via the API.
How do I prevent the bot from making up lead data it wasn't told? Require all tool fields and instruct Claude explicitly to ask a follow-up question rather than infer missing fields. Reviewing a sample of real transcripts against submitted leads catches most drift early.
Can this run on an existing website chat widget? Yes — the conversation loop described above is backend logic. Any chat widget that can POST messages to your server and render streamed text can be wired to this flow with no changes to the widget itself.