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
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: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: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
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:- 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
Token Budget Breakdown
This pipeline costs roughly $0.002–$0.004 per query on the Budget/RAG model — well under 1 cent per question.
