Frequently asked questions
How do I authenticate my Python requests?
Include your API key in the Authorization header as a Bearer token. The format is Authorization: Bearer tts-.... You obtain this key from your account dashboard at /get-api-key/. Ensure you use the active key associated with your NarrativeCode account to successfully authenticate your Python requests.
Can I use the OpenAI Python SDK?
Yes, the official OpenAI Python SDK works seamlessly. You simply change the base_url parameter to https://api.jur012.cc/v1 and provide your NarrativeCode API key. This allows you to use the standard client.audio.speech.create method without modifying your existing code structure significantly.
What is the base URL?
The base URL for all API requests is https://api.jur012.cc/v1. You use this when initializing your HTTP client or SDK. The specific endpoint for generating audio is POST https://api.jur012.cc/v1/audio/speech. All other endpoints follow this same base URL structure.
How do I set the language to Hindi?
Pass the ISO code hi in the language field of your request JSON. Although Hindi uses Devanagari script, explicitly setting the language ensures correct pronunciation. If omitted, the API guesses the language, but setting it explicitly is recommended for Hindi to avoid defaults.
What happens if I exceed the rate limit?
You are limited to 60 requests per minute per key. If you exceed this, subsequent requests will fail. Failed requests are free, so you will not be charged for the attempt. You must wait until the rate limit window resets before sending more requests.
Can I change my API key?
Yes, you can issue a new API key at any time from your account dashboard. When you generate a new key, the old one stops working immediately. This ensures secure access management for your Python scripts without needing to wait for a cooldown period.
Is the SDK official?
No, we do not provide an official SDK specific to NarrativeCode. We rely on the official OpenAI Python SDK. Since our API endpoint shape matches the OpenAI speech endpoint, you can use their standard library by pointing it to our base URL.
How do I handle errors in Python?
Use standard exception handling for your HTTP client. If the API returns an error, such as a rate limit exceeded or invalid input, the SDK will raise an exception. Check the response status code and error message to determine the cause, such as insufficient balance or invalid voice ID.
Does the API support async requests?
The API does not support streaming or WebSocket connections for real-time partial audio. However, you can use Python’s asyncio library to send multiple independent requests concurrently. Each request is processed sequentially on our end, but your Python code can manage parallelism efficiently.
What is the maximum input length?
The maximum input length is 4096 characters per request. Spaces and punctuation count toward this limit. For longer texts, you must split the text into chunks of up to 4096 characters, generate audio for each, and then join the resulting audio files programmatically.
Can I stream the audio?
No, the API does not support streaming audio. It returns the complete audio file in the response body. You receive the file after synthesis is complete. This means you cannot play partial audio while it is being generated; you must wait for the full file.
How do I install the Python package?
Install the OpenAI Python package using pip. Run pip install openai in your terminal. This provides the necessary classes and methods to interact with our API. No additional NarrativeCode-specific packages are required since we use the standard OpenAI endpoint structure.
Do I need to import specific libraries?
You need to import the openai library. Specifically, you will use openai.OpenAI to initialize the client. You may also need os to manage your API key environment variable. No other specific libraries are required for basic text-to-speech functionality.
Is JSON the only format?
Yes, the request body must be sent as JSON. You specify parameters like model, input, voice, and response_format in JSON format. The response returns the audio file directly, but the instruction to generate it is strictly JSON-based. Other formats are not supported for requests.
First request
curl
curl https://api.jur012.cc/v1/audio/speech \
-H "Authorization: Bearer $TTS_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"tts-1","voice":"aria","input":"Hello from the API.","response_format":"mp3"}' \
--output hello.mp3Python (openai)
from openai import OpenAI
client = OpenAI(base_url="https://api.jur012.cc/v1", api_key="tts-...")
with client.audio.speech.with_streaming_response.create(
model="tts-1", voice="nova", input="Hello from Python.", response_format="mp3"
) as response:
response.stream_to_file("hello.mp3")Node.js (openai)
import OpenAI from "openai";
import fs from "node:fs";
const client = new OpenAI({ baseURL: "https://api.jur012.cc/v1", apiKey: process.env.TTS_API_KEY });
const res = await client.audio.speech.create({ model: "tts-1", voice: "milo", input: "Hello from Node.js." });
fs.writeFileSync("hello.mp3", Buffer.from(await res.arrayBuffer()));| voice | |
|---|---|
aria | female |
nova | female |
luna | female |
sage | female |
felix | male |
milo | male |
atlas | male |
orion | male |
| language | |
|---|---|
ar | العربية |
zh | 中文 |
da | Dansk |
nl | Nederlands |
en | English |
fi | Suomi |
fr | Français |
de | Deutsch |
el | Ελληνικά |
he | עברית |
hi | हिन्दी |
it | Italiano |
ja | 日本語 |
ko | 한국어 |
ms | Bahasa Melayu |
no | Norsk |
pl | Polski |
pt | Português |
ru | Русский |
es | Español |
sw | Kiswahili |
sv | Svenska |
tr | Türkçe |
Authentication
Secure your API access by passing your key in the HTTP header. NarrativeCode uses a simple Bearer token scheme that integrates seamlessly with your existing Python scripts for Hindi audiobook generation.
API Key Header
Include your key in every request using the standard Authorization header format. This ensures your account is correctly identified for billing and rate limit tracking when processing your text-to-speech jobs.
- Format: Authorization: Bearer tts-<your_key>
Key Management
You can generate a new API key at any time from your dashboard. This feature allows you to quickly revoke access if a key is compromised or shared with a third-party tool.
Single Key Limit
Each account maintains only one active key. When you issue a new key, the previous one stops working immediately, ensuring clear audit trails for your publishing pipeline.
Endpoint Overview
The API exposes three primary endpoints to manage audio generation and configuration. The Speech endpoint handles the core synthesis task, accepting text and returning audio files. The Voices and Models endpoints provide metadata about available voices and engine configurations without generating audio.
These endpoints allow you to integrate NarrativeCode’s Hindi TTS capabilities directly into your publishing pipeline. You can query available voices and verify model details before sending synthesis requests, ensuring your Python scripts use the correct parameters for consistent audiobook production.
Speech Endpoint
Use the POST endpoint to convert text into audio. Send a JSON body with your text, voice selection, and preferred format. The API returns the audio file directly in the response, ready for download or immediate playback in your workflow.
This endpoint supports multiple audio formats including MP3, WAV, Opus, and FLAC. You can also adjust the speaking speed between 0.25 and 4.0 to match the pacing of your Hindi narration.
- Endpoint: POST /v1/audio/speech
- Method: POST
- Content-Type: application/json
Voices Endpoint
The GET /v1/voices endpoint lists all available voice presets, their associated languages, and supported audio formats. This allows your application to dynamically populate voice selection menus for end-users or internal publishing tools.
You can filter voices by language to ensure the correct Hindi voice is selected for your specific text content.
- Endpoint: GET /v1/voices
- Method: GET
Models Endpoint
Check the available TTS models, such as tts-1 and tts-1-hd. Both models use the same engine and pricing, so there is no cost difference between them. The endpoint returns model details.
- Endpoint: GET /v1/models
- Method: GET
Request Parameters
The API request structure mirrors the OpenAI speech endpoint, allowing you to integrate NarrativeCode directly into existing Python pipelines. You select the model, provide the text input, and choose a voice preset that best fits your audiobook's narrative style.
Each parameter ensures precise control over the synthesis process, from character limits to voice selection, enabling consistent quality for long-form self-publishing projects without external dependencies or custom SDKs.
Model Selection
Choose between tts-1 for standard generation or tts-1-hd for higher quality. Both use the same engine and pricing, so you can upgrade quality without changing your integration logic.
Selecting the model is straightforward: simply pass the desired string in the model field of your JSON payload.
tts-1: Standard qualitytts-1-hd: High-definition audio
Input Text Field
The input field accepts plain text up to 4096 characters per request. For longer manuscripts, split your text into chunks and join the resulting audio files sequentially.
Spaces and punctuation count toward the character limit, so ensure your preprocessing pipeline accounts for this when calculating costs and chunk sizes.
Note that the API does not support SSML, so formatting must be handled in your text preparation step.
- Maximum length: 4096 characters
- Includes spaces and punctuation
Voice Selection
Choose from eight presets like aria for a warm narrator or atlas for neutral news-style delivery. All voices support Hindi and 22 other languages, allowing flexible casting for diverse audiobook projects.
Set the voice parameter to your chosen preset. If the language field is omitted, the system guesses the language from the script, but for Hindi Latin-script text, explicitly set language: hi for best results.
Every audio file includes an inaudible synthetic watermark, distinguishing your generated content as AI-produced.
- 8 voice presets available
- Supports 23 languages including Hindi
Response Formats
The API returns audio files in formats specified by the response_format parameter in your request. Supported options include mp3, wav, opus, and flac. Choose the format that best suits your audiobook distribution pipeline or archival needs.
MP3 Output
MP3 is a supported format. You can specify response_format: mp3 in your JSON payload to receive this format. Universal compatibility with audiobook retailers Smaller file sizes for faster uploads Default format for most integrations
WAV Output
WAV provides uncompressed, high-quality audio suitable for professional editing or mastering stages. Select response_format: wav to receive lossless PCM audio data. This format is ideal if you plan to apply further post-processing to your Hindi audiobook chapters before distribution.
Opus and FLAC
Opus offers efficient compression with good quality, while FLAC provides lossless compression for perfect audio preservation without increasing file size as much as WAV. Use response_format: opus or response_format: flac depending on your storage and quality preferences. These formats are excellent for archiving high-fidelity recordings of your self-published works.
Error Handling
When your TTS request fails, the API returns a standard JSON error object with a status code and a human-readable message. These errors help you debug issues quickly without guessing the cause.
Common failures include invalid API keys, unsupported voice IDs, or malformed JSON bodies. Always check the response body for the message field to understand exactly what went wrong before retrying.
Common Error Codes
Use 401 for authentication failures when your Authorization header is missing or incorrect. Use 400 for bad requests, such as exceeding the 4096 character limit per request or providing an invalid response_format. Use 500 for internal server errors during synthesis.
Check the error object in the JSON response. It contains a code and a message string that explains the specific failure, allowing you to adjust your Python script accordingly.
- 401: Unauthorized (invalid or missing key)
- 400: Bad Request (invalid parameters or limits)
- 500: Internal Server Error (synthesis failed)
Rate Limit Errors
Receive a 429 status code if you exceed 60 requests per minute. New accounts without top-ups start with a stricter limit of 10 requests per minute. Implement exponential backoff in your Python loop to handle these pauses gracefully.
Failed requests are free and do not consume your character balance, but they still count toward your rate limit. Monitor your usage dashboard to anticipate high-volume publishing days.
- 429: Too Many Requests (limit exceeded)
- Rate limit resets every 60 seconds
- New accounts: 10 requests/minute initially
Input Validation
Ensure your input text does not exceed 4096 characters. If your audiobook chapter is longer, split it into chunks in Python before sending individual requests. Spaces and punctuation count toward this limit.
Validate that the voice ID exists in the GET /v1/voices response. If the language code is invalid or missing for non-English Latin text, the API may guess incorrectly, leading to poor audio quality.
- Max input length: 4096 characters
- Spaces and punctuation count as characters
- Validate voice IDs before sending requests

