About translate
A skill for using the Sarvam AI SDK to translate text in Python or JavaScript/TypeScript. It documents model capabilities, language and character limits, and API usage details that distinguish the two translation models.
Key features
- 01Python and JavaScript/TypeScript SDK examples
- 02Two translation model options
- 03Model-specific translation controls
- 04Language detection with mayura:v1
- 05API authentication and endpoint guidance
- 06Character-limit guidance
Use cases
- 01Translate text through the Sarvam AI SDK
- 02Choose a model for language and script options
- 03Handle long text within model limits
MCP support
The skill covers SDK-based translation, not MCP integration. The README points to sarvam-mcp for in-chat translation and localization.
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ sarvamai/ skills --skill translateAfter installing, type/translatein Claude Code to confirm it loaded.
Details
From the project READMETranslation — Sarvam AI
Live in-chat translate/localize → sarvam-mcp (
sarvam_tools_translate/_localize). This skill = SDK code.
Important
Auth:
api-subscription-keyheader — NOTAuthorization: Bearer. Base URL:https://api.sarvam.ai(NOT/v1— that prefix is only for the OpenAI-compatible chat endpoint)
Models
| Model | Max Input | Languages | Features |
|---|---|---|---|
sarvam-translate:v1 | 2,000 chars | 23 (22 Indian + English) | mode (formal only), speaker_gender, numerals_format |
mayura:v1 | 1,000 chars | 11 (10 Indian + English) | All mode values, output_script, speaker_gender, numerals_format, auto source detection |
Quick Start (Python)
from sarvamai import SarvamAI
client = SarvamAI()
response = client.text.translate(
input="Hello, how are you?",
source_language_code="en-IN",
target_language_code="hi-IN",
model="sarvam-translate:v1"
)
print(response.translated_text)
Quick Start (JavaScript/TypeScript)
import { SarvamAIClient } from "sarvamai";
const client = new SarvamAIClient({ apiSubscriptionKey: "YOUR_SARVAM_API_KEY" });
const response = await client.text.translate({
input: "Hello, how are you?",
source_language_code: "en-IN",
target_language_code: "hi-IN",
model: "sarvam-translate:v1"
});
console.log(response.translated_text);
Gotchas
| Gotcha | Detail |
|---|---|
| Method name | Both Python & JS: client.text.translate({...}) — NOT client.translate.translate(). Same text namespace in both SDKs. |
output_script on sarvam-translate | NOT supported — only works with mayura:v1 (roman, fully-native, spoken-form-in-native). Silently ignored on sarvam-translate:v1. |
mode values | sarvam-translate:v1 supports formal only. Colloquial modes (modern-colloquial, classic-colloquial, code-mixed) are mayura:v1 only. speaker_gender works on BOTH models. |
| Auto language detection | source_language_code="auto" only works with mayura:v1. sarvam-translate:v1 requires an explicit source language. |
| Odia language code | od-IN — NOT or-IN. |
| Character limits | Exceeding returns 422. Split long text at sentence boundaries. |
Full Docs
Fetch language codes, mode examples, script options, and numeral formats from:
- https://docs.sarvam.ai/llms.txt — comprehensive docs index
- Translation Guide
- Rate Limits