> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cludo.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Chat

> Returns a generative answer for the given question, with optional citations and multi-turn conversation support. `includeCitations` changes the output for both the standard and streaming endpoints.

> [tab] Standard
>
> You are viewing the **standard** endpoint which returns a complete JSON response.

> [tab] Streaming
>
> The streaming endpoint is the same path as standard with `/stream` appended: `POST /api/v4/{customerId}/{engineId}/search/answer/stream`. It accepts the same request body as the standard endpoint, but streams the response as plain text chunks. When `includeCitations` is `true`, the streamed answer includes inline Markdown citation links (e.g. `[1](url)`) for each source used. When `false` (default), the streamed answer has no inline citations, and a single primary source URL is surfaced separately instead. Response headers include `Cludo-Conversation-Id` and `Cludo-Exchange-Id` for conversation tracking.

***

## Multi-turn conversations

Pass the `conversationId` from a previous response to continue the conversation. For independent questions, omit `conversationId` to start fresh.

***

## Filtering, boosting, and source fields

Three optional fields let you narrow and shape the content the model uses when generating an answer. All three work on both the standard and streaming endpoints.

| Field | What it does |
| - | - |
| `filters` | Restricts the grounding documents to those matching a field/value filter — same syntax as the [Search endpoint filters](https://docs.cludo.com/api-reference/v4/search/search.md) |
| `valueBoost` | Boosts documents where a field matches specific values, surfacing them higher in the context window |
| `sourceFields` | Controls which indexed fields are passed to the model as context (defaults to `Title` and `Content`) |

```bash cURL theme={null}
curl -X POST "https://api.cludo.com/api/v4/{customerId}/{engineId}/search/answer" \
  -H "Authorization: Basic <base64(customerId:apiKey)>" \
  -H "Content-Type: application/json" \
  -d '{
    "question": "What is your return policy?",
    "filters": {
      "Category": ["Policies"]
    },
    "valueBoost": [
      {
        "fieldName": "ContentType",
        "boosts": [
          { "boost": 10, "values": ["FAQ"] }
        ]
      }
    ],
    "sourceFields": ["Title", "Content", "Summary"]
  }'
```

```python Python theme={null}
import requests, base64

credentials = base64.b64encode(b"customerId:apiKey").decode()

response = requests.post(
    "https://api.cludo.com/api/v4/{customerId}/{engineId}/search/answer",
    headers={
        "Authorization": f"Basic {credentials}",
        "Content-Type": "application/json",
    },
    json={
        "question": "What is your return policy?",
        "filters": {
            "Category": ["Policies"]
        },
        "valueBoost": [
            {
                "fieldName": "ContentType",
                "boosts": [{"boost": 10, "values": ["FAQ"]}],
            }
        ],
        "sourceFields": ["Title", "Content", "Summary"],
    },
)
print(response.json())
```

```javascript JavaScript theme={null}
const credentials = btoa("customerId:apiKey");

const response = await fetch(
  "https://api.cludo.com/api/v4/{customerId}/{engineId}/search/answer",
  {
    method: "POST",
    headers: {
      Authorization: `Basic ${credentials}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      question: "What is your return policy?",
      filters: {
        Category: ["Policies"],
      },
      valueBoost: [
        {
          fieldName: "ContentType",
          boosts: [{ boost: 10, values: ["FAQ"] }],
        },
      ],
      sourceFields: ["Title", "Content", "Summary"],
    }),
  }
);
const data = await response.json();
```

```typescript TypeScript theme={null}
const credentials = btoa("customerId:apiKey");

interface ValueBoost {
  fieldName: string;
  boosts: { boost: number; values: string[] }[];
}

const body = {
  question: "What is your return policy?",
  filters: {
    Category: ["Policies"],
  },
  valueBoost: [
    {
      fieldName: "ContentType",
      boosts: [{ boost: 10, values: ["FAQ"] }],
    },
  ] as ValueBoost[],
  sourceFields: ["Title", "Content", "Summary"],
};

