{"id":12888,"library":"bing-translate-api","title":"Bing & Microsoft Translator API for Node.js","description":"bing-translate-api is a Node.js library providing a simple, free, and unofficial API client for both Bing Translator and Microsoft Translator services. It aims to offer programmatic access to translation capabilities without requiring an Azure subscription for basic usage. The current stable version is 4.2.0, with regular updates addressing bug fixes, adding new features, and enhancing stability, particularly through the introduction of new translation modes. Key differentiators include support for multiple translation modes (legacy, EPT since v3.0.0, and MET since v4.0.0), automatic retry logic, and options for gender-debiased translations. It is actively maintained with several minor and patch releases in the past year, indicating a steady release cadence and ongoing development.","status":"active","version":"4.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/plainheart/bing-translate-api","tags":["javascript","bing","microsoft","translator","api","free","node","translate","typescript"],"install":[{"cmd":"npm install bing-translate-api","lang":"bash","label":"npm"},{"cmd":"yarn add bing-translate-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add bing-translate-api","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While CommonJS `require` still works, ESM `import` is the preferred modern syntax, especially given the TypeScript types included.","wrong":"const { translate } = require('bing-translate-api');","symbol":"translate","correct":"import { translate } from 'bing-translate-api';"},{"note":"Since v4.0.0, the more stable Microsoft Translator (MET) mode is available via a separate import path. Ensure you import from `bing-translate-api/met` to use this mode.","wrong":"import { translate } from 'bing-translate-api'; // This is for Bing Translator (legacy/EPT mode)","symbol":"translate (MET Mode)","correct":"import { translate } from 'bing-translate-api/met'; // For Microsoft Translator mode\nimport { MET } from 'bing-translate-api/met'; // Or use the MET constant"},{"note":"For TypeScript users, import the `TranslateResult` type to ensure type safety when handling translation responses. The structure includes `translation`, `language`, and optionally `feminineTranslation`/`masculineTranslation`.","symbol":"TranslateResult","correct":"import type { TranslateResult } from 'bing-translate-api';"}],"quickstart":{"code":"import { translate } from 'bing-translate-api';\n\nasync function performTranslation() {\n  try {\n    // Translate 'Hello world' from English to Spanish\n    const resultEnToEs = await translate('Hello world', 'en', 'es');\n    console.log('English to Spanish:', resultEnToEs.translation);\n\n    // Translate '你好' (Ni hao) from auto-detected Chinese to English\n    const resultZhToEn = await translate('你好', null, 'en');\n    console.log('Chinese to English:', resultZhToEn.translation);\n\n    // Translate with correction enabled (limited to 50 characters for correction)\n    const resultCorrect = await translate('helo there', 'en', 'fr', true);\n    console.log('Corrected and translated:', resultCorrect.translation);\n\n    // Example of using the MET mode (Microsoft Translator) for potentially better stability\n    // import { translate as translateMet } from 'bing-translate-api/met';\n    // const resultMet = await translateMet('Hello from MET mode', 'en', 'de');\n    // console.log('MET mode translation:', resultMet.translation);\n\n  } catch (err) {\n    console.error('Translation error:', err);\n  }\n}\n\nperformTranslation();","lang":"typescript","description":"Demonstrates basic text translation using `translate` with auto-detection, explicit language codes, and optional text correction. Includes comments for using the MET mode."},"warnings":[{"fix":"For new projects or enhanced stability, switch to `import { translate } from 'bing-translate-api/met';` instead of the default `bing-translate-api` import for Microsoft Translator mode.","message":"Version 4.0.0 introduced a new, more stable Microsoft Translator (MET) mode. While the original Bing Translator mode is still accessible, developers are encouraged to migrate to MET mode for better reliability. The MET mode has a distinct import path (`bing-translate-api/met`).","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Review existing code for `cookie` usage (which is no longer passed). Be aware of the `maxTextLen` changes, especially for EPT mode which has a 3000 character limit, and ensure language support aligns with the `eptLangs` list to avoid falling back to legacy mode and potential 429 errors.","message":"Version 3.0.0 introduced an experimental EPT mode and removed `cookie` from HTTP requests, which previously might have been used for maintaining session state. This version also changed the default `maxTextLen` for translation.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always validate input text length before sending to the API. If consistently dealing with longer texts, consider breaking them into smaller chunks or implementing custom logic to handle the varying limits per mode.","message":"Text length limits vary significantly based on the translation mode and geographical region. The default is 1000 characters, but can be up to 5000 in China, and is specifically 3000 characters in EPT mode.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Consult `src/lang.json` and `src/config.json#eptLangs` for supported languages in EPT mode. For correction, ensure text is under 50 characters and in a supported language. Implement error handling to gracefully manage fallback scenarios or unsupported language attempts.","message":"The EPT mode (introduced in v3.0.0) and the correction service (since v1.1.0) have specific language support limitations. Using unsupported languages in EPT mode will cause a fallback to the legacy mode, which is more prone to rate limiting (429 errors). The correction service is limited to 50 characters and a specific list of languages.","severity":"gotcha","affected_versions":">=3.0.0 (EPT), >=1.1.0 (Correction)"},{"fix":"Dynamically determine or explicitly check the `maxTextLen` based on the chosen translation mode (legacy, EPT, MET) and target region to avoid exceeding limits.","message":"The `maxTextLen` was updated from 1000 to 5000 in v2.10.0, but then adjusted again for EPT mode in v3.0.0 to 3000, and the default reverted to 1000 for non-China usage. Relying on a fixed large `maxTextLen` across all modes and regions can lead to issues.","severity":"deprecated","affected_versions":">=2.10.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Implement exponential backoff and retry logic. Consider switching to the more stable Microsoft Translator (MET) mode (`bing-translate-api/met`) if possible, or introduce delays between requests. Ensure languages used with EPT mode are within its supported list.","cause":"Frequent requests exceeding Bing's rate limits, especially common when using the older Bing Translator mode or EPT mode with unsupported languages causing a fallback to legacy.","error":"HTTP 429 Too Many Requests"},{"fix":"Upgrade to version `4.0.1` or later, as this issue was fixed in `v4.0.1`.","cause":"Incorrect TypeScript type declaration syntax, specifically nested `declare` modifiers.","error":"TS(1038): A 'declare' modifier cannot be used in an already ambient context."},{"fix":"Upgrade to version `4.0.2` or later, as this specific error was addressed in `v4.0.2` by avoiding throwing an error when `detectedLang` is absent.","cause":"The `detectedLang` property was sometimes missing from the API response.","error":"TypeError: Cannot read properties of undefined (reading 'detectedLang')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}