Claude API Email Reply Generator Tutorial
What you're building
An email reply generator takes an incoming message and produces a draft response that matches a tone, length, and intent you specify. This guide walks through designing the prompt, calling the Claude API to generate replies, and handling variants (short vs. detailed, formal vs. casual) so you can drop this into a support inbox, CRM, or personal email client.
If you just want working code, skip to the "Building the generator" section below. If you're deciding whether to build this at all, the short answer is: yes, it's a good fit for Claude because email reply generation is mostly about following instructions precisely (tone, length, what to acknowledge, what to avoid) and Claude handles instruction-following and nuance better than template-based approaches.
Why Claude works well for this
Email replies aren't just text completion — they need to:
- Acknowledge the specific content of the incoming email
- Match a requested tone (apologetic, neutral, enthusiastic, firm)
- Stay within a length constraint
- Avoid committing to things the sender hasn't authorized (pricing, refunds, dates)
Claude handles all four reliably when you put them in the system prompt rather than burying them in the user message. The system prompt is where you define the "rules of the reply," and the user message is where you pass the actual incoming email plus any reply parameters.
Designing the prompt
Separate three things clearly:
- System prompt — persona, tone rules, constraints, output format
- Context — the incoming email text
- Parameters — tone override, length target, specific points to include/exclude
Example system prompt:
You are an email reply assistant. Given an incoming email and reply
parameters, write a reply that:
- Directly addresses the sender's main question or request
- Matches the requested tone exactly
- Stays within the requested length
- Never invents commitments, dates, prices, or policies not stated
in the input
- Signs off with the sender's name if provided, otherwise "Best,"
Output only the reply body. No subject line, no explanation.
This keeps the model from padding the reply with meta-commentary like "Here's a draft reply:" which you'd otherwise have to strip out downstream.
Building the generator
Here's a generic request structure using the Claude API. Replace the endpoint and headers with whatever provider you're using — the message shape is what matters.
curl https://api.example.com/v1/messages \
-H "content-type: application/json" \
-H "authorization: Bearer YOUR_API_KEY" \
-d '{
"model": "claude-opus-4-1",
"max_tokens": 400,
"system": "You are an email reply assistant. Write a reply that matches the requested tone and length. Output only the reply body.",
"messages": [
{
"role": "user",
"content": "Incoming email:\n\n\"Hi, I ordered item #4521 three weeks ago and it still hasn't arrived. Can you tell me what's going on?\"\n\nReply tone: apologetic but professional\nReply length: short (under 80 words)\nSender name: Maria"
}
]
}'
A JavaScript version you can drop into a server function:
async function generateReply({ incomingEmail, tone, length, senderName }) {
const res = await fetch("https://api.example.com/v1/messages", {
method: "POST",
headers: {
"content-type": "application/json",
"authorization": `Bearer ${process.env.API_KEY}`,
},
body: JSON.stringify({
model: "claude-opus-4-1",
max_tokens: 400,
system:
"You are an email reply assistant. Write a reply that matches the requested tone and length. Output only the reply body.",
messages: [
{
role: "user",
content: `Incoming email:\n\n"${incomingEmail}"\n\nReply tone: ${tone}\nReply length: ${length}\nSender name: ${senderName}`,
},
],
}),
});
const data = await res.json();
return data.content[0].text;
}
If you'd rather skip provisioning direct model access and billing setup, SubToAPI turns your existing Claude access into an HTTPS API with application keys, so you can make the same call against https://api.subtoapi.app/v1/messages using a sub_live_... key instead of managing provider credentials directly. See the quickstart and messages endpoint docs for the exact request shape.
Adding tone and length controls
Rather than hardcoding tone strings, expose a small set of presets in your UI and map them to explicit instructions in the prompt. Vague tone words like "friendly" produce inconsistent results across calls — be specific:
apologetic→ "Acknowledge the inconvenience directly in the first sentence."firm→ "Be polite but do not over-apologize. State the next step clearly."enthusiastic→ "Use an upbeat opening line and end with a clear call to action."
For length, give a word or sentence budget rather than "short" or "long" — Claude follows numeric constraints more consistently than relative ones.
Handling multiple draft variants
A common UX pattern is generating two or three reply options so the user can pick one. Do this with a single request rather than three separate calls — ask Claude to return a structured list:
Generate 3 reply variants with different tones (formal, casual, brief).
Return as a JSON array: [{"tone": "...", "reply": "..."}]
This cuts latency and cost versus firing three independent requests, and keeps the variants consistent in context (they're all responding to the same email in one pass).
Streaming for a better draft experience
If your interface shows the reply being written in real time rather than waiting for the full response, use streaming instead of a blocking call. SubToAPI supports streaming responses over the same endpoint — details are in the streaming docs. This matters most when replies run long (support escalations, detailed technical answers) since users perceive streamed text as faster even when total generation time is similar.
Production considerations
- Never auto-send without review for anything customer-facing until you've validated output quality on real traffic for a few weeks.
- Log the incoming email and generated reply together so you can audit tone drift or factual errors.
- Rate limit per user, not just globally, so one heavy user doesn't exhaust your quota.
- Strip PII before logging if your emails contain customer data you don't need to retain.
If you're building this as part of a small internal tool, a Solo plan on pricing covers the API usage without needing to set up billing directly with a model provider — useful if you're prototyping before deciding on scale.
FAQ
Does Claude need fine-tuning to write good email replies? No. Clear system prompt instructions covering tone, length, and constraints produce consistent results without fine-tuning. Fine-tuning only helps once you have thousands of labeled examples of your specific reply style.
How do I stop Claude from inventing details like refund amounts or dates? Add an explicit instruction in the system prompt: "Never invent commitments, dates, prices, or policies not stated in the input." Pair this with a short review step before sending anything customer-facing.
Can I generate replies in a specific brand voice? Yes — include 2-3 example replies written in your brand voice directly in the system prompt as style references. This works better than describing the voice abstractly ("professional but warm") because Claude can pattern-match against concrete examples.