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

# Generate email draft

> Generates an email subject and HTML draft from campaign context and the active workspace brand settings.



## OpenAPI

````yaml /openapi.json post /api/v1/ai/generate
openapi: 3.1.0
info:
  title: Nudgen Developer API
  version: 1.0.0
  description: >-
    REST API for managing Nudgen contacts, campaigns, brand settings, and AI
    email drafts with Personal Access Token authentication.
servers:
  - url: https://nudgen.net
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Identity
  - name: Contacts
  - name: Campaigns
  - name: Brand settings
  - name: AI
paths:
  /api/v1/ai/generate:
    post:
      tags:
        - AI
      summary: Generate email draft
      description: >-
        Generates an email subject and HTML draft from campaign context and the
        active workspace brand settings.
      operationId: generateEmailDraft
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GenerateEmailDraftRequest'
            example:
              campaignGoal: Write a short retention email inviting users to try Nudgen.
              link: https://nudgen.net
              personalizationMode: 'off'
      responses:
        '200':
          description: Generated draft
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EmailDraft'
        '400':
          $ref: '#/components/responses/BadRequest'
        '429':
          $ref: '#/components/responses/RateLimited'
components:
  schemas:
    GenerateEmailDraftRequest:
      type: object
      required:
        - campaignGoal
      properties:
        campaignGoal:
          type: string
        context:
          type:
            - string
            - 'null'
        link:
          type:
            - string
            - 'null'
          format: uri
        templateId:
          type:
            - string
            - 'null'
        templateHtml:
          type:
            - string
            - 'null'
        templateSubject:
          type:
            - string
            - 'null'
        autoSelectTemplate:
          type: boolean
        personalizationMode:
          type: string
          enum:
            - 'off'
            - lead_description_intro
          default: 'off'
    EmailDraft:
      type: object
      properties:
        subject:
          type: string
        html:
          type: string
        generationMode:
          type: string
    ErrorResponse:
      type: object
      properties:
        error:
          type: string
  responses:
    BadRequest:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: PAT
      description: Personal Access Token created from Settings -> API Keys.

````