GitbookIO/gitbook · error · Error
AI is not enabled for this site.
Error message
AI is not enabled for this site.
What it means
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.
Source
Thrown at packages/gitbook/src/components/Search/server-actions.tsx:162
}
/**
* Stream a list of suggested questions for the site.
* Optionally scoped to a specific space.
*/
export async function streamRecommendedQuestions(args: { siteSpaceId?: string }) {
return traceErrorOnly('Search.streamRecommendedQuestions', async () => {
const siteURLData = await getSiteURLDataFromMiddleware();
const context = await getServerActionBaseContext();
const responseStream = createStreamableValue<
SearchAIRecommendedQuestionStream | undefined
>();
(async () => {
const siteContext = await fetchServerActionSiteContext(context);
if (!isAIEnabled(siteContext.customization.ai.mode)) {
throw new Error('AI is not enabled for this site.');
}
const apiClient = await context.dataFetcher.api();
const apiStream = apiClient.orgs.streamRecommendedQuestionsInSite(
siteURLData.organization,
siteURLData.site,
{
siteSpaceId: args.siteSpaceId,
}
);
for await (const chunk of apiStream) {
responseStream.update(chunk);
}
})()
.then(() => {
responseStream.done();
})View on GitHub (pinned to db67585ee2)
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.
Example fix
// before
const { stream } = streamRecommendedQuestions(...);
// after
if (!isAIEnabled(customization.ai.mode)) {
return null;
}
const { stream } = streamRecommendedQuestions(...); Defensive patterns
Strategy: validation
Validate before calling
if (!isAIEnabled(customization.ai.mode)) {
return null; // don't fetch recommended questions
}
const { stream } = streamRecommendedQuestions(context); Type guard
const aiEnabled = (mode: string | undefined): mode is string => isAIEnabled(mode);
Try / catch
try {
const result = await streamRecommendedQuestions(args);
} catch (error) {
if (error instanceof Error && error.message === 'AI is not enabled for this site.') {
return []; // no recommendations on AI-disabled sites
}
throw error;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- AI Search is not enabled for this site.
- The AI Assistant is not enabled for this site.
- No response found
- useAI must be used within AIContextProvider
- There is no previous response to rate.
AI-assisted analysis of GitbookIO/gitbook@db67585ee2 (2026-08-28).
Data as JSON: /api/errors/6413f1f509a27384.
Report an issue: GitHub.