API
Configuration
The hevAsk() integration is the default export of @hevmind/ask. It takes one
options object. Only collections is effectively required; everything else has
a default.
// astro.config.mjs
import hevAsk from "@hevmind/ask";
export default defineConfig({
integrations: [
hevAsk({
collections: ["docs"],
basePath: "/docs/",
model: "claude-haiku-4-5",
maxResults: 6,
}),
],
});
Options
| Option | Type | Default | Description |
|---|---|---|---|
collections | string[] | — | Content collection name(s) to index and search. Without it the endpoint errors and the integration warns at build. |
basePath | string | '/docs/' | Slug → URL prefix. A doc’s URL is basePath + slug, plus #anchor for a section. |
endpoint | string | '/api/ask' | Route the search endpoint is injected at. Must match the overlay’s endpoint prop if you change it. |
provider | string | 'anthropic' | Inference provider for the agentic loop and digest builder: 'anthropic', 'openai', or 'openrouter'. Each reads its own key: ANTHROPIC_API_KEY, OPENAI_API_KEY, or OPENROUTER_API_KEY. |
providerBaseUrl | string | per provider | API base URL override for the OpenAI-compatible providers, so any Chat Completions-compatible endpoint works (a proxy, a gateway, a local server). |
model | string | per provider | Model for the agentic search loop. Defaults: claude-haiku-4-5 (anthropic), gpt-4.1-mini (openai), anthropic/claude-haiku-4.5 (openrouter). |
digestModel | string | per provider | Model for the offline digest builder. Defaults: claude-opus-4-8 (anthropic), gpt-5.1 (openai), anthropic/claude-opus-4.8 (openrouter). |
maxResults | number | 6 | Source sections the AI answer may ground in and cite (the Sources footer size); also the keyword result row cap. |
answerMaxTokens | number | 1024 | Token budget for the streamed AI answer. |
maxIterations | number | 4 | Maximum search tool rounds before the model must stop searching and answer. |
chunkHeadingDepth | number | 3 | Deepest heading used as a chunk boundary. 2 = ##; 3 = ## and ###. |
candidatePerSearch | number | 8 | Chunks returned by each search tool call. |
perDocCap | number | 2 | Max chunks from one document returned by a single prefilter call. |
digestDir | string | '.hev-ask' | Path to the committed digest tree, relative to the site root. |
digestContentGlobs | string[] | derived | Globs the offline builder reads. Defaults to Markdown/MDX under each configured collection directory. |
Choosing a provider
provider selects who serves both the runtime loop and the offline digest
build. The search behavior, digest format, and endpoint contract are identical
across providers — only the model and the key env var change.
// astro.config.mjs — the default; reads ANTHROPIC_API_KEY
hevAsk({
collections: ["docs"],
// model defaults to claude-haiku-4-5
});// astro.config.mjs — reads OPENAI_API_KEY
hevAsk({
collections: ["docs"],
provider: "openai",
// model defaults to gpt-4.1-mini
});// astro.config.mjs — reads OPENROUTER_API_KEY
hevAsk({
collections: ["docs"],
provider: "openrouter",
model: "anthropic/claude-haiku-4.5", // or any OpenRouter model slug
}); OpenRouter is the widest door: one OPENROUTER_API_KEY reaches every model it
routes. providerBaseUrl opens the rest — any OpenAI-compatible Chat
Completions endpoint works with provider: "openai":
hevAsk({
collections: ["docs"],
provider: "openai",
providerBaseUrl: "https://my-gateway.example.com/v1",
model: "my-model",
});
Models in the agentic loop must support tool calling; the digest builder also needs forced tool choice. Current models from the major providers all qualify.
What the integration does
When Astro starts up (astro:config:setup) the integration:
- injects the
endpointroute, pointing at@hevmind/ask/endpoint, withprerender: falseso it renders on demand; - registers two virtual modules —
virtual:hev-ask/config(the resolved options) andvirtual:hev-ask/digest(the committed tree, globbed in); - adds the
digestDirtree as watched files so dev reloads when the digest changes; - warns if
collectionsis empty.
At build (astro:build:start) it runs the digest build when the provider’s key
(ANTHROPIC_API_KEY by default) is present (hash-gated, usually a no-op), and
otherwise logs a warning and proceeds with the committed artifact. The build
never fails for lack of a key.
TypeScript
The options type is exported for editor help and config typing:
import type { HevAskOptions } from "@hevmind/ask";
Tuning notes
- Chunk granularity: raise
chunkHeadingDepthto3(the default) for finer section anchors on long pages; drop to2if your###sections are too small to stand alone as results. - Latency: lower
maxIterationsto cap agentic round-trips; raise it if multi-part questions need more search rounds. - Result spread:
perDocCapkeeps one long page from filling the results; raise it if a single page legitimately holds most of the answers. - Recall vs. noise:
candidatePerSearchcontrols how many chunks each search hands the model — more candidates, more recall, more tokens.