Skip to main content
POST
/
api
/
draft
/
translate
Translate Draft
curl --request POST \
  --url https://api.example.com/api/draft/translate \
  --header 'Content-Type: application/json' \
  --data '
{
  "draft": "<string>"
}
'
{
  "translation": "<string>",
  "error": "<string>"
}

Authentication

Requires a valid session. Returns 401 if unauthorized.

Overview

This endpoint uses Claude AI to translate customer support email drafts into Korean while preserving the professional and empathetic tone. It’s designed for teams that need to provide bilingual support.

Request Body

draft
string
required
Draft content to translate (HTML format). HTML tags are stripped before translation.

AI Processing

The endpoint:
  1. Strips HTML tags from the draft to extract plain text
  2. Sends the text to Claude with specific translation instructions
  3. Returns the Korean translation as plain text
  4. Wraps the translation in a <p> tag for consistency
The AI is instructed to:
  • Translate to Korean
  • Preserve professional and empathetic tone
  • Maintain the original meaning
  • Output plain text (no HTML)

Claude API Configuration

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

Response

translation
string
Korean translation wrapped in <p> tags

Example Request

curl -X POST https://api.delightbridge.com/api/draft/translate \
  -H "Content-Type: application/json" \
  -H "Cookie: session=your-session-token" \
  -d '{
    "draft": "<p>Hi Sarah,</p><p>Thank you for reaching out about the premium plan. I would be happy to help you understand the features and pricing.</p><p>The premium plan includes unlimited email threads, AI-powered drafts, multi-language support, and priority customer support. The monthly price is $99, or you can save by choosing our annual plan at $990 (equivalent to 10 months).</p><p>Would you like me to help you get started with the upgrade?</p>"
  }'

Example Response

{
  "translation": "<p>안녕하세요 Sarah님,\n\n프리미엄 플랜에 대해 문의해 주셔서 감사합니다. 기능과 가격에 대해 기꺼이 안내해 드리겠습니다.\n\n프리미엄 플랜에는 무제한 이메일 스레드, AI 기반 초안 작성, 다국어 지원, 그리고 우선 고객 지원이 포함됩니다. 월간 요금은 $99이며, 연간 플랜을 선택하시면 $990(10개월분에 해당)으로 절약하실 수 있습니다.\n\n업그레이드를 시작하실 수 있도록 도와드릴까요?</p>"
}

Use Cases

Bilingual Support Teams

Provide both English and Korean versions of replies:
  1. Generate draft in English using /api/draft/generate
  2. Translate to Korean using /api/draft/translate
  3. Store both versions in the draft record
  4. Display both to bilingual agents

Quality Assurance

Agents can review the translation before sending:
// Generate and translate in parallel
const [generated, translated] = await Promise.all([
  fetch('/api/draft/generate', { method: 'POST', body: generateParams }),
  fetch('/api/draft/translate', { method: 'POST', body: translateParams })
]);

const [generatedData, translatedData] = await Promise.all([
  generated.json(),
  translated.json()
]);

// Save both versions
await fetch('/api/drafts/thread-123', {
  method: 'PUT',
  body: JSON.stringify({
    content: generatedData.draft,
    translation: translatedData.translation
  })
});

Customer Language Preference

Some customers may prefer Korean even if they wrote in English:
if (customer.preferredLanguage === 'ko') {
  const translation = await translateDraft(draft);
  await sendEmail(translation);
} else {
  await sendEmail(draft);
}

Technical Details

HTML Stripping

The API automatically strips HTML tags before translation:
// Input
"<p>Hello <strong>John</strong>,</p><p>Thank you for contacting us.</p>"

// Processed as
"Hello John, Thank you for contacting us."

// Output
"<p>안녕하세요 John님, 문의해 주셔서 감사합니다.</p>"

Markdown Cleanup

If Claude returns markdown code fences, they’re automatically removed:
// Claude might return
"```json\n{\"translation\": \"...\"}\n```"

// API returns clean JSON
{"translation": "..."}

Paragraph Wrapping

Translations are wrapped in <p> tags for consistency with the rest of the system:
// Claude returns plain text
"안녕하세요..."

// API wraps it
"<p>안녕하세요...</p>"

Error Responses

error
string
Error message describing what went wrong

401 Unauthorized

{
  "error": "Unauthorized"
}

500 Internal Server Error

{
  "error": "Failed to translate"
}
Common causes:
  • Claude API connectivity issues
  • API quota exceeded
  • Malformed draft HTML
  • Network timeout

Best Practices

  1. Clean Input: While HTML is stripped automatically, cleaner input produces better translations
  2. Context Preservation: The AI maintains professional tone, but very casual language may lose some nuance
  3. Review Translations: Have bilingual team members review important translations
  4. Batch Processing: If translating multiple drafts, consider rate limiting to avoid API throttling
  5. Caching: Cache translations for identical content to reduce API calls
  6. Error Handling: Implement fallback behavior if translation fails

Limitations

  • Target Language: Currently only supports translation to Korean
  • Plain Text Output: Translation returns plain text, not HTML-formatted content
  • No Context: The translation endpoint doesn’t receive thread context, only the draft itself
  • No Glossary: Custom terminology isn’t currently supported

Future Enhancements

Planned features:
  • Support for additional target languages
  • Custom terminology glossaries
  • Translation memory for consistency
  • Batch translation endpoint

Build docs developers (and LLMs) love