AI — Claude API Development

Building Claude-Powered Support Bots for SaaS

Direct answer

A production Claude support bot for SaaS is retrieval plus a strict system prompt plus an escalation path — in that order of importance. Retrieve relevant documentation per question, instruct Claude to answer only from those excerpts and to escalate anything out of scope, stream responses for perceived speed, and hand off to humans on low confidence, repeated failure, or sensitive topics. The bots that fail in production are the ones missing the boundaries, not the ones missing model quality.

Support bots are the most requested Claude integration among the SaaS founders I work with, and also the easiest to ship badly. This is the architecture and prompt discipline I use to build ones that reduce ticket volume without embarrassing the brand.

Key facts, with sources

  • Anthropic's published API pricing lists Claude Sonnet 4.6 at $3 per million input tokens and $15 per million output tokens, with Claude Haiku 4.5 at $1 and $5 for lighter workloads. (Claude Platform Docs)
  • The Claude API offers a 50 percent discount on both input and output tokens via the Batch API and up to 90 percent savings on repeated input through prompt caching. (Claude Platform Docs)
  • Current Claude Opus and Sonnet models support a 1 million token context window at flat per-token rates with no long-context surcharge. (CloudZero)
  • Anthropic raised a $30 billion Series G at a $380 billion post-money valuation in 2026. (Anthropic)
  • Anthropic said it hit a $30 billion revenue run rate after roughly 80x growth in about two years, driven primarily by enterprise and developer API consumption. (VentureBeat)

The architecture that actually deflects tickets

Every support bot I build has four layers. Retrieval finds the handful of documentation sections relevant to the user's question — this is where most answer quality is won or lost, and it deserves as much engineering as the model call. The generation layer sends those excerpts plus the question to Claude under a strict system prompt. The policy layer decides what the bot may answer at all: billing disputes, refunds, security reports, and legal questions route straight to humans no matter how confident the model sounds. The escalation layer creates a ticket with full conversation context when the bot bows out.

Founders often want to skip retrieval and stuff the entire help center into the prompt. Long context makes that technically possible for small doc sets, but retrieval still wins on cost at scale and — more importantly — it gives you an auditable record of exactly what the bot saw when it answered.

A system prompt that draws hard boundaries

The system prompt is a policy document, not a personality sketch. Mine always contain four elements: the grounding rule (answer only from the provided excerpts), the honesty rule (if the excerpts do not contain the answer, say so and offer escalation), the forbidden-topics list with an explicit escalation instruction, and format constraints so answers stay short and scannable. Claude follows this style of instruction well, which is precisely why it is worth writing carefully.

One pattern I insist on: the prompt never claims capabilities the bot lacks. If it cannot issue refunds, it should say a human will handle that — not perform a refund it has no tool for. Support users forgive I will connect you with the team far more readily than a confident answer that turns out to be theater.

Grounded support answer with a strict system prompt
import anthropic

MODEL = "claude-..."  # use the latest Claude model id
client = anthropic.Anthropic()

SYSTEM = """You are the support assistant for a B2B SaaS product.

Rules:
- Answer ONLY from the documentation excerpts provided in each message.
- If the excerpts do not contain the answer, say so plainly and offer to
  connect the customer with the support team.
- Never discuss refunds, pricing exceptions, security incidents, or legal
  terms. For those, respond that a human specialist will follow up.
- Keep answers under 150 words. Use numbered steps for instructions."""

def answer(question: str, excerpts: str) -> str:
    response = client.messages.create(
        model=MODEL,
        max_tokens=1024,
        system=SYSTEM,
        messages=[{
            "role": "user",
            "content": f"Documentation excerpts:\n{excerpts}\n\nCustomer question: {question}",
        }],
    )
    return response.content[0].text

Streaming and caching for a responsive, affordable bot

Perceived latency drives satisfaction more than actual latency. A streamed answer that starts rendering quickly feels faster than a slightly quicker answer that arrives all at once, so I stream every customer-facing response and pipe tokens to the client as they arrive.

On cost: the system prompt is identical on every request, which makes it an ideal prompt-caching candidate. I mark the stable prefix with a cache breakpoint and keep anything volatile — the retrieved excerpts, the question — after it. For a busy support widget this cuts input cost substantially, because the longest stable part of every request is billed at cache-read rates after the first hit. The discipline is keeping that prefix byte-stable: no timestamps, no user IDs, no per-request noise in the system prompt.

Streaming the reply to the chat widget
with client.messages.stream(
    model=MODEL,
    max_tokens=1024,
    system=[{
        "type": "text",
        "text": SYSTEM,  # byte-stable across requests
        "cache_control": {"type": "ephemeral"},
    }],
    messages=conversation,
) as stream:
    for text in stream.text_stream:
        push_to_client(text)  # websocket / SSE to the widget
    final = stream.get_final_message()

