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

# Create an ai message

> Creates a non-prompt-library (workspace-owned) entry. Requires the AI variable split to be enabled for the workspace; otherwise returns 403 and the legacy `POST /v1/ai-variables` (aiField) endpoint must be used instead.

    > **Required scope:** `AI_VARIABLES_WRITE`
    >
    > **Rate limit:** 30 requests per minute



## OpenAPI

````yaml https://openapi.enginy.ai/definitions.json post /v1/ai-variables/ai-messages
openapi: 3.1.0
info:
  title: Enginy API
  version: 1.0.0
  description: Public API for Enginy platform
servers:
  - url: https://openapi.enginy.ai
    description: Configured server
security: []
tags:
  - name: AI Variables
    description: >-
      Manage AI variables and discover the entity fields you can reference in
      prompts and entity requests.
  - name: Inbox
    description: >-
      Inbox endpoints for listing contact threads, reading thread messages,
      managing tags, and sending manual replies.
  - name: Workflows
    description: >-
      Build, validate, publish, run, and inspect advanced (graph) workflows,
      plus the block/condition catalog needed to author a workflow plan.
paths:
  /v1/ai-variables/ai-messages:
    post:
      tags:
        - AI Variables
      summary: Create an ai message
      description: >-
        Creates a non-prompt-library (workspace-owned) entry. Requires the AI
        variable split to be enabled for the workspace; otherwise returns 403
        and the legacy `POST /v1/ai-variables` (aiField) endpoint must be used
        instead.

            > **Required scope:** `AI_VARIABLES_WRITE`
            >
            > **Rate limit:** 30 requests per minute
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                description:
                  type:
                    - string
                    - 'null'
                channel:
                  type: string
                  enum:
                    - EMAIL
                    - LINKEDIN
                    - WHATSAPP
                    - LINKEDIN_INMAIL
                    - LINKEDIN_CONNECTION
                toneId:
                  type: string
                  minLength: 1
                model:
                  type: string
                  minLength: 1
                outputLength:
                  type: integer
                  minimum: 0
                  maximum: 10
                splitMessages:
                  type: boolean
                prompt:
                  type: string
                  description: >-
                    Plain prompt text. Placeholders: `{fieldId}` for
                    contact/company/CRM/formula/notes fields (discover via the
                    contact/company field-metadata endpoints),
                    `{aiResearch:<id-or-name>}`, `{aiSnippet:<id-or-name>}`,
                    `{aiMessage:<id-or-name>}` for AI entity references.
                    Validation is strict: unknown or ambiguous tokens return 400
                    with the invalid tokens and a sample of valid ones. Escape
                    literal braces by doubling them (`{{` and `}}`).
                folderId:
                  type:
                    - number
                    - 'null'
                customPromptFieldValues:
                  type: array
                  items:
                    type: object
                    properties:
                      customPromptFieldId:
                        type: string
                        minLength: 1
                      value:
                        anyOf:
                          - type: string
                          - type: 'null'
                    required:
                      - customPromptFieldId
                      - value
              required:
                - name
                - channel
                - toneId
                - model
                - outputLength
                - prompt
      responses:
        '201':
          description: AI message created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - success
                  message:
                    type: string
                  data:
                    type: object
                    description: The created AI variable entity.
                    additionalProperties: true
                required:
                  - status
                  - message
        '400':
          description: >-
            Invalid prompt tokens (unknown, ambiguous name, or reference type
            not allowed for this entity) — `details.issues` lists each problem
            and `details.validTokenSample` shows valid tokens
        '403':
          description: AI variable split not enabled for this workspace
        '409':
          description: Conflict - an entity with this name already exists
      security:
        - apiKey: []
components:
  securitySchemes:
    apiKey:
      type: apiKey
      in: header
      name: x-api-key

````