Official JavaScript/TypeScript SDK for the Langbly translation API — a drop-in replacement for Google Translate v2, powered by LLMs.
5-10x cheaper than Google Translate · Better quality · Switch in one PR
npm install langblyimport { Langbly } from "langbly";
const client = new Langbly({ apiKey: "your-api-key" });
// Translate text
const result = await client.translate("Hello world", { target: "nl" });
console.log(result.text); // "Hallo wereld"
// Batch translate
const results = await client.translate(["Hello", "Goodbye"], { target: "nl" });
results.forEach((r) => console.log(r.text));
// Detect language
const detection = await client.detect("Bonjour le monde");
console.log(detection.language); // "fr"
// List supported languages
const languages = await client.languages({ target: "en" });Already using @google-cloud/translate? Switching takes 2 minutes:
// Before (Google Translate)
import { Translate } from "@google-cloud/translate/build/src/v2";
const client = new Translate();
const [translation] = await client.translate("Hello", "nl");
// After (Langbly) — same concepts, better translations, 5x cheaper
import { Langbly } from "langbly";
const client = new Langbly({ apiKey: "your-key" });
const result = await client.translate("Hello", { target: "nl" });→ Full migration guide: langbly.com/docs/migrate-google
- Google Translate v2 API compatible — same endpoint format
- Zero dependencies — uses native
fetch - Full TypeScript types — interfaces for all request/response shapes
- Auto-retry — exponential backoff on 429/5xx with Retry-After support
- Typed errors —
RateLimitError,AuthenticationError,LangblyError - Batch translation — translate multiple texts in one request
- Language detection — automatic source language identification
- HTML support — translate HTML while preserving tags
import { Langbly, RateLimitError, AuthenticationError } from "langbly";
const client = new Langbly({ apiKey: "your-key" });
try {
const result = await client.translate("Hello", { target: "nl" });
} catch (err) {
if (err instanceof AuthenticationError) {
console.error("Invalid API key");
} else if (err instanceof RateLimitError) {
console.error(`Rate limited — retry after ${err.retryAfter}s`);
}
}Create a client instance.
apiKey(string): Your Langbly API key — get one freebaseUrl(string, optional): Override API URL (default:https://api.langbly.com)timeout(number, optional): Request timeout in ms (default: 30000)maxRetries(number, optional): Retries for transient errors (default: 2)
text(string | string[]): Text(s) to translateoptions.target(string): Target language codeoptions.source(string, optional): Source language codeoptions.format("text" | "html", optional): Input format
text(string): Text to analyze
options.target(string, optional): Language code for names
MIT