How to Integrate Bhashini Translation API in Node.js & Fix 401 Auth Errors (2026)

TL;DR: To integrate the Indian Government’s Bhashini ULCA Translation API in Node.js, first generate your userID and ulcaApiKey from the official Bhashini portal. Construct a POST request to https://meity-auth.ulcacontrib.org/ulca/apis/v0/model/getModelsPipeline to retrieve dynamic inference endpoints, then invoke the pipeline with valid ISO language codes (hi, ta, te, bn). Fix common HTTP 401/403 Forbidden errors by whitelisting your domain in the dashboard and passing the Bearer token in the Authorization header.

📋 Quick Navigation (Table of Contents)
  1. ⚡ Bhashini API Error Codes & Fast Fixes
  2. Step 1: Obtain Bhashini API Credentials
  3. Step 2: Initialize Node.js Project & Dependencies
  4. Step 3: Complete Node.js Translation Code
  5. ⚠️ Troubleshooting Common Bhashini Integration Bugs

The Bhashini Mission (Digital India) has revolutionized AI translation, voice recognition, and Indic OCR across 22 scheduled Indian languages. However, for backend developers building SaaS platforms, e-commerce apps, and civic tech solutions, integrating the Bhashini REST APIs in Node.js can be tricky due to multi-stage pipeline handshakes, strict rate limits, and authentication errors.

In this developer guide, we cover the exact Node.js implementation for Bhashini Text Translation, how to structure pipeline requests with Axios, and how to fix common production bugs.


⚡ Bhashini API Error Codes & Fast Fixes

HTTP CodeError MessageRoot CauseSolution
401Unauthorized: Invalid Auth TokenMissing or expired inference tokenQuery /getModelsPipeline first to obtain the temporary auth token
403Forbidden: Domain Not WhitelistedUnregistered origin headerAdd server IP or domain in Bhashini Developer Console
429Rate Limit ExceededSurpassed 100 req/min free quotaImplement exponential backoff or apply for enterprise tier
504Gateway TimeoutIndic translation model cold startSet client timeout to $\ge$ 15,000ms for large regional corpora

Step 1: Obtain Bhashini API Credentials

Before writing code, configure your developer account:

  1. Navigate to the Bhashini Developer Portal (bhashini.gov.in).
  2. Log in using MeriPehchan or official government SSO.
  3. Open My Profile > API Keys.
  4. Generate and save two critical secrets:

– BHASHINI_USER_ID: Unique alphanumeric developer ID.

– BHASHINI_API_KEY: 32-character master key.

– BHASHINI_PIPELINE_ID: Usually configured for translation (translation-pipeline-v1).

💡 Security Tip: Store your BHASHINI_API_KEY in environment variables (.env). Never commit keys to public GitHub repositories.


Step 2: Initialize Node.js Project & Dependencies

Create your backend project directory and install axios and dotenv:

“bash

mkdir bhashini-nodejs-app && cd bhashini-nodejs-app

npm init -y

npm install axios dotenv

`

Create a .env file in your root folder:

`env

BHASHINI_USER_ID="your_user_id_here"

BHASHINI_API_KEY="your_api_key_here"

BHASHINI_PIPELINE_ID="64392f96daac500b55c543d0"

`


Step 3: Complete Node.js Translation Code

Create translate.js with the following modular code:

`javascript

const axios = require('axios');

require('dotenv').config();

const AUTH_URL = 'https://meity-auth.ulcacontrib.org/ulca/apis/v0/model/getModelsPipeline';

async function translateText(sourceText, sourceLang = 'en', targetLang = 'hi') {

try {

// Step A: Fetch Dynamic Inference Endpoint and Compute Key

const pipelineConfig = {

pipelineTasks: [

{

taskType: 'translation',

config: {

language: {

sourceLanguage: sourceLang,

targetLanguage: targetLang

}

}

}

],

pipelineRequestConfig: {

pipelineId: process.env.BHASHINI_PIPELINE_ID

}

};

const configHeaders = {

'userID': process.env.BHASHINI_USER_ID,

'ulcaApiKey': process.env.BHASHINI_API_KEY,

'Content-Type': 'application/json'

};

const authResponse = await axios.post(AUTH_URL, pipelineConfig, { headers: configHeaders, timeout: 10000 });

const callbackUrl = authResponse.data.pipelineInferenceAPIEndPoint.callbackUrl;

const inferenceApiKeyName = authResponse.data.pipelineInferenceAPIEndPoint.inferenceApiKey.name;

const inferenceApiKeyValue = authResponse.data.pipelineInferenceAPIEndPoint.inferenceApiKey.value;

const serviceId = authResponse.data.pipelineResponseConfig[0].config[0].serviceId;

// Step B: Send Translation Inference Payload

const computePayload = {

pipelineTasks: [

{

taskType: 'translation',

config: {

language: {

sourceLanguage: sourceLang,

targetLanguage: targetLang

},

serviceId: serviceId

}

}

],

inputData: {

input: [

{

source: sourceText

}

]

}

};

const computeHeaders = {

[inferenceApiKeyName]: inferenceApiKeyValue,

'Content-Type': 'application/json'

};

const resultResponse = await axios.post(callbackUrl, computePayload, { headers: computeHeaders, timeout: 15000 });

const translatedOutput = resultResponse.data.pipelineResponse[0].output[0].target;

return translatedOutput;

} catch (error) {

console.error('Bhashini Translation Error:', error.response?.data || error.message);

throw error;

}

}

// Example Execution

(async () => {

const textToTranslate = "Welcome to Digital India. Technology empowers citizens everywhere.";

console.log("Translating text to Hindi...");

const hindiResult = await translateText(textToTranslate, 'en', 'hi');

console.log("Output (Hindi):", hindiResult);

})();

`


⚠️ Troubleshooting Common Bhashini Integration Bugs

1. Fixing 401 Unauthorized on Compute Endpoint

Many developers assume the master ulcaApiKey can be passed directly to the translation inference endpoint. This will fail. The compute endpoint requires the short-lived inferenceApiKey returned dynamically inside authResponse.data.pipelineInferenceAPIEndPoint. Always dynamically map the key header name and value as shown in the script above.

2. Handling Dialects & Unicode Formatting

When dealing with Indic scripts like Tamil, Telugu, and Bengali, string lengths in UTF-8 vary significantly. Ensure your database fields (e.g., PostgreSQL VARCHAR) use TEXT or NVARCHAR` collation to prevent truncation errors.


Frequently Asked Questions (FAQ)

Found this guide helpful?Share it with your friends or colleagues on WhatsApp to save them time.

📲 Share on WhatsApp

What languages are supported by the Bhashini API?

Bhashini currently supports all 22 scheduled Indian languages, including Hindi, Bengali, Tamil, Telugu, Marathi, Gujarati, Kannada, Malayalam, Odia, Punjabi, and Assamese, alongside English.

Is the Bhashini API free for commercial startups?

Yes. Bhashini provides a generous free tier of up to 10,000 monthly inference calls for verified Indian startups, educational developers, and researchers registered on India Stack.

How does Bhashini compare with Google Cloud Translate?

While Google Cloud Translate is mature for major global languages, Bhashini demonstrates superior accuracy in Indian administrative terminology, vernacular slang, legal terminology, and low-resource regional dialects.

Written by Rahul Dubey
Tech, Fintech & Digital Ecosystem Specialist at 99InfoStore, tracking personal finance regulations, consumer tech deals, and emerging software tools.

Leave a Reply