본문으로 건너뛰기

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:

ProviderDefault ModelAPI Key Source
OpenAIgpt-4o-miniplatform.openai.com
Anthropicclaude-sonnet-4-20250514console.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=
VariableDefaultDescription
AI_PROVIDERopenaiAI 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:

ButtonDescription
CopyCopy the response to clipboard
InsertInsert the response at the current cursor position in the editor (premium)
ReplaceReplace 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:

CommandDescription
/summarizeSummarize the current document
/translate <lang>Translate the document to a specified language
/improveImprove writing quality and clarity
/expandExpand selected text with more detail
/simplifySimplify complex text
/tocGenerate a table of contents
/proofreadCheck grammar and spelling

For /translate, add the target language after the command (e.g., /translate Korean).

Keyboard Shortcuts

ShortcutAction
EnterSend message
Shift + EnterNew line in input
Arrow Up / DownNavigate slash command suggestions
Tab or EnterSelect a slash command
EscapeClose slash command popup

Feature Availability

FeatureCorePremium (license required)
Basic chat (Q&A)YesYes
Document context awarenessYesYes
Copy responseYesYes
Slash commandsNoYes
Insert at cursorNoYes
Replace documentNoYes

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:

EndpointMethodDescription
/api/ai/statusGETReturns whether AI Chat is enabled and the provider name
/api/ai/chatPOSTStreaming chat endpoint (SSE)

Both endpoints require authentication.

Troubleshooting

AI Chat button does not appear

  • Verify that AI_APIKEY is set in your .env file
  • 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).