Google Translate API X
raw JSON → 10.7.2 verified Sat Apr 25 auth: no javascript
A free and unlimited API for Google Translate (v10.7.2) that uses the same servers as translate.google.com. Cross-platform (Node.js, browsers) via Fetch API, ships TypeScript types. Supports automatic language detection, spelling/language correction, batch translation (arrays/objects), and text-to-speech. Differentiators: supports both single and batch translate endpoints for reliability, provides a Translator class for option persistence, and includes over 100 languages. Actively maintained with weekly releases.
Common errors
error Response code 403 (Forbidden) ↓
cause Google Translate API blocking requests due to rate limiting or missing client parameter.
fix
Set { client: 'gtx' } in options: await translate('text', { to: 'en', client: 'gtx' })
error Cannot find module 'google-translate-api-x' ↓
cause Package not installed or incorrect import path.
fix
Run: npm install google-translate-api-x
error TypeError: translate is not a function ↓
cause Using default import as function with wrong syntax (e.g., require() style with default export).
fix
Use: import translate from 'google-translate-api-x' or const translate = require('google-translate-api-x').default
error Maximum call stack size exceeded ↓
cause Recursive or circular translations without base case.
fix
Avoid translating results of translate() repeatedly; ensure termination condition.
Warnings
gotcha Maximum text length for single translation is 5000 characters; longer text must be split into chunks. ↓
fix Split text into chunks of 5000 chars or less before translating.
gotcha Response code 403 (Forbidden) can occur; use client=gtx option to mitigate. ↓
fix Set { client: 'gtx' } in options when calling translate() or use Translator with client option.
deprecated The autoCorrect option may be deprecated or unreliable; reported values often inaccurate. ↓
fix Avoid relying on autoCorrect results; use with caution.
gotcha Batch endpoint may be less accurate than single endpoint; choose based on needs. ↓
fix Use singleTranslate for accuracy, batchTranslate for performance when accuracy is less critical.
Install
npm install google-translate-api-x yarn add google-translate-api-x pnpm add google-translate-api-x Imports
- translate wrong
const translate = require('google-translate-api-x')correctimport translate from 'google-translate-api-x' - Translator wrong
const { Translator } = require('google-translate-api-x')correctimport { Translator } from 'google-translate-api-x' - speak wrong
import speak from 'google-translate-api-x'correctimport { speak } from 'google-translate-api-x' - languages wrong
const languages = require('google-translate-api-x/languages')correctimport { languages } from 'google-translate-api-x'
Quickstart
import translate, { Translator, speak, languages, isSupported } from 'google-translate-api-x';
const single = await translate('Ik spreek Engels', { to: 'en' });
console.log(single.text); // 'I speak English'
const batch = await translate(['Hello', 'World'], { to: 'es' });
console.log(batch.map(r => r.text)); // ['Hola', 'Mundo']
const tts = await speak('Hello', { to: 'es' });
// tts is base64 MP3 string
const translator = new Translator({ to: 'fr', client: 'gtx' });
const res2 = await translator.translate('How are you?');
console.log(res2.text); // 'Comment allez-vous?'
console.log(isSupported('en')); // true
console.log(Object.keys(languages).length); // > 100