intermediate12 min read· Module 5, Lesson 3
✍️Text Generation Mastery
Summaries, content, code, translations, and data extraction
Text Generation with Claude
Claude is one of the best text generators available. Here's how to use it for common tasks.
Summarization
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 500,
messages: [{
role: "user",
content: `Summarize this article in 3 bullet points:
[paste your article text here]`
}]
});Code Generation
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 2000,
system: "You are an expert programmer. Write clean, well-commented code.",
messages: [{
role: "user",
content: "Write a TypeScript function that validates email addresses using regex"
}]
});Data Extraction
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1000,
messages: [{
role: "user",
content: `Extract the following from this email:
- Sender name
- Company
- Topic
- Action items
Email: "Hi, I'm Sarah from Acme Corp. We need to discuss the Q4 budget.
Please review the attached spreadsheet and schedule a meeting by Friday."`
}]
});Translation
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 1000,
messages: [{
role: "user",
content: `Translate to French:
"The quick brown fox jumps over the lazy dog."`
}]
});Content Generation
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 2000,
system: "You are a skilled content writer who creates engaging, SEO-friendly content.",
messages: [{
role: "user",
content: `Write a blog post about "5 Tips for Learning Programming".
Tone: Friendly and encouraging
Length: About 500 words
Include: practical examples for each tip`
}]
});Text Capabilities Quick Reference
| Task | System Prompt Hint | Temperature |
|---|---|---|
| Summarization | "Be concise and accurate" | 0.3 |
| Code generation | "Write clean, production code" | 0 |
| Creative writing | "Be creative and engaging" | 0.8 |
| Data extraction | "Extract exactly what's asked" | 0 |
| Translation | "Translate naturally, not literally" | 0.3 |
| Q&A | "Be helpful and accurate" | 0.5 |
Next up: Advanced features — vision, extended thinking, tools, and structured outputs.