title: Translate Subtitles description: Translate SRT or VTT subtitle files while preserving all timestamps and formatting
Translate Subtitles
Translate SRT or VTT subtitle files while preserving all timestamps and formatting.
Endpoint
POST /v2/translate/subtitles
Only the text content is translated. All timestamps, formatting, and subtitle structure are preserved exactly as provided.
Headers
X-API-KEY string (required)
: Your API key for authentication
Content-Type string (required)
: Must be application/json
Request Parameters
Body Parameters
format string (required)
: Subtitle format: "srt" or "vtt"
content string (required)
: The subtitle file content (SRT or VTT format)
source string (required)
: Source language code (e.g., "en", "fr") or "auto" for auto-detection
target string (required)
: Target language code (e.g., "en", "fr")
Example Request
curl https://api.translateplus.io/v2/translate/subtitles \
-H "X-API-KEY: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"format": "srt",
"content": "1\n00:00:01,000 --> 00:00:02,000\nHello world\n",
"source": "en",
"target": "es"
}'
import requests
url = "https://api.translateplus.io/v2/translate/subtitles"
headers = {
"X-API-KEY": "your_api_key",
"Content-Type": "application/json"
}
data = {
"format": "srt",
"content": "1\n00:00:01,000 --> 00:00:02,000\nHello world\n",
"source": "en",
"target": "es"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
fetch('https://api.translateplus.io/v2/translate/subtitles', {
method: 'POST',
headers: {
'X-API-KEY': 'your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
format: 'srt',
content: '1\n00:00:01,000 --> 00:00:02,000\nHello world\n',
source: 'en',
target: 'es'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
const https = require('https');
const data = JSON.stringify({
format: 'srt',
content: '1\n00:00:01,000 --> 00:00:02,000\nHello world\n',
source: 'en',
target: 'es'
});
const options = {
hostname: new URL('https://api.translateplus.io').hostname,
path: '/v2/translate/subtitles',
method: 'POST',
headers: {
'X-API-KEY': 'your_api_key',
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log(JSON.parse(responseData));
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
<?php
$url = 'https://api.translateplus.io/v2/translate/subtitles';
$apiKey = 'your_api_key';
$data = [
'format' => 'srt',
'content' => "1\n00:00:01,000 --> 00:00:02,000\nHello world\n",
'source' => 'en',
'target' => 'es'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-KEY: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$result = json_decode($response, true);
echo $result['content'];
} else {
echo 'Error: ' . $response;
}
Success Response (200 OK)
{
"format": "srt",
"content": "1\n00:00:01,000 --> 00:00:02,000\nHola mundo\n"
}
Response Fields
| Field | Type | Description |
|-------|------|-------------|
| format | string | The subtitle format ("srt" or "vtt") |
| content | string | The translated subtitle content with timestamps preserved |
Features
- Format Support: Supports both SRT (SubRip) and VTT (WebVTT) subtitle formats
- Timestamp Preservation: All timestamps are preserved exactly as provided
- Structure Maintenance: Subtitle block structure and formatting are maintained
- Text Translation: Only the text content is translated, timestamps remain unchanged
- Multi-line Support: Handles multi-line subtitle text correctly
- Credits: Requires 1 credit per subtitle block (text entry)
How It Works
- Parses subtitle content into blocks (index, timestamp, text)
- Extracts text content from each block
- Translates each text block while preserving timestamps
- Reconstructs the subtitle file with translated text
Error Responses
400 Bad Request
Invalid request parameters:
{
"detail": "Format must be 'srt' or 'vtt'"
}
402 Payment Required
Insufficient credits:
{
"detail": "Insufficient credits. You have 0 credit(s) remaining, but this request requires 5 credit(s). Please upgrade your plan to continue using the API."
}
403 Forbidden
Invalid or missing API key:
{
"detail": "API key is required. Please provide X-API-KEY header."
}
429 Too Many Requests
Rate limit exceeded:
{
"detail": "Rate limit exceeded. You have made 60 requests. Maximum allowed: 60 requests per minute. Please try again after 45 seconds."
}
Credits
This endpoint requires 1 credit per subtitle block (text entry) in the file.