Skip to main content

Build an API Documentation Bot

This guide walks you through building a developer-facing documentation bot using CET — a pipeline that answers code questions with exact snippets retrieved from your API docs. By the end you will have a live pipeline that:
  • Returns the correct code snippet for any SDK question
  • Understands follow-up questions in the same session (“what about rotating that key?”)
  • Stays under a tight token budget so every answer is concise and costs less

What You Will Build

A 5-node pipeline that retrieves relevant chunks from your API docs, injects conversation context, and produces code-first answers in under 150 words.

Step 1 — Prepare Your Knowledge Base

Good chunking is the foundation. Before uploading your docs, structure them so each section is self-contained. Recommended format for API docs:
Each section — one concept, one snippet — becomes one clean chunk. When sections bleed into each other, the retriever pulls incomplete context and the answer suffers. Upload settings to use:
Tip: After uploading, open the Knowledge Source detail page and preview the first 5 chunks. If a chunk ends mid-sentence or cuts a code block in half, your source document needs clearer section breaks.

Step 2 — Write the System Prompt

Open Pipelines → New Pipeline and add a System Prompt node. Use this template:
Token budget for this node: 200 tokens maximum.

Step 3 — Configure the RAG Node

Add a RAG node and connect it after the System Prompt node.
  • Knowledge source: select the API docs KB you uploaded in Step 1
  • Top-K: 3
  • Similarity threshold: 0.82
  • Max token allocation: 800 tokens
The RAG node retrieves the top 3 most relevant chunks from your KB and injects them into the context window before the LLM sees the user’s question.

Step 4 — Add the Chat History Node

Add a Chat History node and connect it between the RAG node and the LLM node. Why this matters: Without chat history, a follow-up question like “how do I rotate that key?” arrives with no context — the pipeline doesn’t know what “that key” refers to and retrieves the wrong chunks. With chat history, the previous exchange is in context and retrieval is accurate. Configuration: The keep strategy preserves the last 5 messages verbatim. For API docs bots where sessions are short and questions are precise, this is the right choice. See the Chat History Strategies guide for when to use summarize or truncate instead.

Step 5 — Configure the LLM Node

Add an LLM node after the Chat History node. Low temperature keeps answers deterministic — you want the same question to return the same snippet every time, not a creative variation. The Budget/RAG model is ideal here: high-volume doc lookups do not need the quality tier.

Step 6 — Test in the Playground

Open the Playground, select your new pipeline, and start a new session. Send these three questions in sequence without starting a new session:
What to look for:
  • Q1 should return an auth code block immediately, no prose introduction
  • Q2 should understand “that key” refers to the API key from Q1 — this confirms Chat History is working
  • Q3 should return the full paginated function leading with the code block
If Q2 returns a generic answer unrelated to API keys, check that the Chat History node is connected and the window size is at least 3 messages.

Token Budget Breakdown

This pipeline costs roughly $0.002–$0.004 per query on the Budget/RAG model — well under 1 cent per question.