Text to Speech API
Category: voice
Convert text to natural-sounding speech audio using ElevenLabs AI voices. Returns an MP3 audio file.
Endpoint
POST
https://anythingtext.com/api/tools/tts
Authentication Required
Content-Type: application/json
Authentication
This API requires an API key. Generate one from the API Keys section in your dashboard settings.
Include the X-API-Key header in all API requests:
X-API-Key: atk_your_api_key_here
Rate Limiting
API requests are limited to 60 requests per minute per user. If you exceed this limit, the API returns a 429 Too Many Requests response.
Every response includes rate limit headers:
X-RateLimit-Limit: 60
X-RateLimit-Remaining: 57
X-RateLimit-Reset: 42
When rate limited, the response body contains:
{ "error": "Rate limit exceeded. Maximum 60 requests per minute.", "retryAfter": 42, "limit": 60 }
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
text
|
String | Required |
The text to convert to speech
Example: Hello, welcome to AnythingText!
|
voiceId
|
String | Optional |
ElevenLabs voice ID (optional, uses default if omitted)
Example: 21m00Tcm4TlvDq8ikWAM
|
Response
Content-Type: audio/mpeg
MP3 audio file of the spoken text
(binary MP3 data)
Error Responses
| Status | Description | Body |
|---|---|---|
401 |
Not authenticated | {"error": "Please log in..."} |
400 |
Bad request / Missing required params | {"error": "... is required"} |
500 |
Internal server error | {"error": "Failed to ..."} |
cURL Example
curl -X POST https://anythingtext.com/api/tools/tts \
-H "Content-Type: application/json" \
-H "X-API-Key: your_api_key_here" \
-d '{"text": "Hello world"}' \
--output speech.mp3
Code Samples
const response = await fetch('https://anythingtext.com/api/tools/tts', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-API-Key': 'your_api_key_here'
},
body: JSON.stringify({
text: 'Hello, welcome to AnythingText!',
voiceId: '21m00Tcm4TlvDq8ikWAM' // optional
})
});
const blob = await response.blob();
const url = URL.createObjectURL(blob);
const audio = new Audio(url);
audio.play();
import requests
response = requests.post(
'https://anythingtext.com/api/tools/tts',
json={
'text': 'Hello, welcome to AnythingText!',
'voiceId': '21m00Tcm4TlvDq8ikWAM' # optional
},
headers={'X-API-Key': 'your_api_key_here'}
)
with open('speech.mp3', 'wb') as f:
f.write(response.content)
print('Audio saved to speech.mp3')
import java.net.URI;
import java.net.http.*;
import java.nio.file.*;
HttpClient client = HttpClient.newHttpClient();
String json = "{\"text\": \"Hello, welcome to AnythingText!\"}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://anythingtext.com/api/tools/tts"))
.header("Content-Type", "application/json")
.header("X-API-Key", "your_api_key_here")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
HttpResponse<byte[]> response = client.send(request,
HttpResponse.BodyHandlers.ofByteArray());
Files.write(Path.of("speech.mp3"), response.body());
System.out.println("Audio saved to speech.mp3");