AI Chat
Add a documentation-aware AI chat with server-only Pi provider authentication.
Loading documentation…
AI Chat answers questions using the pages in your Heyo Docs site. It uses
Pi's provider catalog and supplies the
model with tools to search and read your documentation. Configure the provider
and model in heyo-docs.config.ts, then give the server endpoint credentials
for each request. The browser never receives the provider, model, or
authentication settings.
Add ai.chat to the site configuration. provider must be a lowercase Pi
provider identifier and model must be an available model identifier for that
provider. The official templates use OpenAI as the example:
Only provider and model are required in ai.chat. The endpoint must pass
authentication unless auth is configured here on the server.
| Setting | Default | Purpose |
|---|---|---|
provider | Required | A Pi provider identifier, for example openai. |
model | Required | A model identifier available from that provider. |
auth | Endpoint-provided | Optional server-only fallback authentication. |
variant | right | right shows a trigger; center shows a compact prompt at the bottom. |
icon | chat | Icon in the right trigger. |
text | AI Chat | Label in the right trigger. |
name | AI | Drawer title and assistant message label. |
placeholder | Ask AI about the docs | Text in both the center prompt and drawer composer. |
With variant: "center", submitting the compact prompt opens the drawer.
With variant: "right", the reader opens the drawer from its floating
trigger. The drawer remains available while readers move between pages.
Pass authentication to createAiChatResponse from the request handler when a
platform resolves secrets or credentials per request. This is the recommended
shape for API keys and platform bindings:
ai.chat.auth is an optional fallback for server-only configuration. Pi's
provider determines which authentication type is valid:
| Type | Use for |
|---|---|
api-key | Providers that accept a secret token: { type: "api-key", token }. |
oauth | Providers using a fresh access token: { type: "oauth", getAccessToken }. |
aws | Amazon Bedrock's AWS credential chain, with optional region or profile. |
bedrock-bearer | Amazon Bedrock bearer authentication, with token and optional region. |
The runtime checks that the provider supports the supplied authentication type. Keep all of these values on the server; the client receives only the chat label, icon, variant, name, and placeholder.
Use the optional server-only ai.authorize guard for authentication,
rate-limiting, or an abuse check. Return a Response to stop the request
before Heyo Docs resolves a provider or starts a stream:
The guard runs only in the request handler. Do not put browser-only session state or a provider secret in the public configuration.
The chat UI sends POST requests to /heyo-docs-internal/ai-chat. Add this
endpoint before enabling ai.chat; createAiChatResponse supplies the model
with the loaded documentation pages and streams its answer back to the UI.
Add this entry to the existing route array:
Then create app/routes/ai-chat.ts:
Create src/pages/heyo-docs-internal/ai-chat.ts:
Create app/heyo-docs-internal/ai-chat/route.ts:
For Cloudflare, read the secret from the Worker binding instead of
process.env, then pass it as the same api-key auth object. The generated
Cloudflare overlays read HEYO_DOCS_AI_API_KEY unless ai.chat.auth is
already configured; set the binding with Wrangler's secret management rather
than in wrangler.jsonc or client code.
Use a server environment variable, platform binding, or OAuth resolver for
credentials. Do not put an API key in client code or commit it to the
repository. The framework integrations remove provider, model, and auth
from the browser-side configuration; the endpoint retains what is needed to
call the provider.