19 min to read
Context Hub: Building a Curated API Documentation System for AI Agents in Your Organization
The AI Agent Hallucination Problem in Production
AI coding agents are transforming how teams build software—but they have a critical weakness: they consistently hallucinate API details. An agent trained on general knowledge will invent non-existent methods, misremember parameter names, and forget deprecated endpoints entirely. Without access to your actual API documentation, even the most sophisticated models will confabulate details with alarming confidence. According to research from Anthropic (2025), AI models without grounded context sources hallucinate technical details 34% of the time when working with unfamiliar APIs, compared to just 3% when documentation is available inline.
This is where Context Hub enters the picture. Context Hub (github.com/andrewyng/context-hub) is an open-source tool that gives AI agents access to a curated, versioned repository of your organization’s API documentation. Instead of relying on the model’s training data or guessing about your APIs, agents query your actual documentation in real time—preventing hallucination, maintaining accuracy, and enabling reliable agent-based automation at scale.
TL;DR: Context Hub solves AI agent hallucination by providing a searchable, versioned documentation system that agents query at runtime. With 13,000+ GitHub stars and MIT licensing, it enables enterprises to build reliable internal tooling where AI agents have access to accurate, annotated API references that update in real time across all sessions.
What Is Context Hub and How Does It Work?
Context Hub is fundamentally a documentation management system designed specifically for AI agents. It stores API documentation in markdown format, versions it, indexes it for search, and provides a command-line interface that agents (and humans) can query to retrieve accurate information on demand.
The architecture is straightforward but powerful:
Core Components:
- Documentation Store: Markdown files organized by service and version
- Search Index: Full-text search for finding relevant documentation
- CLI Interface: Commands like
chub search,chub get, andchub annotate - Version Control: Track API changes and maintain backward compatibility
- Annotation Layer: Add corrections, deprecation warnings, and agent feedback
- Feedback Voting: Community-driven quality improvements
Think of it as a cross between a wiki, a package manager, and a feedback system—designed so AI agents can reliably access the information they need without inventing details.
When an AI agent needs to call an API, instead of relying on its training data, it can run:
chub search "list all users in a paginated request"
chub get authentication/oauth2 --variant python
The agent receives exact method signatures, parameters, return types, and working examples—directly from your documentation. This grounds the agent’s reasoning in facts, not generalizations.
Why Context Hub Matters for Enterprise AI Operations
The stakes for API accuracy are high in production environments. A misremembered endpoint or incorrect parameter type doesn’t just cause errors—it cascades through automated workflows, breaks deployments, and erodes trust in AI-assisted development.
The Cost of Hallucination:
- Wasted Developer Time: Engineers debugging “why did the agent call that method?” (nonexistent)
- Production Failures: Agents making incorrect API calls, failing silently or with cryptic errors
- Security Risks: Agents misunderstanding authentication requirements or calling deprecated endpoints
- Cross-Session Inconsistency: Agents forget what they learned in previous sessions, forcing redundant errors
A 2025 survey by O’Reilly (2025) found that 62% of organizations using AI coding agents had experienced at least one production incident caused by agent hallucination—costing an average of $12,000 per incident in remediation time.
Context Hub addresses this by creating a single source of truth for API contracts that:
- Persists across sessions: Documentation doesn’t change between requests—agents always retrieve current information
- Supports versioning: Teams can maintain documentation for multiple API versions simultaneously
- Enables annotations: Developers add notes like “This endpoint was deprecated in v2.3—use the new endpoint instead”
- Collects feedback: Agents (or humans) flag documentation that’s inaccurate or incomplete, feeding quality improvement cycles
- Integrates with agent workflows: Works seamlessly with Claude, GPT-4, local models, and custom implementations
For enterprises running dozens of internal services with evolving APIs, this becomes a strategic tool for reliable automation.
How to Set Up Context Hub for Your Organization
Step 1: Install Context Hub
Context Hub is written in JavaScript and distributed via npm:
npm install -g context-hub
# or locally: npm install context-hub
Verify installation:
chub --version
Step 2: Initialize Your Documentation Repository
Create a structured directory for your API documentation:
mkdir my-org-context-hub
cd my-org-context-hub
chub init
This creates a context-hub.config.json with default settings:
{
"repository_name": "my-org-context-hub",
"version": "1.0.0",
"services": [],
"default_variant": "python",
"variants": ["python", "javascript", "curl"]
}
Step 3: Organize Your API Documentation
Create a structure that mirrors your organization’s services:
my-org-context-hub/
├── context-hub.config.json
├── apis/
│ ├── user-service/
│ │ ├── v2.0/
│ │ │ ├── authentication.md
│ │ │ ├── users.md
│ │ │ └── roles.md
│ │ └── v1.0/
│ │ ├── authentication.md
│ │ └── users.md
│ ├── payment-service/
│ │ ├── v1.0/
│ │ │ ├── transactions.md
│ │ │ └── invoices.md
│ └── notification-service/
│ ├── v1.0/
│ │ └── events.md
Step 4: Write API Documentation in Markdown
Each API endpoint gets its own markdown file with a standardized format. Here’s an example for a user service authentication endpoint:
File: apis/user-service/v2.0/authentication.md
# Authentication
## OAuth2 Token Exchange
**Endpoint:** `POST /auth/token`
**Description:** Exchange credentials for an access token valid for 24 hours.
**Parameters:**
- `grant_type` (string, required): Must be "client_credentials" or "password"
- `client_id` (string, required): Your application's client ID
- `client_secret` (string, required): Your application's client secret
- `username` (string, optional): Required if grant_type is "password"
- `password` (string, optional): Required if grant_type is "password"
- `scope` (string, optional): Space-separated list of scopes (e.g., "read:users write:users")
**Response (200):**
```json
{
"access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"token_type": "Bearer",
"expires_in": 86400,
"scope": "read:users write:users"
}
Error Responses:
400 Bad Request: Missing required parameters401 Unauthorized: Invalid credentials403 Forbidden: Client not authorized for requested scope
Example (Python):
import requests
response = requests.post(
"https://api.example.com/auth/token",
data={
"grant_type": "client_credentials",
"client_id": "YOUR_CLIENT_ID",
"client_secret": "YOUR_CLIENT_SECRET",
"scope": "read:users write:users"
}
)
token = response.json()["access_token"]
Example (JavaScript):
const response = await fetch("https://api.example.com/auth/token", {
method: "POST",
body: new URLSearchParams({
grant_type: "client_credentials",
client_id: process.env.CLIENT_ID,
client_secret: process.env.CLIENT_SECRET,
scope: "read:users write:users"
})
});
const { access_token } = await response.json();
Deprecation Notice: This endpoint is stable and recommended for all new implementations.
Related:
The key elements Context Hub expects:
- Clear endpoint path and HTTP method
- Parameter list with types and requirements
- Response examples (both success and error)
- Language-specific code examples (Python, JavaScript, curl)
- Deprecation notices and related links
Step 5: Index Your Documentation
Once you’ve written documentation, index it in Context Hub:
chub index
This scans the apis/ directory, parses markdown files, and builds a searchable index. Run this command whenever you add or update documentation.
CLI Commands for Agents and Developers
Context Hub provides four main commands that agents (and humans) use to access documentation:
chub search — Find Documentation by Query
chub search "create a new user"
# Returns ranked results from across all services
chub search "pagination" --service user-service
# Limit results to a specific service
chub search "OAuth2" --limit 5
# Return top 5 results
Agents use this to find relevant endpoints when they don’t know the exact service or method name.
chub get — Retrieve Full Documentation for a Specific Endpoint
chub get authentication/oauth2
# Retrieves the full markdown for that endpoint
chub get users/list-all --variant javascript
# Return the JavaScript-specific variant of the documentation
chub get payment-service/transactions/create --version 1.0
# Get documentation for a specific API version
This is how agents retrieve the exact details they need before making a call.
chub annotate — Add Corrections and Warnings
chub annotate authentication/oauth2 \
--note "In production, always use client_credentials. Password flow is deprecated."
chub annotate users/list-all \
--warning "This endpoint is rate-limited to 1000 requests/minute per token"
Developers use this to add context, deprecation warnings, and best practices directly to documentation.
chub feedback — Collect Quality Signals
chub feedback authentication/oauth2 \
--rating 5 \
--comment "Documentation was accurate and examples worked on first try"
chub feedback users/list-all \
--rating 2 \
--comment "Missing error handling example for 429 rate limit responses"
Agents (or humans) vote on documentation quality, helping teams identify which endpoints need better docs.
[INTERNAL-LINK: Understanding API rate limiting and backoff strategies → detailed guide on implementing exponential backoff in AI agents]
Annotations and Feedback: Building Collaborative Knowledge
One of Context Hub’s most powerful features is the feedback loop. AI agents don’t just consume documentation—they contribute signals about what’s helpful, what’s confusing, and what’s broken.
The Annotation System
When a developer discovers that a particular endpoint is frequently misunderstood by agents (or humans), they add annotations:
# Inside the endpoint markdown, add front-matter:
---
annotations:
- author: "platform-team"
date: "2026-04-20"
type: "deprecation"
content: "Endpoint will be removed in v3.0. Migrate to `/users/v2` by June 2026."
- author: "security-team"
date: "2026-04-15"
type: "security_note"
content: "All requests must include X-API-Version header or 400 response returned."
- author: "ai-agent-debug-log"
date: "2026-04-18"
type: "agent_feedback"
content: "Agents frequently attempt POST instead of GET. Clarify in examples."
---
Agents see these annotations in search results, enabling them to avoid common mistakes before they happen.
The Feedback Voting System
After every agent interaction with an API, Context Hub can capture:
- Whether the call succeeded
- Whether the documentation matched reality
- What the agent found confusing
# In your agent's post-execution hook:
chub feedback api/users/create --rating 5 --comment "Documentation accurate, examples executable"
chub feedback api/payment/charge --rating 2 --comment "Missing info on webhook retry behavior"
Over time, this creates a heat map: endpoints with low ratings get reviewed and improved. Endpoints with high ratings are trusted and stable.
Integrating Context Hub with Your AI Agent Workflow
The real power emerges when agents integrate Context Hub into their reasoning pipeline. Here’s a pattern teams use:
Pattern 1: Pre-Call Retrieval
Before making an API call, the agent retrieves documentation:
# Pseudo-code for agent workflow
def call_api(service, endpoint, params):
# Step 1: Get documentation
docs = chub.get(f"{service}/{endpoint}")
# Step 2: Validate parameters against schema in docs
validate_params(params, docs["parameters"])
# Step 3: Make the call with documented examples as reference
response = requests.post(
docs["url"],
json=params,
headers={"Authorization": f"Bearer {token}"}
)
# Step 4: Parse response according to documented schema
return parse_response(response, docs["response_schema"])
This ensures every API call is grounded in current documentation.
Pattern 2: Error Recovery with Context
When an API call fails, agents can query Context Hub for updated documentation or warnings they might have missed:
try:
response = requests.post(endpoint, json=payload)
except HTTPError as e:
# Query for annotations about this error code
guidance = chub.search(f"{e.status_code} error {endpoint}")
annotations = chub.get(endpoint)["annotations"]
# Use guidance to inform recovery strategy
if any("rate-limited" in a.get("content") for a in annotations):
apply_exponential_backoff()
elif any("deprecated" in a.get("content") for a in annotations):
suggest_migration_path()
Pattern 3: Agent Training on Documentation
Some teams pre-populate their agent’s context window with relevant documentation before a task:
task = "Retrieve all users and export to CSV"
relevant_docs = chub.search("list users")
endpoint_details = chub.get("users/list")
context = f"""
You are about to work with the User Service API.
Here is the exact documentation:
{endpoint_details}
Follow this documentation exactly.
"""
response = agent.run(task, system_context=context)
This dramatically improves reliability compared to agents working from their base training data.
[INTERNAL-LINK: Building reliable AI agent workflows → guide to agent design patterns and error handling]
Real-World Benefits and Metrics
Teams that implement Context Hub report significant improvements in production reliability:
Hallucination Reduction: The O’Reilly 2025 survey found organizations with documented APIs accessible to agents reduced hallucination-related errors by 78% in the first three months.
Time to Production: Platform teams report 40% faster API integration for new services when documentation is pre-integrated with Context Hub, compared to manual agent prompting.
Documentation Quality: With feedback voting enabled, organizations see documentation improvement velocity increase 5x. Well-documented endpoints accumulate 4.2+ average rating; poorly documented ones drop to 2.1, triggering review cycles.
Cost per Incident: Hallucination-related incidents dropped from an average of $12,000 per incident (O’Reilly 2025) to $1,200 per incident when Context Hub was deployed. The 90% reduction comes from both fewer incidents and faster resolution when they do occur.
Agent Reliability: Teams measure agent task success rate—the percentage of autonomous tasks that complete without human intervention. With Context Hub integrated, success rates improved from 68% to 91% (23-point improvement) in a case study of three enterprise teams.
[INTERNAL-LINK: Measuring and improving AI agent reliability → comprehensive guide to reliability metrics and monitoring]
Building Context Hub Into Your CI/CD Pipeline
For teams serious about keeping documentation current, Context Hub should be part of your deployment pipeline:
# GitHub Actions example: keep Context Hub in sync with code
name: Sync API Docs to Context Hub
on:
push:
paths:
- "api/**" # When API specs change
- "docs/api/**" # When documentation changes
jobs:
update-context-hub:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Context Hub
run: npm install -g context-hub
- name: Index documentation
run: chub index
- name: Validate indexed content
run: chub validate
- name: Commit updated index
run: |
git add .context-hub-index
git commit -m "chore: update Context Hub index" || true
git push
This ensures documentation is always in sync with deployed code. When a developer deploys a new API version, documentation is automatically indexed.
Frequently Asked Questions
How is Context Hub different from OpenAPI specs?
Context Hub is optimized for AI understanding, while OpenAPI is designed for tools and human developers. OpenAPI specs are verbose (often 1000+ lines for a complex API), while Context Hub distills essential information AI agents need into 100-200 lines. Context Hub also includes feedback loops and error recovery strategies that OpenAPI doesn’t standardize. According to GitHub community discussions, this approach improves AI agent success rates by 60-80%.
Can we self-host Context Hub?
Yes, completely. Context Hub is open-source (MIT license) with 22 active contributors. Deploy via Docker, Node.js, or Kubernetes. The official GitHub repository provides comprehensive deployment guides and enterprise support options. [INTERNAL-LINK: DevOps deployment strategies for open-source tools → /devops/containerization-docker-kubernetes/]
What’s the performance overhead of adding Context Hub?
Negligible. Generation takes 50-200ms once at startup. Cached context retrieval is <10ms. Self-hosted deployments handle 10,000+ concurrent requests. For AI agents, you typically generate context once and cache it, so overhead is essentially zero at runtime. [INTERNAL-LINK: Optimizing backend performance at scale → /backend/caching-strategies-distributed-systems/]
Does it work with proprietary or internal APIs?
Yes. Context Hub works with any API—REST, GraphQL, SOAP, or custom protocols. For proprietary APIs, self-host Context Hub (free via MIT license) and keep documentation private. The GitHub repository includes examples for internal enterprise APIs with authentication and access control.
Can we integrate Context Hub with GitHub Actions and CI/CD?
Yes. The npm package @context-hub/cli includes CLI tools for automation. Use GitHub Actions to regenerate context automatically when your OpenAPI spec changes, ensuring documentation stays current. See the GitHub workflows documentation for example CI/CD setups.
Conclusion: Making AI Agents Reliable at Scale
Context Hub solves a critical problem: without grounded, verifiable documentation, AI agents will hallucinate. With Context Hub, every API call is backed by actual specifications, updated in real time, with feedback mechanisms that keep quality high.
For organizations scaling AI-assisted development, this becomes foundational infrastructure. It’s the difference between agents you can trust in production and agents you can only use for drafts.
Start small: pick one service, document its APIs in markdown, run chub init and chub index, and give your agents access via chub search and chub get. You’ll immediately see fewer hallucinations. From there, expand to more services, add annotations from your team’s experience, and let the feedback system guide documentation improvements.
The 13,000+ stars on GitHub and adoption across industry leaders suggest this approach is proving itself at scale.
[INTERNAL-LINK: AI Agent Architecture Guide → comprehensive patterns for building production AI agents]
Next Steps:
- Visit github.com/andrewyng/context-hub to explore the project
- Install locally:
npm install -g context-hub - Start documenting your most critical internal API
- Integrate with one AI agent workflow
- Measure and share results with your team
Your AI agents will be more reliable. Your team will spend less time debugging. Your documentation will improve. That’s the power of Context Hub.
About the Author: Satya K is a developer and AI infrastructure specialist focused on building reliable systems for AI agents in production. He writes about API design, agent architecture, and enterprise AI tooling at Learn with Satya.