{"record":{"id":"1caf477f9a9b1cdc","repo":"GitbookIO/gitbook","slug":"the-ai-assistant-is-not-enabled-for-this-site","errorCode":null,"errorMessage":"The AI Assistant is not enabled for this site.","messagePattern":"The AI Assistant is not enabled for this site\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gitbook/src/components/AI/server-actions/chat.ts","lineNumber":46,"sourceCode":"    session,\n    options,\n}: {\n    message?: string;\n    messageContext: AIMessageContext;\n    previousResponseId?: string;\n    toolCall?: AIToolCallResult;\n    tools?: AIToolDefinition[];\n    session: SiteInsightsSession;\n    options?: RenderAIMessageOptions;\n}) {\n    const { stream } = await traceErrorOnly('AI.streamAIChatResponse', async () => {\n        const context = await getServerActionBaseContext({\n            isEmbeddable: options?.asEmbeddable,\n        });\n\n        const siteContext = await fetchServerActionSiteContext(context);\n        if (!isAIChatEnabled(siteContext.customization.ai.mode)) {\n            throw new Error('The AI Assistant is not enabled for this site.');\n        }\n\n        const siteURLData = await getSiteURLDataFromMiddleware();\n\n        const api = await context.dataFetcher.api();\n        const rawStream = api.orgs.streamAiResponseInSite(\n            siteURLData.organization,\n            siteURLData.site,\n            {\n                input: message\n                    ? [\n                          {\n                              role: AIMessageRole.User,\n                              content: message,\n                              context: messageContext,\n                          },\n                      ]\n                    : [],","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/GitbookIO/gitbook/blob/db67585ee243d063c459a855988f21612cea9c95/packages/gitbook/src/components/AI/server-actions/chat.ts#L28-L64","documentation":"Thrown by the streamAIChatResponse server action when the site's AI chat feature is disabled. The action fetches the site context and checks customization.ai.mode with isAIChatEnabled; unless the mode explicitly enables chat, it refuses before ever contacting the streaming API. It is a configuration gate, not a runtime failure.","triggerScenarios":"Invoking the AI chat server action on a site whose customization.ai.mode is 'disabled' or set to a search-only mode (e.g. 'search' instead of 'chat'); embedding the assistant on a site where the AI feature was never turned on in GitBook space settings; the customization not yet propagated after toggling AI on.","commonSituations":"Self-hosting or embedding the GitBook app against an org/site where AI wasn't enabled; changing the AI customization mode to 'search' while UI components still render the chat entry point; caching serving a stale site customization after the setting changed.","solutions":["Enable the AI Assistant (chat mode) for the space/site in GitBook customization settings (customization.ai.mode supporting chat).","If you render chat UI conditionally, gate it on the same isAIChatEnabled(customization.ai.mode) check used server-side so the action is never invoked when disabled.","Verify you're hitting the intended site: wrong org/site URL data leads to a site context whose AI is off.","After enabling, clear/refetch cached site context so the new mode is visible to the server action."],"exampleFix":"// before\n<button onClick={() => streamAIChatResponse({ messages })}>Ask</button>\n\n// after\nconst chatEnabled = isAIChatEnabled(customization.ai.mode);\n{chatEnabled && (\n    <button onClick={() => streamAIChatResponse({ messages })}>Ask</button>\n)}","handlingStrategy":"validation","validationCode":"import { isAIChatEnabled } from './ai';\n\nconst canChat = isAIChatEnabled(customization.ai.mode);\nif (!canChat) {\n    renderDisabledState();\n} else {\n    streamAIChatResponse({ messages });\n}","typeGuard":"const aiModeEnablesChat = (\n    mode: string | undefined\n): mode is 'chat' | 'search-and-chat' => isAIChatEnabled(mode);","tryCatchPattern":"try {\n    await streamAIChatResponse(options);\n} catch (error) {\n    if (error instanceof Error && error.message.includes('not enabled')) {\n        showFeatureDisabledNotice();\n        return;\n    }\n    throw error;\n}","preventionTips":["Mirror the server-side isAIChatEnabled gate in the UI before rendering chat entry points.","Keep site customization cached client-side and re-check on settings changes.","Test with the real ai.mode values used in production."],"tags":["ai","chat","feature-flag","configuration","gitbook"],"backgroundTag":"feature-not-enabled","analyzedSha":"db67585ee243d063c459a855988f21612cea9c95","analyzedAt":"2026-08-28T17:49:47.831Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}