API Documentation

Welcome to the FlexiTranslate API documentation. Our API provides powerful, context-aware translation capabilities for your applications with enterprise-grade reliability.

Introduction

FlexiTranslate API offers blazing-fast, neural machine translation across 140+ languages. With our simple RESTful interface, you can integrate translation capabilities into any application in minutes.

New to FlexiTranslate?
Sign up for a free account and get 10,000 monthly requests at no cost. No credit card required.

Base URL

https://api.flexitranslate.org/v1

Quick Start

Here's a simple example to get you started with translation:

curl -X POST https://api.flexitranslate.org/v1/translate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Hello, world!",
    "target_lang": "es"
  }'

Authentication

All API requests require authentication using an API key. You can obtain your API key from the dashboard after signing up.

Security Best Practices
Never expose your API key in client-side code. Always use server-side integration for production applications.

Authentication Header

Include your API key in the Authorization header:

Authorization: Bearer ft_live_xxxxxxxxxxxxx

Rate Limits

Rate limits vary by plan. Free tier: 60 requests per minute.

Translate Text

POST /v1/translate

Translates text from one language to another using our advanced neural machine translation engine.

Request Parameters

ParameterTypeRequiredDescription
textstringYesThe text to translate (max 5000 characters)
target_langstringYesTarget language code (e.g., "es", "fr", "ja")
source_langstringNoSource language code (auto-detected if omitted)
formalitystringNo"formal" or "informal" (default: "formal")

Response

{
  "success": true,
  "data": {
    "translated_text": "¡Hola, mundo!",
    "detected_source_lang": "en",
    "target_lang": "es",
    "character_count": 13,
    "usage": {
      "remaining_requests": 9987,
      "remaining_chars": 987654
    }
  }
}
curl -X POST https://api.flexitranslate.org/v1/translate \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "Welcome to FlexiTranslate!",
    "target_lang": "zh"
  }'
const response = await fetch('https://api.flexitranslate.org/v1/translate', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    text: 'Welcome to FlexiTranslate!',
    target_lang: 'zh'
  })
});

const data = await response.json();
console.log(data.data.translated_text);
import requests

url = "https://api.flexitranslate.org/v1/translate"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
data = {
    "text": "Welcome to FlexiTranslate!",
    "target_lang": "zh"
}

response = requests.post(url, json=data, headers=headers)
result = response.json()
print(result["data"]["translated_text"])

Detect Language

POST /v1/detect

Detects the language of the provided text.

Request Parameters

ParameterTypeRequiredDescription
textstringYesThe text to analyze

Response

{
  "success": true,
  "data": {
    "language": "English",
    "language_code": "en",
    "confidence": 0.98
  }
}

Supported Languages

FlexiTranslate supports over 140 languages. Here are the most commonly used ones:

LanguageCode
Englishen
Spanishes
Frenchfr
Germande
Chinese (Simplified)zh
Japaneseja
Koreanko
Arabicar
Russianru
Portuguesept
For a complete list of all supported languages, make a GET request to /v1/languages

Website Widget

Add instant translation to your website with our easy-to-use widget. No coding required!

✨ New Feature!
Our widget automatically detects your website's language and offers translation to your visitors with a single click.

Quick Installation

Copy and paste this code snippet just before the closing </body> tag of your website:

<script src="https://flexitranslateapi-dweeikl6jq-uc.a.run.app/api/v1/widget.js?key=YOUR_API_KEY" defer></script>

Advanced Configuration

You can customize the widget behavior with additional parameters:

ParameterDescriptionExample
positionWidget position on screenbottom-right, bottom-left
themeColor themelight, dark, auto
languagesComma-separated language codesen,es,fr,de,zh
auto_detectAuto-detect visitor languagetrue or false

Customized Example

<script src="https://flexitranslateapi-dweeikl6jq-uc.a.run.app/api/v1/widget.js?key=YOUR_API_KEY&position=bottom-left&theme=dark&languages=en,es,fr,de,it,pt,zh,ja,ko&auto_detect=true" defer></script>
Pro Tip: You can also initialize the widget programmatically:
window.FlexiTranslateWidget = {
  key: 'YOUR_API_KEY',
  position: 'bottom-right',
  theme: 'auto',
  languages: ['en', 'es', 'fr', 'de'],
  onTranslate: function(lang) {
    console.log('Translated to:', lang);
  }
};

Widget Configuration Options

OptionTypeDefaultDescription
positionstringbottom-rightWidget position on the page
themestringlightColor scheme (light, dark, auto)
languagesarray['en','es','fr','de','zh','ja','ar']Available languages for translation
auto_detectbooleantrueAutomatically detect visitor's language
show_powered_bybooleantrueShow "Powered by FlexiTranslate"
animationstringslideAnimation style (slide, fade, none)
primary_colorstring#2b5f6bCustom primary color (hex)

Live Examples

Try it yourself! Here's a working example. Replace YOUR_API_KEY with your actual API key.
<!DOCTYPE html>
<html>
<head>
    <title>My Translated Website</title>
    <style>
        body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
        h1 { color: #2b5f6b; }
    </style>
</head>
<body>
    <h1>Welcome to My Website</h1>
    <p>This content will be automatically translated when visitors use the widget.</p>
    
    <script src="https://flexitranslateapi-dweeikl6jq-uc.a.run.app/api/v1/widget.js?key=YOUR_API_KEY" defer></script>
</body>
</html>

Error Handling

The API uses conventional HTTP response codes to indicate success or failure of requests.

CodeMeaningDescription
200SuccessRequest was successful
400Bad RequestInvalid parameters or missing required fields
401UnauthorizedInvalid or missing API key
429Rate LimitedToo many requests, slow down
500Server ErrorInternal server error, try again later

Error Response Format

{
  "success": false,
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Please wait before making more requests.",
    "retry_after": 60
  }
}

JavaScript SDK

Install our official JavaScript SDK for seamless integration:

npm install flexitranslate-sdk
import FlexiTranslate from 'flexitranslate-sdk';

const ft = new FlexiTranslate({
  apiKey: 'YOUR_API_KEY'
});

// Translate text
const result = await ft.translate({
  text: 'Hello, world!',
  targetLang: 'es'
});

console.log(result.translatedText); // ¡Hola, mundo!

Python SDK

pip install flexitranslate
from flexitranslate import Client

client = Client(api_key='YOUR_API_KEY')

# Translate text
result = client.translate(
    text='Hello, world!',
    target_lang='fr'
)

print(result.translated_text)  # Bonjour, le monde !

cURL Examples

Batch Translation

curl -X POST https://api.flexitranslate.org/v1/translate/batch \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "texts": ["Hello", "Good morning", "Good night"],
    "target_lang": "es"
  }'

Get Usage Statistics

curl -X GET https://api.flexitranslate.org/v1/usage \
  -H "Authorization: Bearer YOUR_API_KEY"

Usage Statistics

Monitor your API usage with the stats endpoint:

GET /v1/usage

Response

{
  "success": true,
  "data": {
    "current_month": {
      "requests": 1234,
      "characters": 45678,
      "limit": 10000
    },
    "lifetime": {
      "total_requests": 56789,
      "total_characters": 1234567
    },
    "rate_limit": {
      "remaining": 57,
      "reset_in": 45
    }
  }
}