Skip to main content
POST
/
api
/
draft
/
generate
Generate Draft
curl --request POST \
  --url https://api.example.com/api/draft/generate \
  --header 'Content-Type: application/json' \
  --data '
{
  "messages": [
    {}
  ],
  "document": "<string>",
  "categories": [
    {}
  ],
  "signature": "<string>"
}
'
{
  "draft": "<string>",
  "categoryId": "<string>",
  "detectedLanguage": "<string>",
  "error": "<string>",
  "detail": "<string>"
}

Authentication

Requires a valid session. Returns 401 if unauthorized.

Overview

This endpoint uses Claude AI (Anthropic) to analyze an email thread and automatically generate a professional, empathetic customer support reply. The AI considers:
  • Full email thread history
  • Customer’s communication style and language
  • Reference documentation for your service
  • Available support categories
  • Agent signature

Request Body

messages
array
required
Array of email messages in the thread, ordered chronologicallyEach message object contains:
  • direction (string): Either "inbound" (from customer) or "outbound" (from support)
  • fromName (string): Sender’s name
  • timestamp (string): ISO 8601 timestamp
  • body (string): Email body (HTML or plain text)
document
string
required
Reference documentation about your product/service. The AI uses this to provide accurate, context-aware responses.
categories
array
required
Array of available support categoriesEach category object contains:
  • id (string): Unique category identifier
  • name (string): Display name
signature
string
Agent’s email signature (HTML). Will be automatically appended to the generated draft.

AI Processing

The endpoint constructs a specialized prompt that:
  1. Provides the AI with your reference documentation
  2. Formats the email thread for context
  3. Lists available categories for classification
  4. Instructs the AI to:
    • Write in HTML format using semantic tags
    • Match the customer’s language
    • Be warm, empathetic, and solution-focused
    • Use the customer’s first name
    • Select the most appropriate category
    • Exclude greeting/sign-off (signature is added separately)

Claude API Configuration

  • Model: claude-sonnet-4-6
  • Max Tokens: 1024
  • Role: User prompt with structured instructions

Response

draft
string
Generated email reply in HTML format. Includes the signature if provided in the request.
categoryId
string
The AI-selected category ID from the provided list
detectedLanguage
string
Two-letter language code (e.g., “en”, “ko”, “es”) detected from the customer’s messages

Example Request

curl -X POST https://api.delightbridge.com/api/draft/generate \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-token" \
  -d '{
    "messages": [
      {
        "direction": "inbound",
        "fromName": "Sarah Chen",
        "timestamp": "2026-03-01T09:15:00Z",
        "body": "Hi, I am interested in upgrading to your premium plan. Can you tell me what features are included?"
      },
      {
        "direction": "outbound",
        "fromName": "Alex (Support)",
        "timestamp": "2026-03-01T09:30:00Z",
        "body": "<p>Hi Sarah, thanks for your interest! Let me get you those details.</p>"
      },
      {
        "direction": "inbound",
        "fromName": "Sarah Chen",
        "timestamp": "2026-03-01T10:00:00Z",
        "body": "Also, is there a discount for annual billing?"
      }
    ],
    "document": "Premium Plan Features:\n- Unlimited email threads\n- AI-powered drafts\n- Multi-language support\n- Priority support\n\nPricing: $99/month or $990/year (save 2 months)",
    "categories": [
      { "id": "billing", "name": "Billing & Pricing" },
      { "id": "features", "name": "Product Features" },
      { "id": "technical", "name": "Technical Support" }
    ],
    "signature": "<p>Best regards,<br>Alex Kim<br>Customer Success Team</p>"
  }'

Example Response

{
  "draft": "<p>Hi Sarah,</p><p>Great questions! Our Premium plan includes unlimited email threads, AI-powered draft generation, multi-language support, and priority support access.</p><p>Regarding pricing, we offer two options:</p><ul><li><strong>Monthly:</strong> $99/month</li><li><strong>Annual:</strong> $990/year (you save the equivalent of 2 months!)</li></ul><p>The annual plan is definitely the better value if you're planning to use the service long-term. Would you like me to help you get started with the upgrade?</p><hr><p>Best regards,<br>Alex Kim<br>Customer Success Team</p>",
  "categoryId": "billing",
  "detectedLanguage": "en"
}

Multi-Language Example

The AI automatically detects and responds in the customer’s language: Request with Korean customer message:
{
  "messages": [
    {
      "direction": "inbound",
      "fromName": "김민수",
      "timestamp": "2026-03-01T10:00:00Z",
      "body": "안녕하세요, 프리미엄 플랜으로 업그레이드하고 싶은데 어떻게 하나요?"
    }
  ],
  "document": "...",
  "categories": [...]
}
Response:
{
  "draft": "<p>안녕하세요 민수님,</p><p>프리미엄 플랜에 관심 가져주셔서 감사합니다! 업그레이드는 매우 간단합니다...</p>",
  "categoryId": "features",
  "detectedLanguage": "ko"
}

Error Responses

error
string
Error message describing what went wrong
detail
string
Additional error details (only included in 500 errors)

401 Unauthorized

{
  "error": "Unauthorized"
}

500 Internal Server Error

{
  "error": "Failed to generate draft",
  "detail": "Claude API rate limit exceeded"
}
Common causes:
  • Claude API quota exceeded
  • Invalid API key
  • Malformed prompt
  • Network timeout

Best Practices

  1. Reference Documentation: Keep your document field updated with accurate product information
  2. Message Context: Include the full thread history for better AI understanding
  3. Categories: Provide clear, distinct category names for accurate classification
  4. HTML Cleanup: The API strips HTML tags from messages before processing, so both HTML and plain text inputs work
  5. Error Handling: Implement retry logic for transient failures
  6. Language Detection: Trust the AI’s language detection rather than pre-specifying it

Build docs developers (and LLMs) love