← Blog

Claude API Translation App Integration Guide

2026-11-09 · 5 min read · SubToAPI Team

Can you build a translation app with the Claude API?

Yes. Claude handles translation well because it understands context, idiom, tone, and formatting rather than just swapping words dictionary-style. If you're building a translation feature — a chat widget, a document translator, a subtitle tool, a customer support reply assistant — the Claude API gives you a single endpoint you can call with source text and a target language instruction, and get back a translation that reads like it was written by a native speaker, not a machine.

This guide walks through the practical integration steps: how to structure prompts for translation, how to handle streaming for long documents, how to preserve formatting (HTML, Markdown, placeholders), and how to detect source language automatically. We'll use SubToAPI (https://subtoapi.app) as the API layer in the examples, since it exposes Claude through a standard HTTPS endpoint with an application API key, but the prompt patterns apply to any Claude-compatible integration.

Designing the translation prompt

Translation quality depends almost entirely on how specific your system prompt is. A vague "translate this to French" works, but it leaves tone, formality, and formatting decisions to chance. Be explicit:

{
  "model": "claude-sonnet-4",
  "system": "You are a professional translator. Translate the user's text into Brazilian Portuguese. Preserve the original tone and formality. Do not add explanations, notes, or quotation marks — return only the translated text. Keep any HTML tags, markdown syntax, or placeholders like {{name}} exactly as they appear in the source.",
  "messages": [
    { "role": "user", "content": "Hi {{name}}, your order #4521 has shipped and will arrive by <b>Friday</b>." }
  ]
}

That system prompt does three jobs at once: sets the target language, constrains the output format, and protects dynamic content (placeholders, HTML) that your app needs to stay intact. Skipping that third instruction is the most common bug in translation integrations — Claude will otherwise "helpfully" translate the text inside your variables or rewrite your tags.

Handling multiple target languages in one call

If your app needs the same string in five languages (common for localization pipelines), don't make five separate round trips unless you need them streamed independently. Ask for structured JSON output instead:

{
  "model": "claude-sonnet-4",
  "system": "Translate the given text into the requested languages. Return only valid JSON with language codes as keys and translations as values. No extra commentary.",
  "messages": [
    { "role": "user", "content": "Text: 'Your subscription renews tomorrow.'\nLanguages: es, fr, de, ja, pt-BR" }
  ]
}

This cuts latency and cost compared to five sequential calls, and it's easier to parse into your localization keys programmatically.

Auto-detecting source language

Most translation apps don't ask users to specify the source language — they detect it. Claude can do this in the same call as the translation, which saves a round trip:

{
  "system": "Detect the language of the input text, then translate it into English. Respond with JSON: {\"detected_language\": \"<ISO 639-1 code>\", \"translation\": \"<text>\"}",
  "messages": [
    { "role": "user", "content": "Grazie mille per il tuo aiuto!" }
  ]
}

This is more reliable than running a separate lightweight language-detection library, especially for mixed-language input or short, ambiguous strings where rule-based detectors often fail.

Integrating with SubToAPI

If you're already using Claude through SubToAPI, the translation call looks the same as any other message request — you don't need a separate translation-specific endpoint:

curl https://api.subtoapi.app/v1/messages \
  -H "Authorization: Bearer $SUBTOAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4",
    "system": "Translate into German. Preserve markdown formatting exactly. Return only the translation.",
    "messages": [
      { "role": "user", "content": "## Welcome back!\n\nWe missed you. Here is **20% off** your next order." }
    ]
  }'

SubToAPI gives you a sub_live_... key per application, which matters if your translation feature ships inside a product with multiple environments (staging, production, a customer-facing widget) — you can issue separate keys per surface and see usage broken out per key in the dashboard, rather than sharing one raw Anthropic key across everything. See /docs/quickstart for setup and /docs/messages for the full request schema.

Streaming for long documents

Translating a full document — a contract, a help article, a changelog — in one blocking request means your UI sits idle until the whole thing is done. For anything beyond a paragraph, stream the response so you can render translated text as it arrives:

const response = await fetch("https://api.subtoapi.app/v1/messages", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.SUBTOAPI_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "claude-sonnet-4",
    system: "Translate the document into Spanish. Preserve markdown headings and lists exactly.",
    messages: [{ role: "user", content: documentText }],
    stream: true
  })
});

Full chunk-handling details are covered in /docs/streaming. For a translation UI specifically, the practical win is perceived speed — users see the translated paragraph fill in live instead of staring at a spinner for ten seconds on a long document.

Preserving formatting and placeholders

Three things consistently break naive translation integrations:

Choosing a model and plan

For short UI strings and chat replies, a faster model is usually enough and keeps latency low. For legal, medical, or marketing copy where nuance matters, use a stronger model and consider a review step. If your app serves translation at scale across a team — support agents, content editors, multiple products — SubToAPI's Team (€19/seat) or Scale (€49/seat) plans add seat-based access and shared usage visibility; Solo (€9) covers a single-developer integration. Check /pricing for current details, and start with a free trial at /signup before committing.

Questions

Does Claude support translation between any two languages? Claude handles translation well for widely spoken languages and performs reasonably on many less common ones, but quality varies — test your specific language pair and domain (legal, casual, technical) before shipping.

How do I stop Claude from translating variable placeholders like {{name}}? Name the placeholder pattern explicitly in your system prompt and instruct Claude to leave it unchanged. Omitting this instruction is the most common cause of broken localization strings.

Is streaming necessary for a translation app? Not for short strings, but for documents, articles, or chat transcripts, streaming noticeably improves perceived speed since users see translated text appear incrementally instead of waiting for the full response.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →