Getting Started
Everything you need to make your first API request
Base URL
All API requests should be made to:
https://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 request.
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
Getting Your API Key
- Log in to your Moknah Dashboard
- Navigate to API Keys
- Click Create 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.
Request Format
All requests must include the following headers:
| Header | Value | Required |
|---|---|---|
| Authorization | Bearer YOUR_API_KEY |
Required |
| Content-Type | application/json |
Required for POST requests |
Quick Example
Here's a complete example to generate speech from text:
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': f'Bearer your_api_key',
},
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: Returns binary audio data (
audio/mpeg) - Other endpoints: Returns JSON data
Response Headers
Every response includes rate limit information:
| 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 |
Error Handling
Errors return JSON with a consistent structure:
{
"error_code": "INVALID_REQUEST",
"message": "Invalid request parameters",
"details": {
"text": ["This field is required."]
}
}
Common Error Codes
| HTTP Status | Error Code | Description |
|---|---|---|
| 400 | INVALID_REQUEST |
Invalid parameters |
| 401 | UNAUTHORIZED |
Invalid or missing API key |
| 402 | INSUFFICIENT_CREDITS |
Not enough credits |
| 429 | RATE_LIMIT_EXCEEDED |
Too many requests |
| 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:
For API-related questions or issues, contact us at api@moknah.io.