AI Assistant API
作成2026年3月22日Takeshi Takatsudo
このページはまだ翻訳されていません。原文のまま表示しています。
API specification for the AI assistant chat endpoint.
Endpoint
POST /api/ai-chat
Content-Type: application/json
Request Body
interface AiChatRequest {
message: string;
history: ChatMessage[];
}
interface ChatMessage {
role: "user" | "assistant";
content: string;
}
| Field | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The user’s current message. Must be non-empty. |
history | ChatMessage[] | Yes | Previous conversation messages. Invalid entries are filtered out silently. |
Success Response (200)
interface AiChatResponse {
response: string;
}
The response field contains the assistant’s reply as a markdown string.
Example:
// Request
{
"message": "How do I add a new page?",
"history": []
}
// Response
{
"response": "Create an MDX file in `src/content/docs/`:\n\n1. Add frontmatter with `title`\n2. Write your content in MDX\n3. The page appears in the sidebar automatically"
}
Error Response (400 / 500)
interface AiChatErrorResponse {
error: string;
}
| Status | Condition |
|---|---|
| 400 | Invalid JSON body |
| 400 | message is not a non-empty string |
| 400 | history is not an array |
| 500 | AI_CHAT_MODE is not set to "local" or "remote" |
| 500 | Claude CLI or Anthropic API call failed |
Environment Variables
| Variable | Required | Description |
|---|---|---|
AI_CHAT_MODE | Yes | "local" or "remote" |
ANTHROPIC_API_KEY | Remote mode only | Anthropic API key |
PUBLIC_ENABLE_MOCKS | No | Set to "true" to enable MSW mock responses (dev mode only, ignored in production) |
Backend Modes
Local Mode (AI_CHAT_MODE=local)
Spawns claude -p --model haiku as a subprocess. Documentation context is piped via stdin. 60-second timeout.
Remote Mode (AI_CHAT_MODE=remote)
Calls the Anthropic Messages API with claude-haiku-4-5-20251001. Documentation content is included in the system prompt.
Documentation Context
The endpoint loads llms-full.txt (generated by the llms.txt integration) as context. The file is loaded once and cached in memory.