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

# AI Generate Content

> Generate a complete HTML email body using Gately's built-in AI

Uses Gately's AI model (Kimi K2) to produce inline-styled, email-client-compatible HTML based on your campaign name, subject, and desired tone. The returned HTML can be passed directly to the [Send Campaign](/docs/api-reference/campaigns/send) endpoint.

## Headers

<ParamField header="Authorization" type="string" required>
  `Bearer YOUR_API_KEY`
</ParamField>

<ParamField header="X-Project-ID" type="string">
  Your project UUID. Not required if the API key already encodes the project.
</ParamField>

## Request Body

<ParamField body="campaignName" type="string" required>
  Name of the campaign — used as the primary context for generation
</ParamField>

<ParamField body="subject" type="string">
  Email subject line — provides additional context for the AI
</ParamField>

<ParamField body="tone" type="string" default="professional">
  Writing tone: `professional` · `friendly` · `casual` · `urgent`
</ParamField>

## Response

<ResponseField name="html" type="string">
  Complete, inline-styled HTML email body ready to send
</ResponseField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.usegately.com/api/v1/campaigns/ai-generate" \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "X-Project-ID: YOUR_PROJECT_ID" \
    -H "Content-Type: application/json" \
    -d '{
      "campaignName": "Summer Sale",
      "subject": "50% off everything this weekend",
      "tone": "friendly"
    }'
  ```

  ```typescript SDK — generate only theme={null}
  import { GatelyCampaigns } from '@gately/sdk'

  const campaigns = new GatelyCampaigns({ projectId: 'YOUR_PROJECT_ID' })

  const { html } = await campaigns.aiGenerate({
    campaignName: 'Summer Sale',
    subject: '50% off everything this weekend',
    tone: 'friendly',
  })
  ```

  ```typescript SDK — generate and send in one call theme={null}
  import { GatelyCampaigns } from '@gately/sdk'

  const campaigns = new GatelyCampaigns({ projectId: 'YOUR_PROJECT_ID' })

  const result = await campaigns.aiSend({
    campaignName: 'Summer Sale',
    subject: '50% off everything this weekend',
    tone: 'friendly',
    recipient_all_contacts: true,
  })

  console.log(`Sent to ${result.successful_sends} recipients`)
  ```
</RequestExample>

<ResponseExample>
  ```json Success theme={null}
  {
    "html": "<div style=\"font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 30px;\">\n  <h1 style=\"color: #333;\">Summer Sale — 50% Off!</h1>\n  <p style=\"color: #555; line-height: 1.6;\">Hi there,</p>\n  <p style=\"color: #555; line-height: 1.6;\">We're excited to announce our biggest sale of the year...</p>\n  <a href=\"#\" style=\"display: inline-block; background: #FE551B; color: white; padding: 12px 24px; border-radius: 6px; text-decoration: none; font-weight: bold;\">Shop Now</a>\n</div>"
  }
  ```

  ```json Missing required field theme={null}
  {
    "error": "campaignName is required"
  }
  ```
</ResponseExample>
