Text-to-Text quickstart

Overview

Learn how to translate text between Indic languages using the BHASHINI Inference API.

Getting started

  1. Get an inference API key – Create one in the dashboard
  2. Choose a translation service ID – e.g., ai4bharat/indictrans-v2-all-gpu--t4
  3. Send a request – Use the pipeline endpoint with your service ID and language pair
  4. Parse the response – Extract translated text from the JSON response

Key concepts

  • Source language: Language of the input text (e.g., hi for Hindi)
  • Target language: Desired output language (e.g., gu for Gujarati)
  • Service ID: Identifier for the translation model pipeline
  • Pipeline tasks: Array of tasks to execute (here: translation)

Interactive playground

Try Translation
hi → gu by default; update service ID and languages
Request
Add an inference API key to run.
curl
curl --location 'https://dhruva-api.bhashini.gov.in/services/inference/pipeline' \
--header 'Accept: */*' \
--header 'Authorization: YOUR_INFERENCE_API_KEY' \
--header 'Content-Type: application/json' \
--data '{
"pipelineTasks": [
{
"taskType": "translation",
"config": {
"serviceId": "",
"language": {
"sourceLanguage": "hi",
"targetLanguage": "gu"
}
}
}
],
"inputData": {
"input": [
{
"source": "<text>"
}
]
}
}'
Response
Send a request to see the live response here.

Code examples

const url = 'https://dhruva-api.bhashini.gov.in/services/inference/pipeline';
const headers = {
  'Accept': '*/*',
  'Authorization': '<YOUR_INFERENCE_API_KEY>',
  'Content-Type': 'application/json'
};
const payload = {
  pipelineTasks: [
    {
      taskType: 'translation',
      config: {
        language: {
          sourceLanguage: 'hi',
          targetLanguage: 'gu'
        },
        serviceId: 'ai4bharat/indictrans-v2-all-gpu--t4'
      }
    }
  ],
  inputData: {
    input: [
      { source: 'नमस्ते दुनिया' }
    ]
  }
};


fetch(url, {
  method: 'POST',
  headers: headers,
  body: JSON.stringify(payload)
})
  .then(res => res.json())
  .then(data => console.log(data))
  .catch(err => console.error(err));