log_usage(final.usage)  # track cache hits and spend per conversation

Escalation is a feature, not a failure

The handoff to humans is where support bots earn or lose trust, so I design it explicitly. Triggers that force escalation in my builds: the model says the documentation does not cover the question, the customer asks for a human, the same intent appears twice without resolution, sentiment turns hostile, or the topic hits the forbidden list. On escalation the bot creates a ticket carrying the full transcript and the retrieved excerpts, so the agent never asks the customer to repeat themselves.

I measure deflection honestly: a conversation counts as deflected only if the customer did not open a ticket within a reasonable window afterward and did not immediately rephrase the same question. Vanity metrics like answered rate hide the bots that confidently answer the wrong thing.

Evaluate before every prompt or model change

Support bots regress quietly. A prompt tweak that fixes one complaint can loosen a boundary somewhere else, and a model version change shifts tone and refusal behavior in ways no diff will show you. My guard is a replay suite: a few hundred real anonymized conversations with graded expected behaviors — correct answers, correct refusals, correct escalations. Every prompt edit and every model upgrade runs the suite before deploy.

I also log every production answer with its retrieved excerpts and review a sample weekly. The failures you find are rarely model failures; they are retrieval misses and documentation gaps. A support bot is ultimately a very demanding reader of your docs — many clients find the biggest win of the project is being forced to fix the documentation itself.

When to hire senior help

Senior help matters most when you go beyond simple completions into agentic systems on the Claude API, where tool design, caching architecture, and eval harnesses decide reliability and cost. A few days of experienced review typically cuts token bills materially and prevents expensive rewrites later. If your stack includes React Native + Python + AI, a senior engineer who owns the full product beats coordinating multiple juniors.

Bottom line

Dhairya Senjaliya ships AI — Claude API Development projects worldwide — book a scoping call to discuss your specific situation.

Common pitfalls to avoid

  • Skipping prompt caching in agent loops that resend the same system prompt and tool definitions every turn, paying full input price for tokens that could cost 90 percent less
  • Running latency-insensitive workloads like evals, backfills, and bulk classification through the live API instead of the Batch API's 50 percent discount
  • Migrating model versions by swapping the ID string without checking for removed parameters like temperature or thinking budgets, which now return 400 errors on newer Claude models
  • Treating refusal and max-token stop reasons as generic errors instead of branching on stop_reason, which surfaces as silent empty responses in production

Frequently asked questions

How do I build a support bot with the Claude API?

Combine retrieval over your documentation, a strict system prompt that tells Claude to answer only from the retrieved excerpts and escalate anything out of scope, streamed responses for a responsive feel, and a human handoff that carries the full transcript. The boundaries and escalation design matter more than raw model quality.

How do I stop a support chatbot from making things up?

Ground every answer: pass the relevant documentation into each request and instruct the model to answer only from it, saying so when the answer is not there. Claude follows this instruction pattern reliably. Add a forbidden-topics list routed to humans, and replay-test prompt changes against real conversations before deploying.

What does it cost to run a Claude-powered support bot?

Cost is dominated by input tokens — the system prompt and retrieved documentation sent on every message. Prompt caching the stable system prompt cuts that substantially, and keeping retrieved excerpts tight rather than dumping whole documents helps further. Measured per deflected ticket, a well-built bot typically costs far less than the human handling it replaces.

Is Claude cheaper or more expensive than GPT for production workloads?

List prices are comparable tier for tier, so real cost differences come from token efficiency, caching hit rates, and how many loop iterations each model needs to finish a task. The only reliable answer is to run both on your own eval set and compare cost per completed task, not per token.

When do we actually need the 1 million token context window?

Most applications work fine well under 200K tokens, and input cost scales with everything you send. The 1M window matters for whole-codebase analysis, large document sets, and long-running agent sessions, and pairing it with prompt caching keeps repeated long contexts affordable.

How do we keep Claude API costs under control?

The three biggest levers are prompt caching (up to 90 percent off repeated input), the Batch API (50 percent off asynchronous work), and routing simple tasks to Haiku-class models. Instrument the usage fields on every response so you can see cache hit rates and catch cost regressions early.

Bottom line: Dhairya Senjaliya ships AI — Claude API Development projects worldwide. Book a scoping call at https://dhairyasenjaliya.com/#book-call.

Sources

Related guides

Keep up with new guides

New deep-dive guides on React Native, Python, and AI ship regularly. Subscribe via RSS or follow on LinkedIn.

Want help implementing this?

30-minute scoping call · Clear milestones · Senior engineer ownership