---
title: "Ask AI"
description: "Add a RAG-powered AI chat to your documentation"
canonical_url: "https://docs.farming-labs.dev/docs/customization/ai-chat"
markdown_url: "https://docs.farming-labs.dev/docs/customization/ai-chat.md"
last_updated: "2018-10-20"
agent:
  tokenBudget: 1200
  task: "Enable Ask AI with an explicit provider, retrieval path, and secret-handling model."
  outcome: "A docs question returns a grounded streamed answer with citations from the configured documentation corpus."
  appliesTo:
    framework:
      - "nextjs"
      - "tanstackstart"
      - "sveltekit"
      - "astro"
      - "nuxt"
    version:
      - ">=0.2.60"
    package:
      - "@farming-labs/docs"
  prerequisites:
    - "A working docs runtime and searchable content are already available."
    - "The selected provider credentials are stored in environment variables rather than committed config."
    - "Decide whether the browser may call the provider directly or must use a same-origin server proxy."
  files:
    - "docs.config.ts"
    - "docs.config.tsx"
    - "src/lib/docs.config.ts"
    - ".env.local"
  sideEffects:
    - "Ask AI can send questions and retrieved documentation to the configured model provider."
    - "Enabling feedback or analytics can store additional interaction metadata."
  verification:
    - description: "Ask a question answered by one known page."
      expect: "The response streams successfully, cites the expected page, and does not expose provider credentials to the browser."
  rollback:
    - "Set ai.enabled to false and remove provider credentials and any custom chat route added for the integration."
  failureModes:
    - symptom: "The answer is plausible but cites no documentation."
      resolution: "Verify the search provider, maxResults, MCP endpoint when useMcp is enabled, and the selected page's machine-readable content."
    - symptom: "The browser reports an authentication or CORS error."
      resolution: "Move secret-bearing requests behind the same-origin docs API or configure the documented browser-safe Docs Cloud path."
---

<!-- farming-labs:agent-contract:start -->
## Agent Contract

Task: Enable Ask AI with an explicit provider, retrieval path, and secret-handling model.
Outcome: A docs question returns a grounded streamed answer with citations from the configured documentation corpus.

### Applies To

- Framework: `nextjs`, `tanstackstart`, `sveltekit`, `astro`, `nuxt`
- Version: `>=0.2.60`
- Package: `@farming-labs/docs`

### Prerequisites

- A working docs runtime and searchable content are already available.
- The selected provider credentials are stored in environment variables rather than committed config.
- Decide whether the browser may call the provider directly or must use a same-origin server proxy.

### Files

- `docs.config.ts`
- `docs.config.tsx`
- `src/lib/docs.config.ts`
- `.env.local`

### Side Effects

- Ask AI can send questions and retrieved documentation to the configured model provider.
- Enabling feedback or analytics can store additional interaction metadata.

### Verification

- Ask a question answered by one known page.
  - Expected: The response streams successfully, cites the expected page, and does not expose provider credentials to the browser.

### Rollback

- Set ai.enabled to false and remove provider credentials and any custom chat route added for the integration.

### Failure Modes

- The answer is plausible but cites no documentation. — Recovery: Verify the search provider, maxResults, MCP endpoint when useMcp is enabled, and the selected page's machine-readable content.
- The browser reports an authentication or CORS error. — Recovery: Move secret-bearing requests behind the same-origin docs API or configure the documented browser-safe Docs Cloud path.
<!-- farming-labs:agent-contract:end -->

# Ask AI

## Ask AI task

Task: Enable Ask AI with an explicit provider, retrieval path, and secret-handling model.

Expected result: A docs question returns a grounded streamed answer with citations from the configured documentation corpus.

## Ask AI prerequisites

- A working docs runtime and searchable content are already available.
- The selected provider credentials are stored in environment variables rather than committed config.
- Decide whether the browser may call the provider directly or must use a same-origin server proxy.
- Applies to framework nextjs, tanstackstart, sveltekit, astro, nuxt; version >=0.2.60; package @farming-labs/docs.

## Ask AI verification

- Ask a question answered by one known page. Expected: The response streams successfully, cites the expected page, and does not expose provider credentials to the browser.
- Failure: The answer is plausible but cites no documentation.
- Recovery: Verify the search provider, maxResults, MCP endpoint when useMcp is enabled, and the selected page's machine-readable content.
- Rollback: Set ai.enabled to false and remove provider credentials and any custom chat route added for the integration.

## Ask AI agent guidance

Configure top-level `ai` in `docs.config.ts` or `docs.config.tsx`, and keep provider credentials in
environment variables. Next.js reads `OPENAI_API_KEY` directly; TanStack Start, SvelteKit, and Astro
pass the server-only value through `src/lib/docs.server.ts`, while Nuxt reads it through Nitro.

Set `ai.useMcp: true` only when Ask AI should retrieve with `search_docs` from `mcp.route` (default
`/api/docs/mcp`). Success means a question answered by a known page streams and cites that page. If
the answer has no citation, check the search provider, `ai.maxResults`, MCP endpoint, and the page's
machine-readable content. Move credential-bearing requests behind the same-origin docs API when the
browser reports authentication or CORS errors; `staticExport: true` intentionally hides Ask AI.

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
