Skip to main content
POST
https://app.autocalls.ai/api/
/
ai
/
generate-reply
curl -X POST "https://app.autocalls.ai/api/ai/generate-reply" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -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"
    }
  }'
{
  "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
}
This endpoint generates an AI response for a given message using your configured assistant. It automatically creates or reuses conversations based on the customer identifier, making it ideal for integrating AI responses into external platforms, CRMs, or custom chat interfaces.
Rate Limited — This endpoint is rate limited to 5 requests per minute per API token to prevent abuse.

Request Body

assistant_id
integer
required
The ID of the assistant to use for generating the response. Must belong to your account.
customer_identifier
string
required
A unique identifier for the customer. This is used to maintain conversation context across multiple messages.Examples: phone number, email address, CRM contact ID, Facebook user ID.Maximum length: 255 characters.
message
string
required
The customer’s message to respond to.
variables
object
Optional context variables to pass to the assistant. These are merged with any existing conversation variables.Useful for passing customer data, session context, or other metadata.

Response Fields

success
boolean
Indicates whether the request was successful
conversation_id
string
The UUID of the conversation. Use this to track or reference the conversation later.
customer_identifier
string
The customer identifier provided in the request
reply
string
The AI-generated response to the customer’s message
function_calls
array
Array of function calls made by the assistant while processing the message. Empty array if no functions were called.
ai_disabled
boolean
Indicates if AI responses are disabled for this conversation (e.g., due to manual takeover)

Error Responses

success
boolean
Will be false when an error occurs
error
string
Error message describing what went wrong
error_code
string
Machine-readable error code. Possible values:
  • ASSISTANT_NOT_FOUND - The assistant ID is invalid or doesn’t belong to your account
  • INSUFFICIENT_BALANCE - Your account balance is too low to process the message
curl -X POST "https://app.autocalls.ai/api/ai/generate-reply" \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -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"
    }
  }'
{
  "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
}

Use Cases

Multi-Channel AI Responses

Use this endpoint to add AI responses to any messaging platform:
  1. Receive a message from WhatsApp, Facebook, SMS, or any other channel
  2. Call this endpoint with the message and customer identifier
  3. Send the AI response back through the original channel

CRM Integration

Integrate AI responses into your CRM or helpdesk:
  1. Use the CRM contact ID as the customer_identifier
  2. Pass customer data as variables for personalized responses
  3. The conversation persists across sessions using the same identifier

Custom Chat Interfaces

Build your own chat interface powered by your Autocalls assistant:
  1. Generate a unique identifier for each user session
  2. Send messages through this endpoint
  3. Display the AI responses in your interface

Conversation Persistence

Conversations are automatically persisted based on the assistant_id and customer_identifier combination:
  • Same identifier: Messages are added to the existing conversation, maintaining full context
  • New identifier: A new conversation is created for the customer
  • Variables merge: When variables are provided, they are merged with existing conversation variables

Best Practices

  1. Use consistent identifiers: Always use the same format for customer identifiers (e.g., always E.164 for phone numbers)
  2. Pass relevant context: Use the variables field to provide customer data that helps the AI personalize responses
  3. Handle rate limits: Implement retry logic with exponential backoff for rate-limited requests
  4. Store conversation IDs: Save the returned conversation_id for later reference or debugging
  5. Monitor costs: Track usage to manage costs, especially for high-volume integrations