---
updatedAt: 2026-08-06T09:23:09.000Z
agentTools:
  projectIndex: https://developers.alcmeon.com/llms.txt
---

# Send AI generated answer (V2)

V2 endpoint to invoke to send an AI generated answer to a social network user via bot scenario. 
This version supports custom exit codes and enhanced variable handling for bot scenarios. Once your AI API has been asynchronously called by Alcméon with a jwt specific for a given social network user,  this endpoint can be invoked (with the jwt previously received) to send the generated answer and trigger the appropriate scenario exit.


# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "AI",
    "version": "1.0"
  },
  "servers": [
    {
      "url": "https://api.alcmeon.com",
      "description": "Alcmeon production API server"
    }
  ],
  "x-readme": {
    "explorer-enabled": false
  },
  "components": {
    "securitySchemes": {
      "basic_auth": {
        "description": "Basic authentication using your environment Instance ID as username and Application Secret as password.\n",
        "type": "http",
        "scheme": "basic"
      },
      "bearer_token": {
        "description": "OAuth 2.0 Bearer token authentication.  Obtain a token by calling the /v1/oauth2/token endpoint with your credentials. The token is valid for one hour.\n",
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT"
      }
    },
    "schemas": {
      "ResponseError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "A short string explaining the reason of the error."
          },
          "details": {
            "type": "string",
            "description": "A short string which describes what is wrong. Provide this string to  support@alcmeon.com if you wish to obtain more details about the problem.\n"
          }
        }
      },
      "RateLimitResponseError": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string",
            "description": "Rate limit reached"
          },
          "details": {
            "type": "string",
            "description": "A string showing the time when the rate limit will be reset. Example: {'rate_limited_until': '2024-01-22T13:05:41Z'}\n"
          }
        }
      }
    }
  },
  "security": [
    {
      "basic_auth": []
    },
    {
      "bearer_token": []
    }
  ],
  "paths": {
    "/ai/v2/answer": {
      "post": {
        "summary": "Send AI generated answer (V2)",
        "description": "V2 endpoint to invoke to send an AI generated answer to a social network user via bot scenario. \nThis version supports custom exit codes and enhanced variable handling for bot scenarios. Once your AI API has been asynchronously called by Alcméon with a jwt specific for a given social network user,  this endpoint can be invoked (with the jwt previously received) to send the generated answer and trigger the appropriate scenario exit.\n",
        "parameters": [
          {
            "in": "header",
            "name": "X-JWT",
            "schema": {
              "type": "string",
              "description": "The JWT token string received in the `jwt.token` field from the webhook payload. This JWT is valid for 60 seconds and can only be used once. You cannot reuse a JWT received for user A to send an AI generated answer to another user B."
            },
            "required": true
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "required": [
                  "code",
                  "message",
                  "variables"
                ],
                "properties": {
                  "code": {
                    "type": "string",
                    "description": "Exit code to determine which scenario path to take. Must match one of the exit codes provided in the webhook request. Can be one of the standard exit codes (endDiscussion, continueDiscussion, escalateToHuman, error)  or a custom exit code defined in the AI Agent settings.\n"
                  },
                  "message": {
                    "description": "The message to send to the social network user.  Set to null if no message should be sent (e.g., when only setting variables or choosing an exit without a response). Otherwise, provide a message object with the content to send.\n",
                    "nullable": true,
                    "oneOf": [
                      {
                        "type": "object",
                        "description": "Text message to send to the user",
                        "required": [
                          "type",
                          "text"
                        ],
                        "properties": {
                          "type": {
                            "type": "string",
                            "enum": [
                              "text"
                            ],
                            "description": "The type of message content. Currently only 'text' is supported."
                          },
                          "text": {
                            "type": "string",
                            "description": "The generated response content to send to the social network user. Must respect the max_message_content_length from the webhook request."
                          }
                        }
                      }
                    ]
                  },
                  "variables": {
                    "type": "object",
                    "description": "A dictionary of custom variables to be stored in the bot context and used later in the scenario. Can include any data such as sentiment analysis, extracted entities, or other metadata.\n"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Success - Answer processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "status"
                  ],
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": [
                        "ok",
                        "canceled"
                      ],
                      "description": "'ok' - The answer was successfully processed and the bot scenario will continue with the chosen exit. 'canceled' - The token was canceled because the user sent a new message before the AI could respond. The answer is ignored.\n"
                    }
                  }
                },
                "examples": {
                  "success": {
                    "value": {
                      "status": "ok"
                    },
                    "summary": "Answer processed successfully"
                  },
                  "canceled": {
                    "value": {
                      "status": "canceled"
                    },
                    "summary": "Token canceled by new user message"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - Invalid or expired token, or malformed JSON payload",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResponseError"
                },
                "examples": {
                  "invalid_token": {
                    "value": {
                      "error": "Invalid token",
                      "details": "Token not found or already consumed"
                    },
                    "summary": "Invalid token"
                  },
                  "expired_token": {
                    "value": {
                      "error": "Invalid token",
                      "details": "Token has expired (60 second limit)"
                    },
                    "summary": "Expired token"
                  },
                  "invalid_state": {
                    "value": {
                      "error": "Invalid token",
                      "details": "Token state is not pending"
                    },
                    "summary": "Token already used or in invalid state"
                  }
                }
              }
            }
          },
          "429": {
            "description": "Rate limit reached. For this route limit is 150 requests per minute.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RateLimitResponseError"
                }
              }
            }
          }
        }
      }
    }
  }
}
```