AI Chat
Docunara includes a built-in AI Chat assistant that helps you write, improve, translate, and summarize documentation directly from the editor. The assistant understands your current document context and can generate Markdown-formatted content ready to insert into your documents.
Setup
1. Choose a Provider
Docunara supports two AI providers:
| Provider | Default Model | API Key Source |
|---|---|---|
| OpenAI | gpt-4o-mini | platform.openai.com |
| Anthropic | claude-sonnet-4-20250514 | console.anthropic.com |
2. Configure Environment Variables
Add the following to your .env file:
# AI provider: "openai" or "anthropic" (default: openai)
AI_PROVIDER=openai
# API key for the AI provider (required to enable AI Chat)
AI_APIKEY=sk-your-api-key-here
# Model name (optional — uses provider default if empty)
AI_MODEL=
# Custom system prompt (optional — has a sensible default)
AI_SYSPROMPT=
| Variable | Default | Description |
|---|---|---|
AI_PROVIDER | openai | AI provider to use (openai or anthropic) |
AI_APIKEY | (empty) | API key for the selected provider. AI Chat is disabled when empty. |
AI_MODEL | (auto) | Model name. Defaults to gpt-4o-mini for OpenAI, claude-sonnet-4-20250514 for Anthropic. |
AI_SYSPROMPT | (built-in) | Custom system prompt. When empty, uses a built-in prompt optimized for documentation writing. |
3. Restart the Server
After setting AI_APIKEY, restart the server. The AI Chat button will appear in the editor toolbar automatically.
Using AI Chat
Opening the Panel
When AI Chat is enabled, a sparkle icon button appears in the editor toolbar. Click it to open the AI Chat panel on the right side of the editor.
Basic Chat
Type a message and press Enter to send. The AI responds with streaming output in real time. You can ask questions about your document, request writing suggestions, or ask for help with Markdown formatting.
The AI automatically receives context about:
- The current document path and locale
- The full document content
- Any text you have selected in the editor
Action Buttons
Each AI response includes action buttons:
| Button | Description |
|---|---|
| Copy | Copy the response to clipboard |
| Insert | Insert the response at the current cursor position in the editor (premium) |
| Replace | Replace the entire document content with the response (premium) |
Slash Commands (Premium)
Type / in the input field to see available commands. Slash commands provide one-click access to common documentation tasks:
| Command | Description |
|---|---|
/summarize | Summarize the current document |
/translate <lang> | Translate the document to a specified language |
/improve | Improve writing quality and clarity |
/expand | Expand selected text with more detail |
/simplify | Simplify complex text |
/toc | Generate a table of contents |
/proofread | Check grammar and spelling |
For /translate, add the target language after the command (e.g., /translate Korean).
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
| Enter | Send message |
| Shift + Enter | New line in input |
| Arrow Up / Down | Navigate slash command suggestions |
| Tab or Enter | Select a slash command |
| Escape | Close slash command popup |
Feature Availability
| Feature | Core | Premium (license required) |
|---|---|---|
| Basic chat (Q&A) | Yes | Yes |
| Document context awareness | Yes | Yes |
| Copy response | Yes | Yes |
| Slash commands | No | Yes |
| Insert at cursor | No | Yes |
| Replace document | No | Yes |
Basic AI Chat is available to all users when AI_APIKEY is configured. Slash commands and editor integration actions (Insert / Replace) require a valid license.
Custom System Prompt
You can customize the AI assistant's behavior by setting AI_SYSPROMPT in your .env file. The default system prompt instructs the AI to:
- Write concise, professional documentation
- Use proper Markdown formatting (headings, lists, code blocks, tables)
- Support Docusaurus-specific features (admonitions with
:::tip,:::note, etc.) - Respond in the same language the user writes in
To override this, provide your own prompt:
AI_SYSPROMPT=You are a technical writer specializing in API documentation. Always include code examples in your responses.
API Endpoints
The AI Chat feature exposes two API endpoints:
| Endpoint | Method | Description |
|---|---|---|
/api/ai/status | GET | Returns whether AI Chat is enabled and the provider name |
/api/ai/chat | POST | Streaming chat endpoint (SSE) |
Both endpoints require authentication.
Troubleshooting
AI Chat button does not appear
- Verify that
AI_APIKEYis set in your.envfile - Restart the server after changing
.env - Check the server logs for API key validation errors
Slash commands show "premium" badge
Slash commands and Insert/Replace actions require a valid license file. See Licensing for details.
Streaming responses are slow
Response speed depends on the AI provider and model. Consider using a faster model by setting AI_MODEL (e.g., gpt-4o-mini is generally faster than gpt-4o).