LibreTranslate
libretranslate.com · AI
Free and open-source machine translation API — translate text between 30+ languages. Self-hostable for full privacy. Public instance available with API key (free tier available).
Authentication
API Key
Free API key at libretranslate.com. Pass as api_key in request body. Can also self-host for unlimited use.
Sample Requests
POST
Translate text
Translate English to Spanish.
https://libretranslate.com/translate
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Content-Type | application/json |
Request Body — data you're sending
{
"q": "Hello, world!",
"source": "en",
"target": "es",
"api_key": "YOUR_KEY"
}
curl -X POST "https://libretranslate.com/translate" \
-H "Content-Type: application/json" \
-H "Content-Type: application/json" \
-d '{"q":"Hello, world!","source":"en","target":"es","api_key":"YOUR_KEY"}'import requests
headers = {
"Content-Type": "application/json"
}
data = {
"q": "Hello, world!",
"source": "en",
"target": "es",
"api_key": "YOUR_KEY"
}
response = requests.post(
"https://libretranslate.com/translate",
headers=headers,
json=data,
)
print(response.json())const url = 'https://libretranslate.com/translate';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"q": "Hello, world!",
"source": "en",
"target": "es",
"api_key": "YOUR_KEY"
}),
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"bytes"
"encoding/json"
)
func main() {
targetURL := "https://libretranslate.com/translate"
jsonData, _ := json.Marshal({"q":"Hello, world!","source":"en","target":"es","api_key":"YOUR_KEY"})
req, _ := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://libretranslate.com/translate")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Content-Type"] = "application/json"
req.body = "{\"q\":\"Hello, world!\",\"source\":\"en\",\"target\":\"es\",\"api_key\":\"YOUR_KEY\"}"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://libretranslate.com/translate";
$opts = ["http" => [
"method" => "POST",
"header" => implode("\r\n", [
"Content-Type: application/json",
"Content-Type: application/json"
]),
"content" => json_encode({"q":"Hello, world!","source":"en","target":"es","api_key":"YOUR_KEY"}),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));
POST
Detect language
Detect the language of a text.
https://libretranslate.com/detect
Hover any highlighted part to learn what it does
Headers — extra info sent with the request
| Content-Type | application/json |
Request Body — data you're sending
{
"q": "Bonjour le monde",
"api_key": "YOUR_KEY"
}
curl -X POST "https://libretranslate.com/detect" \
-H "Content-Type: application/json" \
-H "Content-Type: application/json" \
-d '{"q":"Bonjour le monde","api_key":"YOUR_KEY"}'import requests
headers = {
"Content-Type": "application/json"
}
data = {
"q": "Bonjour le monde",
"api_key": "YOUR_KEY"
}
response = requests.post(
"https://libretranslate.com/detect",
headers=headers,
json=data,
)
print(response.json())const url = 'https://libretranslate.com/detect';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
"q": "Bonjour le monde",
"api_key": "YOUR_KEY"
}),
});
const data = await response.json();
console.log(data);package main
import (
"fmt"
"io"
"net/http"
"bytes"
"encoding/json"
)
func main() {
targetURL := "https://libretranslate.com/detect"
jsonData, _ := json.Marshal({"q":"Bonjour le monde","api_key":"YOUR_KEY"})
req, _ := http.NewRequest("POST", targetURL, bytes.NewBuffer(jsonData))
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, _ := client.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}require "net/http"
require "json"
uri = URI("https://libretranslate.com/detect")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
req = Net::HTTP::Post.new(uri)
req["Content-Type"] = "application/json"
req["Content-Type"] = "application/json"
req.body = "{\"q\":\"Bonjour le monde\",\"api_key\":\"YOUR_KEY\"}"
res = http.request(req)
puts JSON.parse(res.body)<?php
$url = "https://libretranslate.com/detect";
$opts = ["http" => [
"method" => "POST",
"header" => implode("\r\n", [
"Content-Type: application/json",
"Content-Type: application/json"
]),
"content" => json_encode({"q":"Bonjour le monde","api_key":"YOUR_KEY"}),
]];
$ctx = stream_context_create($opts);
$res = file_get_contents($url, false, $ctx);
print_r(json_decode($res, true));Postman Setup Guide
- Get a free API key at libretranslate.com
- POST to /translate with JSON body: {"q":"text","source":"en","target":"fr","api_key":"YOUR_KEY"}
- List languages: GET /languages
- Self-hosting: docker run -ti -p 5000:5000 libretranslate/libretranslate