Skip to main content

AI API

The AI API provides AI-powered features including conversational assistance, content suggestions, and a knowledge base. AI features require a configured provider (OpenAI, Gemini, or Claude) in Settings > AI Configuration. All endpoints require JWT authentication.

AI Query

POST /api/ai/query

Send a message to the AI assistant. Supports multi-turn conversations.

Request Body

{
"message": "How can I improve my onboarding flow completion rate?",
"conversationId": "conv_abc123",
"context": { "currentFlowId": "flow_xyz" }
}
FieldTypeRequiredDescription
messagestringYesThe user's message
conversationIduuidNoContinue an existing conversation (omit to start new)
contextobjectNoAdditional context for the AI

Response

{
"data": {
"conversationId": "conv_abc123",
"response": "Here are some strategies to improve completion rates...",
"messages": [
{
"role": "user",
"content": "How can I improve...",
"timestamp": "2025-01-20T10:00:00Z"
},
{
"role": "assistant",
"content": "Here are some strategies...",
"timestamp": "2025-01-20T10:00:01Z"
}
]
}
}

Suggest Flow

POST /api/ai/suggest-flow

Get AI-generated flow recommendations based on a page and user segment.

Request Body

{
"pageUrl": "https://app.example.com/settings",
"userSegment": "new_users",
"goal": "Help users configure notifications"
}

Response

{
"data": {
"suggestion": "...",
"steps": [...]
}
}

Suggest Audience

POST /api/ai/suggest-audience

Generate audience targeting rules from a natural language description.

Request Body

{
"description": "Enterprise users who signed up in the last 30 days and haven't completed onboarding"
}

The description field accepts 1-500 characters.

Generate Content

POST /api/ai/generate-content

Generates a draft content item from a natural-language description. The response contains both the raw aiData payload (used to commit the item) and a renderable preview. No content is persisted until you call Commit Content.

Request Body

{
"type": "tooltip",
"siteId": "550e8400-e29b-41d4-a716-446655440000",
"description": "Highlight the new Reports button in the top nav for first-time users."
}
FieldTypeRequiredDescription
typestringYesOne of flow, tooltip, beacon, survey, announcement, journey, task-list
siteIduuidYesSite the generated content should belong to
descriptionstringYes1–2000 characters. Plain-language description of what to generate

Response

{
"data": {
"aiData": { "...": "..." },
"preview": { "...": "..." },
"tokensUsed": 1247
}
}

tokensUsed is debited from the tenant's AI token balance immediately. Generation fails with INSUFFICIENT_AI_TOKENS if the balance is zero.

Commit Content

POST /api/ai/commit-content

Persists a previously generated draft. Pass back the aiData payload returned by /ai/generate-content. The endpoint creates the parent record and any child records (e.g., flow steps, survey questions) atomically.

Request Body

{
"type": "tooltip",
"siteId": "550e8400-e29b-41d4-a716-446655440000",
"aiData": { "...": "..." }
}

Response

{
"data": {
"parentId": "ct_abc123",
"parentType": "tooltip",
"createdSubItemIds": {
"steps": ["st_111", "st_222"]
}
}
}

createdSubItemIds is present only for content types that have child records (flows, surveys, journeys, task lists).

Knowledge Base

List Articles

GET /api/ai/knowledge-base

Query Parameters

ParameterTypeDefaultDescription
pagestring"1"Page number
limitstring"20"Items per page
searchstringFull-text search
categorystringFilter by category

Response

{
"data": [
{
"id": "kb_abc",
"title": "Getting Started Guide",
"content": "Welcome to...",
"metadata": {},
"tenantId": "t_789",
"createdAt": "2025-01-10T09:00:00Z",
"updatedAt": "2025-01-10T09:00:00Z"
}
],
"meta": { "total": 15, "page": 1, "limit": 20, "totalPages": 1 }
}

Create Article

POST /api/ai/knowledge-base

Request Body

{
"title": "Getting Started Guide",
"content": "Welcome to the platform...",
"category": "onboarding",
"tags": ["getting-started", "basics"]
}
FieldTypeRequiredDescription
titlestringYesArticle title
contentstringYesArticle body (supports markdown)
categorystringNoCategory for organization
tagsstring[]NoTags for search and filtering

Get Article

GET /api/ai/knowledge-base/:id

Update Article

PATCH /api/ai/knowledge-base/:id

All fields are optional for updates.

Delete Article

DELETE /api/ai/knowledge-base/:id

List Conversations

GET /api/ai/conversations

Returns all AI conversations for the current tenant.

Response

{
"data": [
{
"id": "conv_abc123",
"tenantId": "t_789",
"messages": [...],
"createdAt": "2025-01-20T10:00:00Z",
"updatedAt": "2025-01-20T10:05:00Z"
}
],
"meta": { "total": 5, "page": 1, "limit": 20, "totalPages": 1 }
}

AI Configuration

Get Configuration

GET /api/ai-config

Response

{
"data": {
"id": "aic_abc",
"tenantId": "t_789",
"provider": "OPENAI",
"maskedKey": "sk-...abc1",
"isEnabled": true,
"lastVerifiedAt": "2025-01-15T12:00:00Z",
"createdAt": "2025-01-10T00:00:00Z",
"updatedAt": "2025-01-15T12:00:00Z"
}
}

Returns null if no AI provider has been configured.

Save Configuration

POST /api/ai-config

Request Body

{
"provider": "OPENAI",
"apiKey": "sk-your-api-key"
}
ProviderValue
OpenAIOPENAI
Google GeminiGEMINI
Anthropic ClaudeCLAUDE

Toggle AI Features

POST /api/ai-config/toggle

Request Body

{
"enabled": false
}

Disabling AI features stops all AI-powered functionality (suggestions, knowledge base queries) without removing the provider configuration.