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
userIDandulcaApiKeyfrom the official Bhashini portal. Construct a POST request tohttps://meity-auth.ulcacontrib.org/ulca/apis/v0/model/getModelsPipelineto retrieve dynamic inference endpoints, then invoke the pipeline with valid ISO language codes (hi,ta,te,bn). Fix commonHTTP 401/403 Forbiddenerrors by whitelisting your domain in the dashboard and passing the Bearer token in theAuthorizationheader.
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 Code | Error Message | Root Cause | Solution |
|---|---|---|---|
| 401 | Unauthorized: Invalid Auth Token | Missing or expired inference token | Query /getModelsPipeline first to obtain the temporary auth token |
| 403 | Forbidden: Domain Not Whitelisted | Unregistered origin header | Add server IP or domain in Bhashini Developer Console |
| 429 | Rate Limit Exceeded | Surpassed 100 req/min free quota | Implement exponential backoff or apply for enterprise tier |
| 504 | Gateway Timeout | Indic translation model cold start | Set client timeout to $\ge$ 15,000ms for large regional corpora |
Step 1: Obtain Bhashini API Credentials
Before writing code, configure your developer account:
- Navigate to the Bhashini Developer Portal (
bhashini.gov.in). - Log in using MeriPehchan or official government SSO.
- Open My Profile > API Keys.
- 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_KEYin 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)
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.






