> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt.
> For full documentation content in one file, see https://docs.sarvam.ai/llms-full.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# Translation

POST https://api.sarvam.ai/translate
Content-Type: application/json

**Translation** converts text from one language to another while preserving its meaning.
For Example: **'मैं ऑफिस जा रहा हूँ'** translates to **'I am going to the office'** in English, where the script and language change, but the original meaning remains the same.

Available languages:
- **`bn-IN`**: Bengali
- **`en-IN`**: English
- **`gu-IN`**: Gujarati
- **`hi-IN`**: Hindi
- **`kn-IN`**: Kannada
- **`ml-IN`**: Malayalam
- **`mr-IN`**: Marathi
- **`od-IN`**: Odia
- **`pa-IN`**: Punjabi
- **`ta-IN`**: Tamil
- **`te-IN`**: Telugu

### Newly added languages:
- **`as-IN`**: Assamese
- **`brx-IN`**: Bodo
- **`doi-IN`**: Dogri
- **`kok-IN`**: Konkani
- **`ks-IN`**: Kashmiri
- **`mai-IN`**: Maithili
- **`mni-IN`**: Manipuri (Meiteilon)
- **`ne-IN`**: Nepali
- **`sa-IN`**: Sanskrit
- **`sat-IN`**: Santali
- **`sd-IN`**: Sindhi
- **`ur-IN`**: Urdu

For hands-on practice, you can explore the notebook tutorial on [Translate API Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/translate/Translate_API_Tutorial.ipynb).

Reference: https://docs.sarvam.ai/api-reference-docs/text/translate-text

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: ''
  version: 1.0.0
