**🤖 Agent skill** — `npx skills@latest add https://github.com/OpenSourceAGI/dev-tools-starter-agent --skill ask-ai-button` ([what it covers](../../skills/ask-ai-button/SKILL.md))
# ask-ai-button
An **Ask AI** button for docs sites. The visitor types a question, picks a
model, and a new tab opens in QwkSearch, Perplexity, Claude, ChatGPT, Gemini,
Grok, Copilot, Le Chat, Venice or Brave with the prompt already
filled in: the current page (as a link or as pasted Markdown) plus their
question. They can also just copy the prompt, or copy the page as Markdown.
Ships as a **dropdown** for a page header, a **floating action button**, or an
**inline panel**. Self-styled — no Tailwind or CSS import needed — and it picks
up Fumadocs' theme colors automatically.
Spun out of the Ask AI dropdown and copy button in
[`starter-templates/template-fumadocs`](../../starter-templates/template-fumadocs/).
## Install
```bash
bun add ask-ai-button # or: npm install ask-ai-button
```
`react` and `react-dom` 18+ are peers.
## Usage
```tsx
import { AskAIButton, CopyPageButton } from "ask-ai-button";
// Dropdown, e.g. under a Fumadocs page title
// Floating action button, once in your layout
// same as variant="fab"
// Inline panel, anywhere in the page
```
The components are client components (the bundle starts with `"use client"`),
so they can be rendered straight from a Next.js server component.
### What gets sent
The panel has a **Link to page / Include page text** toggle:
| Mode | Prompt |
| --- | --- |
| `link` *(default with `markdownUrl`)* | `Read https://site/docs/intro.mdx, ` — the model fetches the page |
| `content` | The page's Markdown pasted between `` tags, then the question |
In `content` mode the text comes from `markdownUrl`, or from `getContent()` if
you pass one, or from the page's ``/`` text when neither is set.
If a pasted page would make the URL longer than `maxUrlLength` (default 8000),
the tab opens with the `link` prompt and the full prompt is put on the
clipboard so the visitor can paste it.
`Ctrl/⌘ + Enter` in the message box sends to the first provider.
### Suggested questions
Optionally show a few starter questions under the message box; clicking one
fills it in. Pass a fixed list, or generate them with QwkSearch's follow-up
generator — the same `suggest-followups` agent and clean-up QwkSearch uses for
the follow-ups under its answers:
```tsx
import { AskAIButton, qwkSearchSuggestions } from "ask-ai-button";
// Create the loader once (outside the component) so results are cached per page.
const suggestions = qwkSearchSuggestions({
baseUrl: "https://api.qwksearch.com", // or your own QwkSearch deployment
provider: "groq", // optional: model, key, max (default 4)
});
```
A loader receives the page (`pageUrl`, `markdownUrl`, `title`) and its text as
`content`, and can return questions from anywhere. To use your own model with
the same prompt, call `buildSuggestionsPrompt({ query, article })` and turn the
reply into questions with `parseSuggestions(reply)`. The section stays hidden
when the list is empty.
When `suggestedQuestions` is a loader, the section gets a **Suggest** button
that regenerates the questions (the loader's context then has `refresh: true`)
and a loading and an error state with retry. Results are cached per page, so
reopening the dropdown doesn't ask again. Each question is a row you can click
to fill the message box; the arrow button beside the box sends it to the first
provider, and picking a provider honors the Link to page / Include page text
toggle as usual.
### Choosing providers
```tsx
```
Built-in IDs, in menu order: `qwksearch`, `perplexity`, `claude`, `chatgpt`,
`gemini`, `grok`, `copilot`, `mistral`, `venice`, `brave`. QwkSearch shows its
full-color logo. Mix them
with your own:
```tsx
`https://www.phind.com/search?q=${encodeURIComponent(p)}` },
// Or your own API / in-page chat — no tab is opened
{ id: "api", title: "Our assistant", onSelect: (prompt, page) => fetch("/api/ask", { method: "POST", body: prompt }) },
]}
/>
```
A provider without an `icon` shows its site's favicon.
### Comparing the built-in providers
Every provider below opens in a new tab with the prompt pre-filled. They differ
in what happens after that.
| Provider | ID | Primary role | Models | Search & citations | Files & knowledge | Extensibility | Main trade-off |
| --- | --- | --- | --- | --- | --- | --- | --- |
| [QwkSearch](https://qwksearch.com) | `qwksearch` | Self-hostable AI research, writing and personal knowledge stack (Cloudflare Workers or Docker, open source) | Bring your own keys: Claude, GPT, Gemini, Grok, Llama and others | Strong: 100+ sites in 13 categories, selectable sources, query expansion, cited answers, APA formatting | PDF, YouTube and DOCX extraction; cloud-storage sync | MCP, editable prompts, skills, memory, notes editor, browser extension, desktop app, VS Code | You run the infrastructure, keys, sources and usage costs yourself |
| [Perplexity](https://www.perplexity.ai) | `perplexity` | Hosted AI answer engine for web research | Perplexity picks the model | Strong web answers with citations; little control over sources | Partial PDF support | Memory; no self-hosted MCP/server extensibility | Fast and polished, but no self-hosting, BYOK, deep prompt/tool customization or source selection |
| [Claude](https://claude.ai) | `claude` | Hosted reasoning, writing and AI workspace | Anthropic models only | Web search available; citations can be inconsistent | Files, projects, Google Drive support | Skills, memory, project instructions, MCP; Claude Code separately | Strong reasoning and writing, but closed and single-provider |
| [ChatGPT](https://chatgpt.com) | `chatgpt` | Hosted general-purpose assistant | OpenAI models only | Web search, more limited than a dedicated research engine | Files; Drive/SharePoint connectors on eligible plans | Memory, custom GPTs, custom instructions, code/data tools, paid connectors | Broad capability, but no self-hosting or cross-provider models |
| [Gemini](https://aistudio.google.com) | `gemini` | Google search ecosystem plus the Gemini assistant (opens in AI Studio) | Gemini family only | Google's broad web index; synthesized answers | Strong Google Drive and Workspace alignment | Gems, extensions, memory | Best for Google-centric teams; not self-hostable or source-configurable |
| [Grok](https://grok.com) | `grok` | Hosted chat with X-aware discovery | Grok models only | X posts plus web search; citations can be inconsistent | Partial file support | Custom instructions, memory; limited open tool ecosystem | Great for current X context; no self-hosting, BYOK or source controls |
| [Copilot](https://copilot.microsoft.com) | `copilot` | Microsoft's hosted consumer assistant | Microsoft-managed (OpenAI-based) models | Bing-grounded answers with source links | Files; Microsoft 365 integration on business plans | Limited open extensibility in the consumer app | Convenient in the Microsoft ecosystem; little model or source control |
| [Le Chat](https://chat.mistral.ai) | `mistral` | Mistral's hosted assistant | Mistral models only | Web search with sources | File uploads and document analysis | Agents, connectors, memory | European, fast and open-weight-friendly, but single-provider |
| [Venice](https://venice.ai) | `venice` | Privacy-oriented hosted multi-model chat | Several open model families (Llama, Qwen, DeepSeek and others) | No dedicated research/search workflow | Limited file uploads | System prompts; no built-in MCP, skills or durable memory | Private and flexible on models, but light on research and productivity tooling |
| [Brave](https://search.brave.com) | `brave` | AI answers on top of Brave's independent search index | Brave-managed models | Search-first answers with cited results | — | Brave Search API for developers | Privacy-focused search, but a shallow chat and tooling surface |
For general web research, **Perplexity** is the simplest hosted
answer-with-citations experience, while **QwkSearch** is the most complete
research-to-writing environment: source control, editable prompts, structured
file extraction, MCP, notes, storage sync, browser tooling and IDE integration.
Other tools worth knowing about (not built in — add them as custom providers if they take a prompt in their URL)
| Tool | Primary role | Deployment / licensing | Search & citations | Main trade-off |
| --- | --- | --- | --- | --- |
| [Open WebUI](https://openwebui.com) | Broad local-model and AI workspace | Self-hosted (Docker, Kubernetes); license has a branding-preservation condition | Web search, URL ingestion, strong RAG | Broadest feature set, but heavy to operate securely |
| [LobeHub](https://lobehub.com) | Polished agent workspace | Self-host or cloud; LobeHub Community License | Agent workflows rather than cited web research | Heavier than a simple chat UI; check the license before white-labeling |
| [AnythingLLM](https://anythingllm.com) | Private document chat and turnkey RAG | Desktop apps and Docker; MIT | Web browsing secondary to document workflows | Opinionated around workspaces; desktop edition lacks server features |
| [LibreChat](https://librechat.ai) | Multi-provider ChatGPT/Claude-style app | Self-hosted; MIT | Web search, but not search-first | Production needs MongoDB, Redis and more; fast-moving |
| [Vane (formerly Perplexica)](https://github.com/ItzCrazyKns/Perplexica) | Self-hosted Perplexity-style research engine | Local/Docker; MIT | Excellent: cited answers, SearxNG, academic/discussion modes, domain filters | Closest open-source Perplexity, but immature auth and multi-user support |
| [Onyx](https://onyx.app) | Enterprise internal search and deep research | Docker, Kubernetes, Helm, Terraform; MIT core, paid enterprise features | Hybrid retrieval, web search, deep research | Infrastructure-heavy; lite mode drops most of the RAG stack |
| [Notion](https://www.notion.com) | Cloud workspace with AI-assisted organizational search | Proprietary cloud | Enterprise Search across Notion, connected apps and the web | Strong if Notion is your hub; closed and plan-gated |
| [Elicit](https://elicit.com) | Scientific research and evidence synthesis | Proprietary hosted; API and MCP | Excellent for scholarship: 138M papers, 545K clinical trials, sentence-level citations | Rigorous for academic evidence, but not general web search or self-hosted |
## Props
`AskAIButton` takes every `AskAIPanel` prop plus the trigger props.
| Prop | Default | |
| --- | --- | --- |
| `markdownUrl` | — | Raw Markdown/MDX of the page. Relative URLs resolve against the current page. |
| `pageUrl` | `location.href` | The page being asked about. |
| `title` | — | Named in the prompt and shown in the panel header. |
| `githubUrl` | — | Adds a GitHub link. |
| `providers` | all built-ins | IDs and/or `AIProvider` objects, in order. |
| `defaultMode` | `link` if `markdownUrl`, else `content` | Starting mode. |
| `showModeToggle` | `true` | Show the link/content toggle. |
| `getContent` | — | Supply the page text yourself. |
| `promptTemplate` | `buildPrompt` | `(input) => string` to change the wording. |
| `maxUrlLength` | `8000` | URL length before falling back to the link prompt. |
| `placeholder`, `heading` | — | Text in the panel. `heading={null}` hides the header. |
| `suggestedQuestions` | — | A list of questions, or `(page) => string[] \| Promise` such as `qwkSearchSuggestions()`. |
| `suggestionsLabel` | `"Suggested questions"` | Label above them; `null` hides it. |
| `suggestLabel` | `"Suggest"` | Text of the button that regenerates loader-made questions. |
| `onSend` | — | `({ provider, prompt, href })` after each send — for analytics. |
| `injectStyles` | `true` | Set `false` if you ship `askAIButtonCss` yourself. |
| `variant` | `dropdown` | `dropdown` or `fab`. |
| `floating` | — | Shorthand for `variant="fab"`; wins over `variant` when set. |
| `label`, `icon` | `"Ask AI"`, sparkle | Trigger content. `label={null}` gives an icon-only FAB. |
| `align` | `start` | Dropdown: panel aligns to the trigger's `start` or `end` edge. |
| `position` | `bottom-right` | FAB: `bottom-right` or `bottom-left`. |
| `open`, `defaultOpen`, `onOpenChange` | — | Controlled or uncontrolled open state. |
Helpers exported for building your own UI: `buildPrompt`,
`resolveProviderTarget`, `resolveProviders`, `AI_PROVIDERS`, `fetchMarkdown`,
`copyText`, `copyPendingText`, `qwkSearchSuggestions`, `buildSuggestionsPrompt`,
`parseSuggestions`, and the brand icons (including `QwkSearchColorIcon`).
## Theming
Every class is prefixed `aai-`. Colors come from CSS variables that default to
Fumadocs' `--color-fd-*` tokens and fall back to a neutral palette, with a dark
palette under `.dark` or `[data-theme="dark"]`:
```css
.aai-root {
--aai-primary: #7c3aed;
--aai-radius: 1rem;
}
```
The stylesheet is injected once as `