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

# Trigger AI Reply

> Triggers an AI-generated reply to a specific message in a chat. The AI agent processes the message context and generates an appropriate response asynchronously.

**Requirements:**
- Organization must have an active subscription
- Organization must be on the Pro plan
- AI agent must be enabled at the organization level
- AI agent must be enabled for the specific chat

This is an asynchronous endpoint - it queues the AI reply for processing and returns immediately with a trace ID for tracking.



## OpenAPI

````yaml POST /ai/reply
openapi: 3.0.3
info:
  title: API - Local
  description: >-
    #### Welcome to the official Postman collection of Periskope API


    Periskope APIs enable you automate actions on your WhatsApp phone, and the
    Periskope platform


    - Read more about the APIs & webhooks here -
    [https://docs.periskope.app/api-reference/introduction](https://docs.periskope.app/api-reference/introduction)
        
    - We encourage responsible usage of the APIs. Follow these best practices
    and recommendations for safe actions on WhatsApp -
    [https://docs.periskope.app/get-started/best-practices](https://docs.periskope.app/get-started/best-practices)
        

    #### Getting Started


    ##### Pre-requisites:


    1. **Sign up for a free account on Periskope:** To use the Periskope API,
    you need to have an active Periskope account. If you don’t have one, you can
    sign up for a 7-day free trial [here](https://console.periskope.app).
        
    2. **Scan the QR code from WhatsApp to connect your phone:** A connected
    phone is required to use the APIs
        
    3. **Go to** [Settings &gt;
    API](https://console.periskope.app/settings/api), and generate an API key
    for your organization - The API key is used to authenticate every request.
    Please keep this secure
        

    ##### Using Postman:


    1. **Fork the collection so you can edit values and test the APIs in your
    own postman environment:** To fork the collection, click on the three dots
    next to v1. Then click on create a fork (_shortcut: Ctrl + Alt + F)._
        
    2. **Update the value of the variables in the collection:**  
        \- Update the API key with the key generated in Step 3  
        \- Update the phone number with your connected number. This number will be added to the `x-phone` header across requests
        
        It must be in the format of country code+number, with no special characters or spaces _e.g. +91 98745 32456 becomes 919874532456_
        

    For any help or feedback, please contact us at
    [support@periskope.app](https://mailto:support@periskope.app), or ping us on
    [WhatsApp](https://what.sapp.link/periskope)
  version: 1.0.0
  contact: {}
servers:
  - url: https://api.periskope.app/v1
security:
  - bearerAuth: []
tags:
  - name: contacts
  - name: tickets
  - name: tasks
  - name: phones
  - name: message
  - name: queue
  - name: chats
  - name: group
  - name: members
  - name: webhooks
  - name: custom properties
paths:
  /ai/reply:
    post:
      tags:
        - ai
      summary: Trigger AI Reply
      description: >-
        Triggers an AI-generated reply to a specific message in a chat. The AI
        agent processes the message context and generates an appropriate
        response asynchronously.


        **Requirements:**

        - Organization must have an active subscription

        - Organization must be on the Pro plan

        - AI agent must be enabled at the organization level

        - AI agent must be enabled for the specific chat


        This is an asynchronous endpoint - it queues the AI reply for processing
        and returns immediately with a trace ID for tracking.
      operationId: triggerAiReply
      parameters:
        - name: x-phone
          in: header
          schema:
            type: string
            example: '919874532456'
          description: The connected WhatsApp phone number for scope validation
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - chat_id
                - unique_id
                - org_phone
              properties:
                chat_id:
                  type: string
                  description: The unique identifier of the chat to reply in
                  example: 120363025896399300@g.us
                unique_id:
                  type: string
                  description: >-
                    The unique_id of the message to reply to. The AI will use
                    this message and its surrounding context to generate a reply
                  example: BAE58B775A57D71E
                org_phone:
                  type: string
                  description: >-
                    The phone number of the organization (connected WhatsApp
                    number) in the format country_code + number without special
                    characters
                  example: '919874532456'
            example:
              chat_id: 120363025896399300@g.us
              unique_id: BAE58B775A57D71E
              org_phone: '919874532456'
      responses:
        '200':
          description: AI reply triggered successfully
          headers:
            x-periskope-org-id:
              schema:
                type: string
              description: The organization ID
            x-periskope-trace-id:
              schema:
                type: string
              description: Trace ID for the request
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: AI reply triggered
                  trace_id:
                    type: string
                    format: uuid
                    example: a1b2c3d4-e5f6-7890-abcd-ef1234567890
                    description: A unique trace ID for tracking the AI reply processing
              example:
                success: true
                message: AI reply triggered
                trace_id: a1b2c3d4-e5f6-7890-abcd-ef1234567890
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  message:
                    type: string
                    example: AI agent is not enabled for this organization
              examples:
                agent_not_available:
                  summary: AI agent not available
                  value:
                    success: false
                    message: AI agent is not available for this organization
                subscription_inactive:
                  summary: Subscription inactive
                  value:
                    success: false
                    message: Organization subscription is inactive
                pro_plan_required:
                  summary: Pro plan required
                  value:
                    success: false
                    message: AI agent requires a Pro plan
                agent_not_enabled_org:
                  summary: Agent not enabled for org
                  value:
                    success: false
                    message: AI agent is not enabled for this organization
                agent_not_enabled_chat:
                  summary: Agent not enabled for chat
                  value:
                    success: false
                    message: AI agent is not enabled for this chat
        '401':
          description: Unauthorized - Invalid or missing API key
      security:
        - apikeyAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````