paths:
  /translate:
    post:
      operationId: translate
      summary: Translate Text
      description: >-
        **Translation** converts text from one language to another while
        preserving its meaning.

        For Example: **'मैं ऑफिस जा रहा हूँ'** translates to **'I am going to
        the office'** in English, where the script and language change, but the
        original meaning remains the same.


        Available languages:

        - **`bn-IN`**: Bengali

        - **`en-IN`**: English

        - **`gu-IN`**: Gujarati

        - **`hi-IN`**: Hindi

        - **`kn-IN`**: Kannada

        - **`ml-IN`**: Malayalam

        - **`mr-IN`**: Marathi

        - **`od-IN`**: Odia

        - **`pa-IN`**: Punjabi

        - **`ta-IN`**: Tamil

        - **`te-IN`**: Telugu


        ### Newly added languages:

        - **`as-IN`**: Assamese

        - **`brx-IN`**: Bodo

        - **`doi-IN`**: Dogri

        - **`kok-IN`**: Konkani

        - **`ks-IN`**: Kashmiri

        - **`mai-IN`**: Maithili

        - **`mni-IN`**: Manipuri (Meiteilon)

        - **`ne-IN`**: Nepali

        - **`sa-IN`**: Sanskrit

        - **`sat-IN`**: Santali

        - **`sd-IN`**: Sindhi

        - **`ur-IN`**: Urdu


        For hands-on practice, you can explore the notebook tutorial on
        [Translate API
        Tutorial](https://github.com/sarvamai/sarvam-ai-cookbook/blob/main/notebooks/translate/Translate_API_Tutorial.ipynb).
      tags:
        - subpackage_text
      parameters:
        - name: api-subscription-key
          in: header
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_TranslationResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_ErrorMessage'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_ErrorMessage'
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_ErrorMessage'
        '429':
          description: Quota Exceeded
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_ErrorMessage'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Sarvam_Model_API_ErrorMessage'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/Sarvam_Model_API_TranslationRequest'
servers:
  - url: https://api.sarvam.ai
    description: Production
components:
  schemas:
    Sarvam_Model_API_TranslateSourceLanguage:
      type: string
      enum:
        - auto
        - bn-IN
        - en-IN
        - gu-IN
        - hi-IN
        - kn-IN
        - ml-IN
        - mr-IN
        - od-IN
        - pa-IN
        - ta-IN
        - te-IN
        - as-IN
        - brx-IN
        - doi-IN
        - kok-IN
        - ks-IN
        - mai-IN
        - mni-IN
        - ne-IN
        - sa-IN
        - sat-IN
        - sd-IN
        - ur-IN
      title: Sarvam_Model_API_TranslateSourceLanguage
    Sarvam_Model_API_TranslateTargetLanguage:
      type: string
      enum:
        - bn-IN
        - en-IN
        - gu-IN
        - hi-IN
        - kn-IN
        - ml-IN
        - mr-IN
        - od-IN
        - pa-IN
        - ta-IN
        - te-IN
        - as-IN
        - brx-IN
        - doi-IN
        - kok-IN
        - ks-IN
        - mai-IN
        - mni-IN
        - ne-IN
        - sa-IN
        - sat-IN
        - sd-IN
        - ur-IN
      title: Sarvam_Model_API_TranslateTargetLanguage
    Sarvam_Model_API_TranslateSpeakerGender:
      type: string
      enum:
        - Male
        - Female
      title: Sarvam_Model_API_TranslateSpeakerGender
    Sarvam_Model_API_TranslateMode:
      type: string
      enum:
        - formal
        - modern-colloquial
        - classic-colloquial
        - code-mixed
      title: Sarvam_Model_API_TranslateMode
    Sarvam_Model_API_TranslateModel:
      type: string
      enum:
        - mayura:v1
        - sarvam-translate:v1
      title: Sarvam_Model_API_TranslateModel
    Sarvam_Model_API_TransliterateMode:
      type: string
      enum:
        - roman
        - fully-native
        - spoken-form-in-native
      title: Sarvam_Model_API_TransliterateMode
    Sarvam_Model_API_NumeralsFormat:
      type: string
      enum:
        - international
        - native
      title: Sarvam_Model_API_NumeralsFormat
    Sarvam_Model_API_TranslationRequest:
      type: object
      properties:
        input:
          type: string
          description: >-
            The text you want to translate is the input text that will be
            processed by the translation model. The maximum is 1000 characters
            for Mayura:v1 and 2000 characters for Sarvam-Translate:v1.
        source_language_code:
          $ref: '#/components/schemas/Sarvam_Model_API_TranslateSourceLanguage'
          description: >+
            Source language code for translation input.


            **mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada,
            Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu


            **sarvam-translate:v1 Languages:** All mayura:v1 languages and
            Assamese, Bodo, Dogri, Konkani, Kashmiri, Maithili, Manipuri,
            Nepali, Sanskrit, Santali, Sindhi, Urdu


            **Note:** mayura:v1 supports automatic language detection using
            'auto' as the source language code.

        target_language_code:
          $ref: '#/components/schemas/Sarvam_Model_API_TranslateTargetLanguage'
          description: >+
            The language code of the translated text. This specifies the target
            language for translation.


            **mayura:v1 Languages:** Bengali, English, Gujarati, Hindi, Kannada,
            Malayalam, Marathi, Odia, Punjabi, Tamil, Telugu


            **sarvam-translate:v1 Languages:** All mayura:v1 and Assamese, Bodo,
            Dogri, Konkani, Kashmiri, Maithili, Manipuri, Nepali, Sanskrit,
            Santali, Sindhi, Urdu

        speaker_gender:
          $ref: '#/components/schemas/Sarvam_Model_API_TranslateSpeakerGender'
          description: Please specify the gender of the speaker for better translations.
        mode:
          $ref: '#/components/schemas/Sarvam_Model_API_TranslateMode'
          description: >-
            Specifies the tone or style of the translation.


            **Model Support:**

            - **mayura:v1**: Supports formal, classic-colloquial, and
            modern-colloquial modes

            - **sarvam-translate:v1**: Only formal mode is supported


            **Default:** formal
        model:
          $ref: '#/components/schemas/Sarvam_Model_API_TranslateModel'
          description: >-
            Specifies the translation model to use.

            - mayura:v1: Supports 12 languages with all modes, output scripts,
            and automatic language detection.

            - sarvam-translate:v1: Supports all 22 scheduled languages of India,
            formal mode only.
        output_script:
          oneOf:
            - $ref: '#/components/schemas/Sarvam_Model_API_TransliterateMode'
            - type: 'null'
          description: >-
            **output_script**: This is an optional parameter which controls the
            transliteration style applied to the output text.


            **Transliteration**: Converting text from one script to another
            while preserving pronunciation.


            For mayura:v1 - We support transliteration with four options:

            - **`null`**(default): No transliteration applied.

            - **`roman`**: Transliteration in Romanized script.

            - **`fully-native`**: Transliteration in the native script with
            formal style.

            - **`spoken-form-in-native`**: Transliteration in the native script
            with spoken style.


            For sarvam-translate:v1 - Transliteration is not supported.

            ### Example:

            English: Your EMI of Rs. 3000 is pending.

            Default modern translation: आपका Rs. 3000 का EMI pending है (when
            `null` is passed).


            With postprocessing enabled:

            - **roman output**: aapka Rs. 3000 ka EMI pending hai.
        numerals_format:
          $ref: '#/components/schemas/Sarvam_Model_API_NumeralsFormat'
          description: >-
            `numerals_format` is an optional parameter with two options
            (supported for both mayura:v1 and sarvam-translate:v1):


            - **`international`** (default): Uses regular numerals (0-9).

            - **`native`**: Uses language-specific native numerals.


            ### Example:

            - If `international` format is selected, we use regular numerals
            (0-9). For example: `मेरा phone number है: 9840950950`.

            - If `native` format is selected, we use language-specific native
            numerals, like: `मेरा phone number है: ९८४०९५०९५०`.
      required:
        - input
        - source_language_code
        - target_language_code
      title: Sarvam_Model_API_TranslationRequest
    Sarvam_Model_API_TranslationResponse:
      type: object
      properties:
        request_id:
          type:
            - string
            - 'null'
        translated_text:
          type: string
          description: Translated text result in the requested target language.
        source_language_code:
          type: string
          description: Detected or provided source language of the input text.
      required:
        - request_id
        - translated_text
        - source_language_code
      title: Sarvam_Model_API_TranslationResponse
    Sarvam_Model_API_ErrorCode:
      type: string
      enum:
        - invalid_request_error
        - internal_server_error
        - unprocessable_entity_error
        - insufficient_quota_error
        - invalid_api_key_error
        - authentication_error
        - not_found_error
        - rate_limit_exceeded_error
      title: Sarvam_Model_API_ErrorCode
    Sarvam_Model_API_ErrorDetails:
      type: object
      properties:
        request_id:
          type:
            - string
            - 'null'
        message:
          type: string
          description: Message describing the error
        code:
          $ref: '#/components/schemas/Sarvam_Model_API_ErrorCode'
          description: >-
            Error code for the specific error that has occurred. Refer to the
            error code documentation for more details.
      required:
        - request_id
        - message
        - code
      title: Sarvam_Model_API_ErrorDetails
    Sarvam_Model_API_ErrorMessage:
      type: object
      properties:
        error:
          $ref: '#/components/schemas/Sarvam_Model_API_ErrorDetails'
          description: Error details
      required:
        - error
      title: Sarvam_Model_API_ErrorMessage
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: api-subscription-key

```

## Examples



**Request**

```json
{
  "input": "Hello, how are you?",
  "source_language_code": "auto",
  "target_language_code": "bn-IN"
}
```

**Response**

```json
{
  "request_id": "a1b2c3d4-e5f6-7890-ab12-cd34ef567890",
  "translated_text": "হ্যালো, আপনি কেমন আছেন?",
  "source_language_code": "en-IN"
}
```

**SDK Code**

```typescript
import { SarvamAIClient } from "sarvamai";

const client = new SarvamAIClient({
  apiSubscriptionKey: process.env.SARVAM_API_KEY,
});

const response = await client.text.translate({
  input: "Hello, how are you?",
  source_language_code: "auto",
  target_language_code: "hi-IN",
  speaker_gender: "Male",
});

```

```typescript
import { SarvamAIClient } from "sarvamai";

async function main() {
    const client = new SarvamAIClient({
        apiSubscriptionKey: "YOUR_API_KEY_HERE",
    });
    await client.text.translate({
        input: "Hello, how are you?",
        source_language_code: "auto",
        target_language_code: "bn-IN",
    });
}
main();

```

```python
from sarvamai import SarvamAI

client = SarvamAI(
    api_subscription_key="YOUR_API_KEY_HERE",
)

client.text.translate(
    input="Hello, how are you?",
    source_language_code="auto",
    target_language_code="bn-IN",
)

```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.sarvam.ai/translate"

	payload := strings.NewReader("{\n  \"input\": \"Hello, how are you?\",\n  \"source_language_code\": \"auto\",\n  \"target_language_code\": \"bn-IN\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("api-subscription-key", "<apiSubscriptionKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.sarvam.ai/translate")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["api-subscription-key"] = '<apiSubscriptionKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"input\": \"Hello, how are you?\",\n  \"source_language_code\": \"auto\",\n  \"target_language_code\": \"bn-IN\"\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.sarvam.ai/translate")
  .header("api-subscription-key", "<apiSubscriptionKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"input\": \"Hello, how are you?\",\n  \"source_language_code\": \"auto\",\n  \"target_language_code\": \"bn-IN\"\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.sarvam.ai/translate', [
  'body' => '{
  "input": "Hello, how are you?",
  "source_language_code": "auto",
  "target_language_code": "bn-IN"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'api-subscription-key' => '<apiSubscriptionKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.sarvam.ai/translate");
var request = new RestRequest(Method.POST);
request.AddHeader("api-subscription-key", "<apiSubscriptionKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"input\": \"Hello, how are you?\",\n  \"source_language_code\": \"auto\",\n  \"target_language_code\": \"bn-IN\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "api-subscription-key": "<apiSubscriptionKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "input": "Hello, how are you?",
  "source_language_code": "auto",
  "target_language_code": "bn-IN"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.sarvam.ai/translate")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```