Rate Limits
The API enforces a strict rate limit of 60 requests per minute per key. This ensures stable performance for batch processing audiobook chapters. Since requests are processed sequentially, long texts may queue briefly during high load.
Each request handles up to 4096 characters. For longer books, split your text into chunks and join the resulting audio files programmatically. This approach keeps individual requests within limits and maintains consistent generation speeds.
60 Requests Per Minute
After your initial trial or top-up, you can make 60 requests per minute. This limit applies to the POST /v1/audio/speech endpoint. It is sufficient for generating most audiobook chapters in reasonable timeframes without complex throttling logic.
- Limit is per API key, not per IP.
- Applies to all request types equally.
- No burst allowance beyond the per-minute average.
Initial Limit
New accounts start with a lower limit of 10 requests per minute. This applies until you make your first top-up. Once you add credit via USTRC-20, the limit increases to the full 60 requests per minute immediately.
- Initial limit: 10 requests/minute.
- Increases after first top-up.
- Applies to all keys created after top-up.
Limit Reset
The rate limit window resets continuously every minute. There is no fixed hourly or daily cap. If you exceed the limit, you receive a 429 error. Simply wait for the window to slide forward and retry your request.
- Sliding window reset.
- No daily cap.
- Retry after receiving 429 status code.
Speed Control
Speed control lets you adjust the generation pace from 0.25x to 4.0x, giving you precise command over audiobook timing. This feature is essential for self-publishing authors who need to match specific narration styles or ensure clarity for complex Hindi texts.
By modifying the speed parameter, you can create a more engaging listening experience without re-recording. Faster speeds work well for simple narratives, while slower rates enhance comprehension for dense content.
Speed Range
The API accepts speed values between 0.25 and 4.0. This wide range allows you to fine-tune the output significantly, accommodating everything from slow, deliberate storytelling to rapid, energetic delivery.
Values outside this range may result in errors or unnatural audio quality. Stick to the documented bounds for consistent results across all voices and languages.
- Minimum: 0.25x for very slow, clear narration.
- Maximum: 4.0x for fast-paced updates.
- Default: 1.0x for standard natural speech.
Adjusting Pace
To adjust the pace, include the speed field in your JSON request body alongside the text and voice parameters. This adjustment applies to the entire request, ensuring uniform pacing throughout the generated audio file.
For long texts, consider splitting them into parts. This allows you to vary the speed for different sections, such as using a slower pace for dialogue and a faster pace for descriptive passages.
- Add
speedto the request JSON. - Apply consistent pacing for single requests.
- Vary pace by splitting long texts.
Default Speed
If you do not specify a speed, the API defaults to 1.0x, which provides a natural, balanced narration speed. This is suitable for most audiobook projects and requires no additional configuration.
Using the default speed ensures compatibility with standard listening expectations. It is the recommended starting point for new projects before fine-tuning for specific voice characteristics.
The default speed works seamlessly with all eight available voices, ensuring consistent audio quality regardless of the selected narrator.
- Default value is 1.0x.
- Suitable for most audiobook projects.
- Works with all available voices.
Code Examples
Integrate NarrativeCode into your Python audiobook pipeline with minimal overhead. Use standard libraries for simple scripts or leverage the OpenAI SDK for robust retry logic and type safety, ensuring your self-publishing workflow remains automated and reliable.
The following examples demonstrate how to send text and receive audio files directly. These snippets cover the most common use cases for generating Hindi and other language audiobooks programmatically.
Python Requests Library
Use the requests library for straightforward HTTP calls. Pass your API key in the header and send the JSON payload. The response contains the binary audio data, which you can write directly to a file.
This method is ideal for simple scripts where you need full control over the request lifecycle without installing additional SDK packages.
- Install via
pip install requests - Set
Authorization: Bearer tts-your-key - Handle binary response with
response.content
OpenAI SDK Usage
Leverage the official OpenAI Python SDK by pointing base_url to https://api.jur012.cc/v1. This allows you to use familiar methods like Audio.speech.create() with your NarrativeCode API key.
This approach is recommended for complex pipelines, as the SDK handles JSON serialization and provides consistent error handling for your audiobook generation tasks.
Ensure you pass `model=
tts-1
or tts-1-hd` as required by the endpoint.
Curl Command
For quick testing or shell-based automation, use curl to send a POST request. Replace YOUR_API_KEY and input your Hindi text.
This command returns the audio file directly to your terminal or a specified output file, useful for verifying voice settings before integrating into Python.
Listen to the 8 voices
Each sample below was generated by this API from the same sentence. For longer novels, split the text into parts and join the resulting audio files seamlessly.
23 languages
Any voice speaks any of these languages.
