Skip to main content
This tutorial walks through building an AI chatbot that can answer questions about the Urantia Book with accurate citations, using the Urantia Papers API for retrieval and OpenAI for generation.

Architecture

The chatbot follows the RAG (Retrieval-Augmented Generation) pattern:
  1. User asks a question about the Urantia Book
  2. Search the Urantia Papers API for relevant passages
  3. Retrieve context around the top results
  4. Generate an answer using an LLM with the retrieved passages as context
  5. Return the answer with source citations

Prerequisites

  • Node.js 18+ or Python 3.10+
  • An OpenAI API key (for the LLM)
  • No Urantia API key needed (it’s free and open)

Step 1: Search for Relevant Passages

The search endpoint supports three modes:
  • and — All words must appear (best for specific queries)
  • or — Any word can appear (best for broad exploration)
  • phrase — Exact phrase match (best for quoting)

Step 2: Get Surrounding Context

The context endpoint is critical for RAG quality. A single paragraph often lacks the full meaning — surrounding paragraphs provide narrative flow.
The window parameter (1-10) controls how many paragraphs before and after the target are included.

Step 3: Build the Prompt

Step 4: Generate the Answer

Step 5: Add Streaming (Optional)

For a better user experience, stream the response:

Tips for Better Results

  1. Use type: "and" for specific questions and type: "or" for exploratory ones
  2. Increase the context window for complex topics — window=5 gives broader narrative context
  3. Search with key terms from the Urantia Book’s vocabulary (e.g., “Thought Adjuster” instead of “inner spirit”)
  4. Filter by paper when you know the relevant section — use the paperId parameter
  5. Lower the temperature (0.2-0.4) for factual accuracy; raise it (0.6-0.8) for more creative explanations

Full Example (Python)

Next Steps

  • Add conversation history for multi-turn chat
  • Implement a web UI with React or Next.js
  • Add audio playback for cited passages using the /audio endpoint
  • Deploy as a Telegram or Discord bot

AI Agent Integration Guide

See the full recommended workflow for AI agent integration.