{"record":{"id":"6413f1f509a27384","repo":"GitbookIO/gitbook","slug":"ai-is-not-enabled-for-this-site","errorCode":null,"errorMessage":"AI is not enabled for this site.","messagePattern":"AI is not enabled for this site\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/gitbook/src/components/Search/server-actions.tsx","lineNumber":162,"sourceCode":"}\n\n/**\n * Stream a list of suggested questions for the site.\n * Optionally scoped to a specific space.\n */\nexport async function streamRecommendedQuestions(args: { siteSpaceId?: string }) {\n    return traceErrorOnly('Search.streamRecommendedQuestions', async () => {\n        const siteURLData = await getSiteURLDataFromMiddleware();\n        const context = await getServerActionBaseContext();\n\n        const responseStream = createStreamableValue<\n            SearchAIRecommendedQuestionStream | undefined\n        >();\n\n        (async () => {\n            const siteContext = await fetchServerActionSiteContext(context);\n            if (!isAIEnabled(siteContext.customization.ai.mode)) {\n                throw new Error('AI is not enabled for this site.');\n            }\n\n            const apiClient = await context.dataFetcher.api();\n            const apiStream = apiClient.orgs.streamRecommendedQuestionsInSite(\n                siteURLData.organization,\n                siteURLData.site,\n                {\n                    siteSpaceId: args.siteSpaceId,\n                }\n            );\n\n            for await (const chunk of apiStream) {\n                responseStream.update(chunk);\n            }\n        })()\n            .then(() => {\n                responseStream.done();\n            })","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/GitbookIO/gitbook/blob/db67585ee243d063c459a855988f21612cea9c95/packages/gitbook/src/components/Search/server-actions.tsx#L144-L180","documentation":"Thrown by the streamRecommendedQuestions server action when AI is not enabled at all for the site (isAIEnabled(siteContext.customization.ai.mode) is false). This is the loosest of the AI gates — any non-disabled AI mode passes — so seeing this error means the site's ai.mode is disabled or unset, or the fetched site context belongs to a different site than expected.","triggerScenarios":"Calling streamRecommendedQuestions with customization.ai.mode === 'disabled' or undefined; site context fetched for the wrong org/site (bad middleware URL data); customization not yet propagated or cached as disabled after enabling; invoking the action from an embed of a site without AI.","commonSituations":"Enabling AI in settings but hitting a cached context; custom deployments where the customization API returns the default (disabled) mode; calling the action before the space settings finished saving.","solutions":["Enable AI for the space/site in GitBook customization (any AI mode satisfies this check).","Only render the recommended-questions UI when isAIEnabled(customization.ai.mode) is true, using the site context already available client-side.","Verify the site context being fetched matches the site the user is browsing (org/space/site IDs).","Bust cache/redeploy after changing AI settings so server actions see fresh customization."],"exampleFix":"// before\nconst { stream } = streamRecommendedQuestions(...);\n\n// after\nif (!isAIEnabled(customization.ai.mode)) {\n    return null;\n}\nconst { stream } = streamRecommendedQuestions(...);","handlingStrategy":"validation","validationCode":"if (!isAIEnabled(customization.ai.mode)) {\n    return null; // don't fetch recommended questions\n}\nconst { stream } = streamRecommendedQuestions(context);","typeGuard":"const aiEnabled = (mode: string | undefined): mode is string => isAIEnabled(mode);","tryCatchPattern":"try {\n    const result = await streamRecommendedQuestions(args);\n} catch (error) {\n    if (error instanceof Error && error.message === 'AI is not enabled for this site.') {\n        return []; // no recommendations on AI-disabled sites\n    }\n    throw error;\n}","preventionTips":["Gate recommended-questions UI on isAIEnabled(client-known ai.mode).","Recheck the gate after settings changes instead of caching enabled state forever.","Ensure the middleware resolves to the site you actually configured."],"tags":["ai","feature-flag","configuration","server-action","gitbook"],"backgroundTag":"feature-not-enabled","analyzedSha":"db67585ee243d063c459a855988f21612cea9c95","analyzedAt":"2026-08-28T17:49:47.831Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}