← Blog

Building an Internal Knowledge Base Chatbot with Claude API

2026-11-24 · 5 min read · SubToAPI Team

What "Claude API internal knowledge base chatbot" actually means

If you're searching this, you're almost certainly trying to give your team (or your product's users) a chat interface that answers questions from your own documents — wikis, PDFs, Notion pages, support tickets, internal runbooks — instead of Claude's general training data. The short answer: you don't fine-tune Claude on your docs. You retrieve the relevant chunks of your knowledge base at query time and pass them into the prompt alongside the user's question, then let Claude generate a grounded answer. This pattern is called retrieval-augmented generation (RAG), and it's the standard way to build internal chatbots on top of any LLM API, Claude included.

The second thing people usually need to solve is access: how do you actually call Claude reliably from a backend service, with streaming responses, usage visibility, and more than one teammate able to use it without sharing a single login. That's an infrastructure problem separate from the retrieval logic, and it's where a layer like SubToAPI fits — it turns your Claude access into a real HTTPS API with application keys, streaming, and per-seat usage, so the chatbot you build isn't tied to one person's session.

Architecture of a knowledge base chatbot

A working internal chatbot has four parts:

  1. Ingestion — pull documents from your sources (Confluence, Google Drive, Notion, a database) and split them into chunks small enough to fit in a prompt.
  2. Retrieval — given a user question, find the most relevant chunks. This is usually vector search, but keyword search or a hybrid of both works fine for smaller knowledge bases.
  3. Generation — send the retrieved chunks plus the question to Claude with a system prompt that tells it to answer only from the provided context.
  4. Delivery — expose this as a chat endpoint your team's tools (Slack bot, internal dashboard, support widget) can call, with streaming so answers feel responsive.

This article focuses on steps 3 and 4 — the prompt design and the API delivery layer. If you need the vector search piece in depth, that's a separate concern from how you talk to Claude, but the short version is: embed your chunks once, embed the incoming question, do a similarity search, and pull the top 3–8 chunks into the prompt.

Writing a grounded system prompt

The single biggest failure mode of internal chatbots is confident, wrong answers — Claude filling gaps with general knowledge instead of saying "I don't know." You fix most of this with the system prompt, not with more context:

You are an internal support assistant for Acme Corp.
Answer the user's question using ONLY the context below.
If the answer is not in the context, say you don't have
that information and suggest who to ask internally.
Always cite which document a fact came from.

Context:
{{retrieved_chunks}}

Keep the context block tightly scoped — dumping your entire wiki into every request wastes tokens and makes Claude more likely to blend unrelated facts. Retrieval quality matters more than prompt cleverness here.

Calling Claude for each turn

Once you have the retrieved chunks, the request itself is a normal Messages call. Here's what that looks like against SubToAPI's Claude-compatible endpoint:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "max_tokens": 600,
    "system": "You are an internal support assistant for Acme Corp. Answer only from the context below. Context: [retrieved chunks here]",
    "messages": [
      {"role": "user", "content": "How do I reset a customer'\''s SSO config?"}
    ]
  }'

For a chat UI, you'll want to stream the response token by token rather than wait for the full answer — see /docs/streaming for the event format. A minimal JavaScript handler:

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-sonnet-4",
    max_tokens: 600,
    stream: true,
    system: systemPromptWithContext,
    messages: [{ role: "user", content: question }]
  })
});

for await (const chunk of res.body) {
  process.stdout.write(decodeChunk(chunk));
}

Full request/response shapes are in /docs/messages and the basic setup is in /docs/quickstart.

Multi-turn conversations and memory

Internal chatbots rarely stay single-turn — someone asks a follow-up like "what about staging?" that only makes sense with prior context. Keep the conversation as a running array of {role, content} messages and re-run retrieval on each new user turn, not just the first one, since follow-ups often need different chunks than the original question. Append the latest assistant turn and new retrieved context, then send the whole array back to Claude. Trim older turns once you approach the model's context window rather than letting the conversation grow unbounded.

Tool use for live lookups

Sometimes "knowledge" isn't static documents — it's a live system: a ticket status, an account record, a deploy log. For that, Claude's tool use lets the model call a function (e.g., lookup_ticket(id)) mid-conversation instead of relying only on pre-retrieved text. This is worth adding once your chatbot moves past static docs; see /docs/tools for how tool definitions and tool_use/tool_result turns work.

Access, usage, and team rollout

Once the chatbot works for you, the next question is always "how does the rest of the team use this without me being the bottleneck." Each service calling the API (the Slack bot, the internal dashboard, the support tool) should have its own key so you can see which one is generating cost and traffic, and rotate one without breaking the others. SubToAPI gives each application a sub_live_... key, tracks usage per key, and supports team seats so multiple engineers can manage the integration from one dashboard instead of sharing credentials. Plans start at Solo (€9) for a single integration up to Team (€19/seat) and Scale (€49/seat) for larger rollouts — see /pricing, or start with a free trial at /signup.

Testing before you ship it internally

Before rolling out to the whole team:

questions

Do I need to fine-tune Claude on my company documents? No. Retrieval-augmented generation — fetching relevant chunks at query time and feeding them into the prompt — works better for most internal knowledge bases and avoids retraining every time docs change.

How do I stop the chatbot from making up answers? Constrain the system prompt to answer only from provided context, require it to say when information isn't available, and keep retrieved context tightly scoped rather than overloading the prompt with irrelevant chunks.

How do multiple internal tools share one Claude integration? Give each tool its own application API key so usage and errors are traceable per integration, rather than one shared credential. SubToAPI supports this with per-application keys and team seats under one dashboard — see /docs for setup 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 →