TypeScript API / @laikacms/server/ai / DecapAiConfig
Interface: DecapAiConfig
Configuration for decapAi
Properties
authenticateAccessToken
authenticateAccessToken: (rawToken) => Promise<User>;Authenticate a Bearer access token and return the user. This should be the same callback used in @laikacms/server/api, backed by the same resolveBearer seam from laikacms/auth: { ...ctx.user, scopes: ctx.scopes }. Returning scopes lets decapAi enforce requiredScope instead of granting every authenticated user full AI/document access.
Parameters
| Parameter | Type |
|---|---|
rawToken | string |
Returns
Promise<User>
basePath?
optional basePath?: string;Base path for the AI endpoints (default: '/api/ai')
callbacks
callbacks: AiSessionCallbacks;Session storage callbacks
logger?
optional logger?: Logger;Logger instance
maxOutputTokens?
optional maxOutputTokens?: number;Maximum output tokens for response (default: 4096)
messages?
optional messages?: object;Localized messages for error responses and system prompts. If not provided, defaults to English messages.
errors
errors: object;errors.aiProcessingFailed
aiProcessingFailed: string = 'AI processing failed';errors.authenticationFailed
authenticationFailed: string = 'Authentication failed';errors.failedToDeleteSession
failedToDeleteSession: string = 'Failed to delete session';errors.failedToGetSession
failedToGetSession: string = 'Failed to get session';errors.failedToListSessions
failedToListSessions: string = 'Failed to list sessions';errors.insufficientScope
insufficientScope: string = 'Insufficient scope for this request';errors.invalidJsonBody
invalidJsonBody: string = 'Invalid JSON body';errors.methodNotAllowed
methodNotAllowed: string = 'Method not allowed';errors.missingAuthHeader
missingAuthHeader: string = 'Missing or invalid Authorization header';errors.missingDocumentContext
missingDocumentContext: string = 'Missing document context';errors.missingDocumentSlug
missingDocumentSlug: string = 'Missing documentSlug query parameter';errors.missingOrInvalidMessage
missingOrInvalidMessage: string = 'Missing or invalid message';errors.sessionAccessDenied
sessionAccessDenied: string = 'Session access denied';errors.sessionNotFound
sessionNotFound: string = 'Session not found';errors.unknownEndpoint
unknownEndpoint: string = 'Unknown AI endpoint: %s';systemPrompt
systemPrompt: string;Base system prompt - translatable, describes the AI's role
model
model: LanguageModel;LLM model to use (from Vercel AI SDK) Example: openai('gpt-4o'), anthropic('claude-3-5-sonnet-20241022')
requiredScope?
optional requiredScope?: Scope;Scope required to use the AI endpoints (chat + sessions), checked via hasScope against user.scopes when authenticateAccessToken returns one. Users with no scopes (legacy/full-admin sessions per the resolveBearer convention) are always allowed. Defaults to 'content:write' since the AI can edit documents via updateDocument.
systemPrompt?
optional systemPrompt?: string;System prompt for the AI assistant. Replaces the default prompt entirely — the built-in getDocumentData/updateDocument tool guidance is discarded when this is set. To extend the default rather than replace it, use the messages option instead: import en from '@laikacms/server/ai/i18n/en';messages: { ...en, systemPrompt: 'Your prefix.\n\n' + en.systemPrompt }
temperature?
optional temperature?: number;Temperature for response generation (default: 0.7)
tools?
optional tools?: ToolSet;Tools to provide to the AI. Use the standard Vercel AI SDK tool() function to create tools.
Client-side tools (getDocumentData, updateDocument) are executed by the CMS client (see the Dulla transport in laikacms/decap-cms), which is why they carry no execute. Server-side tools should have one.
Example
import { jsonSchema, tool } from '@laikacms/server/ai';
tools: {
getCmsConfig: tool({
description: 'Get the CMS configuration',
inputSchema: jsonSchema({
type: 'object',
properties: {},
additionalProperties: false,
}),
execute: async () => ({ configYaml: myConfigYaml }),
}),
}