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

# Generate reply

> Generate an AI reply to a customer message, keyed by a customer identifier.

Generates an AI response for a customer message using your assistant. Conversations are automatically created or resumed based on the `customer_identifier`, making this ideal for integrating AI replies into external platforms, CRMs, or custom messaging interfaces.

<Info>
  This endpoint is rate-limited to **5 requests per minute** per API token.
</Info>

## Endpoint

`POST /user/ai/generate-reply`

## Request

<ParamField body="assistant_id" type="integer" required>
  ID of the assistant to use. Must belong to your account.
</ParamField>

<ParamField body="customer_identifier" type="string" required>
  A unique identifier for the customer. Used to maintain conversation context across multiple messages. Examples: phone number, email, CRM contact ID, Facebook user ID. Maximum 255 characters.
</ParamField>

<ParamField body="message" type="string" required>
  The customer's message to respond to.
</ParamField>

<ParamField body="variables" type="object">
  Optional context variables to pass to the assistant. Merged with any existing conversation variables.
</ParamField>

## Response

<ResponseField name="success" type="boolean">Whether the request was successful.</ResponseField>
<ResponseField name="conversation_id" type="string">UUID of the conversation. Use this to reference the conversation later.</ResponseField>
<ResponseField name="customer_identifier" type="string">The customer identifier provided in the request.</ResponseField>
<ResponseField name="reply" type="string">The AI-generated response.</ResponseField>

<ResponseField name="function_calls" type="array">
  Functions the assistant executed while processing the message.

  <Expandable title="Function call properties">
    <ResponseField name="name" type="string">Name of the function called.</ResponseField>
    <ResponseField name="arguments" type="object">Arguments passed to the function.</ResponseField>
    <ResponseField name="result" type="object">Result returned by the function.</ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="ai_disabled" type="boolean">Whether AI responses are disabled for this conversation (e.g., due to manual takeover).</ResponseField>

## Example

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST "https://portal.intellixent.ai/api/user/ai/generate-reply" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "assistant_id": 123,
      "customer_identifier": "+14155551234",
      "message": "Hi, I would like to schedule an appointment",
      "variables": {
        "customer_name": "John Smith",
        "source": "whatsapp"
      }
    }'
  ```

  ```javascript Node.js theme={null}
  const response = await fetch('https://portal.intellixent.ai/api/user/ai/generate-reply', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer YOUR_API_KEY',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      assistant_id: 123,
      customer_identifier: '+14155551234',
      message: 'Hi, I would like to schedule an appointment',
      variables: {
        customer_name: 'John Smith',
        source: 'whatsapp'
      }
    })
  });

  const data = await response.json();
  console.log(data.reply);
  ```
</CodeGroup>

```json 200 Success theme={null}
{
  "success": true,
  "conversation_id": "7c9e6679-7425-40de-944b-e07fc1f90ae7",
  "customer_identifier": "+14155551234",
  "reply": "Hi John! I'd be happy to help you schedule an appointment. What day and time work best for you?",
  "function_calls": [],
  "ai_disabled": false
}
```

```json 404 Assistant not found theme={null}
{
  "success": false,
  "error": "Assistant not found or does not belong to you",
  "error_code": "ASSISTANT_NOT_FOUND"
}
```

```json 402 Insufficient balance theme={null}
{
  "success": false,
  "error": "Insufficient balance. Please top up your account.",
  "error_code": "INSUFFICIENT_BALANCE"
}
```

```json 429 Rate limited theme={null}
{
  "message": "Too Many Attempts.",
  "retry_after": 60
}
```

## Conversation persistence

Conversations are automatically persisted by `assistant_id` + `customer_identifier`:

* **Same identifier**: Messages are added to the existing conversation, maintaining full context.
* **New identifier**: A new conversation is created.
* **Variables merge**: Variables provided in the request are merged with existing conversation variables.

<Tip>
  Use consistent identifier formats (e.g., always E.164 format for phone numbers) to ensure conversation continuity across requests.
</Tip>
