Getting Started
Everything you need to make your first API request
Base URLs
Moknah provides two types of endpoints depending on your use case:
Standard REST API (for single requests):
https://moknah.io/api/v1/
Real-time WebSocket API (for continuous streaming):
wss://moknah.io/api/v1/
Authentication
The Moknah API uses API keys for authentication. Include your API key in the Authorization header using the
Bearer scheme with every HTTP request and WebSocket handshake.
Authorization: Bearer YOUR_API_KEY
Getting Your API Key
- Log in to your Moknah Dashboard
- Subscribe to the Pro Plan or contact Sales for enterprise access.
- Navigate to API
- Click Manage API Keys
- Click New Key
- Copy and securely store your key
Never expose your API key in client-side code or public repositories. Treat it like a password.
Quick HTTP Example
Here's a complete example to generate speech from text using the standard REST API:
curl -X POST "https://moknah.io/api/v1/tts/generate/" \
-H "Authorization: Bearer your_api_key" \
-H "Content-Type: application/json" \
-d '{
"text": "مرحبا بك في منصة مكنة",
"voice_id": 1
}' \
--output speech.mp3
import requests
response = requests.post(
"https://moknah.io/api/v1/tts/generate/",
headers={
"Authorization": f"Bearer your_api_key",
},
json={
"text": "مرحبا بك في منصة مكنة",
"voice_id": 1
}
)
if response.status_code == 200:
with open("speech.mp3", "wb") as f:
f.write(response.content)
print("Audio saved!")
else:
print(f"Error: {response.json()}")
const response = await fetch(
'https://moknah.io/api/v1/tts/generate/',
{
method: 'POST',
headers: {
'Authorization': 'Bearer your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'مرحبا بك في منصة مكنة',
voice_id: 1
})
}
);
if (response.ok) {
const blob = await response.blob();
// Use the audio blob
console.log("Audio generated!");
} else {
const error = await response.json();
console.error(error);
}
Response Format
Success Responses
Successful responses vary by endpoint:
- TTS Generate (POST): Returns complete binary audio data (audio/mpeg)
- TTS Stream (WSS): Streams binary MP3 chunks continuously as they are generated
- Other endpoints: Returns structured JSON data
Rate Limit Headers (HTTP Only)
Every HTTP response includes rate limit information (WebSockets enforce limits via connection closures):
| Header | Description |
|---|---|
| RateLimit-Limit | Maximum requests per minute |
| RateLimit-Remaining | Requests remaining in current window |
| RateLimit-Reset | Unix timestamp when limit resets |
| Moknah-Credits-Remaining | Your remaining credit balance |
Common Error Codes
| Code | Type | Description |
|---|---|---|
| 400 | INVALID_REQUEST |
Invalid parameters or malformed JSON |
| 401 | UNAUTHORIZED |
Invalid or missing API key |
| 402 | INSUFFICIENT_CREDITS |
Account does not have enough credits |
| 429 | RATE_LIMIT_EXCEEDED |
Too many requests (HTTP) |
| 4290 | CONCURRENT_LIMIT |
Too many active connections (WSS) |
| 500 | INTERNAL_SERVER_ERROR |
Server error |
See the Errors page for detailed error handling guidance.
Next Steps
Now that you're set up, explore the available endpoints:
Get available voices for TTS
Convert text to audio
Real-time WebSocket TTS
Extract text from audio file
Real-time WebSocket STT
For API-related questions or issues, contact us at api@moknah.io.