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

# Generate Email (Async)

> Generate one email or a multi-email series for a project using its brand context and optional images. Provide count (1-12) to request a specific series length, or omit it to infer from the prompt. Returns immediately with a conversationId and pending status. Use GET /v1/projects/emails/{conversationId}/status to retrieve production HTML, screenshots, and per-email IDs.



## OpenAPI

````yaml /api-reference/openapi.json post /v1/projects/emails/generate
openapi: 3.1.0
info:
  title: Migma.ai API (v1)
  description: >-
    API for managing brands, contacts, email generation, sending, and
    integrations.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.migma.ai
    description: Production
security:
  - apiKeyAuth: []
tags:
  - name: Projects/Brands
    description: Manage projects (brands) and import from websites
  - name: Contacts
    description: Manage your contacts, segments, tags, and topics
  - name: Segments
    description: Create and manage dynamic contact segments
  - name: Tags
    description: Organize contacts with tags
  - name: Topics
    description: Manage subscription topics and preferences
  - name: Emails
    description: Generate, send, and export emails
  - name: Email Validation
    description: Validate email content for compatibility and deliverability
  - name: Email Previews
    description: Preview emails across devices and email clients
  - name: Domains
    description: Manage sending domains and verification
  - name: Webhooks
    description: Manage webhook endpoints for real-time event notifications
  - name: Integrations
    description: Third-party platform integrations
  - name: Campaigns
    description: Create, schedule, send, and manage email campaigns
  - name: Project Editing
    description: Edit project assets, logos, images, and knowledge base entries
paths:
  /v1/projects/emails/generate:
    post:
      tags:
        - Emails
      summary: Generate Email (Async)
      description: >-
        Generate one email or a multi-email series for a project using its brand
        context and optional images. Provide count (1-12) to request a specific
        series length, or omit it to infer from the prompt. Returns immediately
        with a conversationId and pending status. Use GET
        /v1/projects/emails/{conversationId}/status to retrieve production HTML,
        screenshots, and per-email IDs.
      operationId: GenerateEmail
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateEmailRequest'
      responses:
        '200':
          description: Email generation started
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiResponseGenerateEmail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '404':
          $ref: '#/components/responses/NotFound'
      x-codeSamples:
        - lang: javascript
          label: Node.js SDK
          source: |-
            import Migma from 'migma';

            const migma = new Migma('YOUR_API_KEY');

            const { data, error } = await migma.emails.generate({
              projectId: 'PROJECT_ID',
              prompt: 'Create a three-email onboarding series',
              count: 3,
              languages: ['en']
            });

            // Poll /status or use generateAndWait() to get result.emails[].
components:
  schemas:
    GenerateEmailRequest:
      type: object
      properties:
        projectId:
          type: string
          pattern: ^[0-9a-fA-F]{24}$
        prompt:
          type: string
        images:
          type: array
          items:
            $ref: '#/components/schemas/EmailImage'
          maxItems: 5
        model:
          type: string
          default: migmaAI-model-v0.1
        webMode:
          type: boolean
          default: true
          description: >-
            Allow MigmaAI to do research, use connectors, mcp and more. It may
            take longer to generate the email. Use only if the prompt is unclear
            or requires additional information.
        languages:
          type: array
          items:
            type: string
          maxItems: 5
          description: >-
            The languages to generate the email in. If not provided, the email
            will be generated as instructed by the prompt.
        visibility:
          type: string
          enum:
            - private
            - unlisted
            - public
          default: private
          description: >-
            Set the visibility of the generated conversation. Private
            conversations are only visible to the user, unlisted conversations
            are accessible via direct link but not listed publicly, and public
            conversations are visible in the public gallery.
        referenceId:
          type: string
          pattern: ^[0-9a-fA-F]{24}$
          description: >-
            Optional conversation ID to remix so you can create personalized
            variants from an existing conversation.
        count:
          type: integer
          minimum: 1
          maximum: 12
          description: >-
            Optional target number of emails to generate for a series. Omit to
            let Migma infer single email vs series from the prompt.
      required:
        - projectId
        - prompt
    ApiResponseGenerateEmail:
      allOf:
        - $ref: '#/components/schemas/ApiResponse'
        - type: object
          properties:
            data:
              $ref: '#/components/schemas/GenerateEmailData'
    EmailImage:
      type: object
      properties:
        source:
          $ref: '#/components/schemas/EmailImageSource'
      required:
        - source
    ApiResponse:
      type: object
      properties:
        success:
          type: boolean
        data:
          nullable: true
        error:
          type: string
          nullable: true
      required:
        - success
    GenerateEmailData:
      type: object
      properties:
        conversationId:
          type: string
          description: The conversation ID to check status and retrieve results
        status:
          type: string
          enum:
            - pending
          description: Initial status is always pending
        message:
          type: string
          description: Information message about the generation process
        link:
          type: string
          format: uri
          description: >-
            Direct link to view the email in Migma dashboard
            (https://migma.ai/chat?c={conversationId})
        count:
          type: integer
          description: Requested email count, when provided.
        referenceId:
          type: string
          description: Reference conversation used for remixing, when provided.
      required:
        - conversationId
        - status
        - message
        - link
    ApiError:
      type: object
      properties:
        success:
          type: boolean
          default: false
        error:
          type: string
      required:
        - success
        - error
    EmailImageSource:
      type: object
      properties:
        type:
          type: string
          enum:
            - url
          default: url
        url:
          type: string
          format: uri
      required:
        - type
        - url
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    Unauthorized:
      description: Unauthorized
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: Authorization
      description: >-
        API key authentication. Use 'Authorization: Bearer YOUR_API_KEY' where
        YOUR_API_KEY is obtained from the Migma dashboard under Settings → API
        Integration.

````