POST/smart-forms/:id/chat

Chat

Ask an AI assistant questions about smart form session data

Scope: SMART_FORMS_ANALYTICS

Overview

Sends a natural language message to an AI assistant that has access to the smart form's completed session data (up to the 50 most recent sessions). Returns a conversational answer and the number of credits consumed. Pass conversationHistory to maintain multi-turn conversations.

Request

POST/smart-forms/:id/chat

Headers

HeaderValue
AuthorizationBearer fxk_live_<your-api-key>
Content-Typeapplication/json

Path Parameters

Request Body

ConversationHistory Entry

FieldTypeDescription
rolestringuser or assistant
contentstringThe message content

Example Request

# Single-turn question
curl -X POST "https://api.formfex.com/api/v1/public/smart-forms/SMART_FORM_ID/chat" \
  -H "Authorization: Bearer $FORMFEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "What are the most common complaints from respondents?"
  }'

# Multi-turn with conversation history
curl -X POST "https://api.formfex.com/api/v1/public/smart-forms/SMART_FORM_ID/chat" \
  -H "Authorization: Bearer $FORMFEX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Can you give me specific examples?",
    "conversationHistory": [
      {
        "role": "user",
        "content": "What are the most common complaints from respondents?"
      },
      {
        "role": "assistant",
        "content": "The most common complaints are long checkout wait times and noise levels in rooms."
      }
    ]
  }'

Response

Response Fields

FieldTypeDescription
answerstringThe AI assistant's response
creditsUsednumberNumber of credits consumed by this request (minimum 1)

Error Cases

StatusDescription
400No completed sessions exist to chat about
401Invalid or missing API key
403Smart Forms feature not available on plan, or insufficient credits
404Smart form not found or not owned by this API key

Session Context

The AI has access to the 50 most recently completed sessions, including their full Q&A transcripts and individual analyses. Questions can reference specific sessions, trends, sentiment scores, or common themes.

Credit Cost

Each chat request consumes a minimum of 1 credit. Complex questions across many sessions may consume more. The exact cost is returned in the creditsUsed field.

n8n

In n8n, this operation is available as Chat under the Smart Form resource in the Formfex node. Note: AI Agent tool nodes may compose messages longer than 500 characters — the node automatically truncates to stay within the limit.