const response = await fetch(
  "https://api.cludo.com/api/v4/{customerId}/{engineId}/search/answer",
  {
    method: "POST",
    headers: {
      Authorization: `Basic ${credentials}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify(body),
  }
);
const data: unknown = await response.json();
```

***

## Tagging requests for analytics

The optional `tags` field labels the context a question was asked from. Tags are stored on the analytics events for the request and do not change the answer. They work on both the standard and streaming endpoints.

If you built AI Mode yourself, see [Tagging AI Mode requests](https://docs.cludo.com/guides/ai-chat-integration.md#tagging-ai-mode-requests) for the tag that makes its requests count as AI Mode.

```json theme={null}
{
  "question": "What is your return policy?",
  "tags": ["<string>"]
}
```

A request is never rejected because of its tags. Instead, the tags are sanitized:

* Each tag is lower-cased, and characters other than `a`–`z`, `0`–`9` and `_` are removed. This also removes surrounding whitespace.
* Each tag is cut to 32 characters.
* Empty tags, duplicate tags and entries that are not strings are dropped.
* Only the first 5 tags are kept.
* A `tags` value that is not an array is ignored.


## OpenAPI

````yaml POST /api/v4/{customerId}/{engineId}/search/answer
openapi: 3.1.0
info:
  title: Cludo AI API
  version: 4.0.0
  description: >-
    AI Chat, streaming answers, feedback and click tracking, and AI Summary
    endpoints for Cludo search engines.
servers:
  - url: https://api.cludo.com
    description: EU region (Customer IDs below 10,000,000)
  - url: https://api-us1.cludo.com
    description: US region (Customer IDs 10,000,000 and above)
security:
  - SiteKey: []
paths:
  /api/v4/{customerId}/{engineId}/search/answer:
    post:
      summary: AI Chat
      description: >-
        Returns a generative answer for the given question, with optional
        citations and multi-turn conversation support. `includeCitations`
        changes the output for both the standard and streaming endpoints.
      operationId: getAiAnswer
      parameters:
        - $ref: '#/components/parameters/customerId'
        - $ref: '#/components/parameters/engineId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AiChatRequest'
      responses:
        '200':
          description: Successful AI Chat response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AiAnswerResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - SiteKey: []
        - BasicAuth: []
components:
  parameters:
    customerId:
      name: customerId
      in: path
      required: true
      description: Your Cludo account ID.
      schema:
        type: integer
    engineId:
      name: engineId
      in: path
      required: true
      description: Search engine ID.
      schema:
        type: integer
  schemas:
    AiChatRequest:
      type: object
      required:
        - question
      properties:
        question:
          type: string
          description: >-
            End-user question in natural language. Grounding content is
            retrieved from your indexed pages.
        conversationId:
          type: string
          format: uuid
          description: >-
            Reuse the **same** id from a previous AI Chat response to continue a
            thread; omit or use a new id to start fresh (streaming responses
            expose ids in headers too).
        language:
          type: string
          description: >-
            ISO-639-1 or simple locale code for answer language (e.g. `en`,
            `da`).
        answerLength:
          type: string
          enum:
            - comprehensive
            - concise
          description: >-
            `comprehensive` for longer explanations; `concise` for short
            answers.
        customPrompt:
          type: string
          description: >-
            Extra system-style instructions (tone, disclaimers, formatting). Use
            sparingly; overrides can affect safety and quality.
        includeCitations:
          type: boolean
          description: >-
            For non-streaming AI Chat, when **true**, the JSON response includes
            `citations` with title, url, and snippet for each source used, and
            `url` is left empty. When **false** (default), `citations` is
            omitted and `url` holds a single primary source link instead. For
            streaming AI Chat, when **true**, inline Markdown citation links are
            included in the streamed text. When **false** (default), the
            streamed text has no inline citations and a single primary source
            URL is surfaced separately. Server default: `False`.
        filters:
          type: object
          additionalProperties:
            type: array
            items:
              type: string
          description: >-
            Restrict the grounding content used to answer the question. Each key
            is an indexed field name mapped to allowed values (e.g.
            `{"Category": ["Guides"]}`). The reserved keys `range`, `date`, and
            `geo_distance` express numeric, date, and geo-distance filters — see
            the Search endpoint's *Filter value formats* for the full grammar.
          example:
            Category:
              - Guides
        valueBoost:
          type: array
          description: >-
            Field boost configurations that influence the ranking of search
            results used as context for the answer. Each entry names an indexed
            field and a list of boost rules, where each rule pairs a numeric
            boost multiplier with the values that trigger it.
          items:
            type: object
            properties:
              fieldName:
                type: string
                description: The indexed field name to boost.
              boosts:
                type: array
                items:
                  type: object
                  properties:
                    boost:
                      type: integer
                    values:
                      type: array
                      items:
                        type: string
        sourceFields:
          type: array
          description: >-
            Document fields to use as grounding context when generating the
            answer. Defaults to `["Title", "Content"]` when omitted. Extend this
            list to include additional indexed fields (e.g. `"Summary"`,
            `"Description"`) so the model can draw on richer content.
          items:
            type: string
          example:
            - Title
            - Content
        tags:
          type: array
          description: >-
            Labels naming the context the question was asked from, recorded on
            the analytics events for the request. If you built AI Mode yourself,
            see the AI Mode section of the [AI Integration
            Guide](/guides/ai-chat-integration#tagging-ai-mode-requests) for the
            tag to send. Tags never cause a request to be rejected. Instead they
            are sanitized: each tag is lower-cased, characters other than
            `a`–`z`, `0`–`9` and `_` are removed, and the result is cut to 32
            characters. Empty tags, duplicates and entries that are not strings
            are dropped, and only the first 5 tags are kept. A value that is not
            an array is ignored.
          maxItems: 5
          items:
            type: string
            maxLength: 32
          example:
            - <string>
    AiAnswerResponse:
      type: object
      properties:
        value:
          $ref: '#/components/schemas/AiAnswerValue'
    AiAnswerValue:
      type: object
      properties:
        answer:
          type: string
          description: Final natural-language reply to show the user.
        url:
          type: string
          description: >-
            Optional primary link when the answer maps cleanly to one
            destination. Only populated when `includeCitations` is `false` —
            when citations are enabled, this is empty and `value.citations` is
            the source of truth instead.
        chatSessionId:
          type: string
          description: >-
            Server-side session id (may align with `conversationId` depending on
            deployment).
        conversationId:
          type: string
          description: >-
            Pass this on the next `AiChatRequest` to continue the same
            conversation.
        exchangeId:
          type: string
          description: >-
            Identifies this specific Q/A pair. Use with feedback and click
            endpoints.
        citations:
          type: array
          description: >-
            Populated in non-streaming AI Chat responses when `includeCitations`
            was true in the request.
          items:
            $ref: '#/components/schemas/AiCitation'
        couldAnswer:
          type: boolean
          description: >-
            Whether the AI was able to generate a meaningful answer from the
            indexed content.
    ErrorResponse:
      type: object
      description: Error response returned when a request fails.
      properties:
        message:
          type: string
          description: A message describing what went wrong.
    UnauthorizedError:
      type: object
      description: Returned when authentication fails.
      properties:
        message:
          type: string
          description: Authentication failure reason.
    ServerError:
      type: object
      description: Returned when an unexpected server error occurs.
      properties:
        status:
          type: string
          description: HTTP status name.
        code:
          type: integer
          description: HTTP status code.
        messages:
          type: array
          items:
            type: string
          description: Error details, usually including a support reference id.
    AiCitation:
      type: object
      properties:
        reference:
          type: integer
          description: Citation number matching `[n]` in the answer text.
        url:
          type: string
          description: Source page URL.
        pageTitle:
          type: string
          description: Title of the source page.
  responses:
    BadRequest:
      description: >-
        The request is invalid. This typically occurs due to missing required
        fields, incorrect parameter values, or malformed request body.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            message: >-
              The request could not be processed. Check the request body and
              required parameters.
    Unauthorized:
      description: >-
        Authentication failed. The Authorization header is missing or contains
        invalid credentials.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/UnauthorizedError'
          example:
            message: unauthorized
    InternalServerError:
      description: >-
        An unexpected server error occurred. If this persists, contact
        support@cludo.com.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ServerError'
          example:
            status: InternalServerError
            code: 500
            messages:
              - >-
                Error occur. Please contact support with error ID:
                a1b2c3d4-e5f6-7890-abcd-ef1234567890
  securitySchemes:
    SiteKey:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        SiteKey authentication. Pass the full value including the `SiteKey`
        prefix: `SiteKey <base64(customerId:engineId:searchKey)>`. Example:
        `SiteKey dGVzdDoxMjM0NTY3Ojk4NzY1`.
    BasicAuth:
      type: http
      scheme: basic
      description: >-
        Basic authentication. Use your Customer ID as the username and API Key
        as the password. Example header: `Authorization: Basic
        MTIzNDU2NzpteS1hcGkta2V5`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.