Endpoint
Connection
Connect to the WebSocket endpoint:x-api-key header during the WebSocket handshake.
Authentication
Requires API key authentication. Authentication can be provided via:- Query parameter:
?x-api-key=YOUR_API_KEY - Header:
x-api-key: YOUR_API_KEY - In
initConnectionmessage:x_api_keyfield
Request
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
x-api-key | string | No* | API key for authentication (alternative to header) |
initConnection message
Headers
| Header | Type | Required | Description |
|---|---|---|---|
x-api-key | string | No* | API key for authentication |
initConnection message
InitConnection Message Parameters
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "initConnection" |
model_id | string | Yes | The model identifier to use for generation |
voice_id | string | Yes | The voice ID to use for synthesis |
voice_settings | object | No | Voice settings object |
voice_settings.stability | number | No | Voice stability (0.0 to 1.0). Higher values produce more consistent output. Default: 0.5 |
x_api_key | string | No* | API key for authentication (alternative to query/header) |
Text Message Parameters
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "text" |
text | string | Yes | The Arabic text to append to the buffer |
try_trigger_generation | boolean | Yes | If true, triggers generation immediately after appending text |
CloseConnection Message Parameters
| Field | Type | Required | Description |
|---|---|---|---|
type | string | Yes | Must be "closeConnection" |
Example InitConnection Request
Example Text Request
Example CloseConnection Request
Message Types
Initialize Connection
Initialize the WebSocket connection with model and voice settings. Message:Send Text
Send text for generation. Text is buffered until generation is triggered. Message:text(string): The text to append to the buffertry_trigger_generation(boolean): Iftrue, triggers generation immediately after appending text
Close Connection
Gracefully close the WebSocket connection. Message:Response Types
Audio Chunk
Streaming audio data as base64-encoded PCM16 chunks.Final Chunk
Indicates the end of audio generation.Error
Error response with descriptive message.Example Usage
JavaScript
Python
Best Practices
- Initialize First: Always send
initConnectionbefore sending text - Handle Errors: Implement error handling for all error message types
- Buffer Management: Text is buffered until
try_trigger_generationistrue - Connection Lifecycle: Close connections gracefully using
closeConnection - Reconnection: Implement reconnection logic for production applications
Cost Calculation
Cost is calculated and deducted from your wallet balance when generation completes successfully. The cost is based on:- Text length (number of characters)
- Model cost per character
Wallet Balance: Ensure your wallet has sufficient balance. Insufficient balance will result in an error message. Check your balance in the Faseeh dashboard.