JavaScript Guide to the Spindragons TTS API

By Spindragons editorial team · Updated 2026-11-19

This guide shows you how to generate speech from text using the Spindragons TTS API with JavaScript. You will learn to make JSON requests, handle responses, and manage your API key. The endpoint follows the same shape as the OpenAI speech API, so you can use the official OpenAI SDK by simply changing the base URL. No custom SDK or complex setup is required.

Designed for freelancers building web apps, this page covers authentication, endpoints, and error handling. You will see concrete examples for generating audio in MP3, WAV, or other formats. The guide explains rate limits, character constraints, and how to rotate your key. It is a practical reference for integrating text-to-speech into your JavaScript projects without managing infrastructure.

JavaScript Guide to the Spindragons TTS API

Frequently asked questions

How do I get an API key?

Sign up on /get-api-key/ using Google or email plus password. Your unique key appears immediately on the dashboard. You can issue a new key at any time, which instantly invalidates the previous one. This ensures your credentials remain secure while allowing easy rotation if needed.

What is the base URL?

The API base URL is https://api.spindragons.info/v1. Use this endpoint for all requests, including POST /v1/audio/speech for generation and GET /v1/voices for metadata. Ensure your HTTP client points to this domain to correctly route your JSON payloads to the Spindragons infrastructure.

Does it work with OpenAI SDK?

Yes, the request shape matches the OpenAI speech endpoint. Configure your OpenAI SDK by setting the base_url to https://api.spindragons.info/v1 and providing your Spindragons key. This allows you to use official OpenAI libraries without rewriting your integration logic for this specific API.

What formats are supported?

Supported formats include mp3, wav, opus, flac, and pcm. Specify your preferred format in the response_format field of your JSON request. Each format serves different use cases, from web-friendly MP3 to lossless FLAC, ensuring compatibility with your JavaScript audio players or processing pipelines.

How do I handle errors?

Failed requests are free: if synthesis fails, the charge is returned in full. Monitor your HTTP response status codes to detect errors. If a request fails, no characters are deducted from your balance, allowing you to retry or adjust parameters without financial penalty for the attempt.

What are the rate limits?

You are limited to 60 requests per minute per key. Before your first top-up, this limit drops to 10 requests per minute. Monitor your usage via the dashboard to avoid throttling, especially when generating audio for real-time applications or batch processing large text volumes.

Can I change my API key?

Yes, you can issue a new key at any time from your dashboard. When you generate a new key, the old one stops working immediately. This allows you to revoke access instantly if a key is compromised or if you need to rotate credentials for security.

Is the API JSON-based?

Yes, the API uses JSON for all requests and responses. You send a JSON body containing fields like model, input, and voice to the POST endpoint. The response returns the audio file directly, making it straightforward to integrate into JavaScript applications using standard fetch or axios calls.

How do I set the speed?

Set the speed using the speed field in your JSON request, with a range of 0.25 to 4.0. This allows you to adjust the playback rate of the generated audio. A value of 1.0 represents normal speed, while higher values accelerate the voice and lower values slow it down.

What models are available?

Two models are available: tts-1 and tts-1-hd. Both use the same engine and pricing structure. Select your preferred model in the request body to determine the quality and processing method. The choice does not affect the cost, which remains $10 per million characters for either option.

How do I list voices?

Send a GET request to /v1/voices to retrieve available voices, languages, formats, and pricing. This endpoint provides metadata about the eight presets, including their names and characteristics. Use this data to dynamically populate your UI controls, allowing users to select their preferred voice for synthesis.

Do I need a specific library?

No specific library is required. You can use any HTTP client, including the official OpenAI SDK, fetch(), or axios. The API accepts standard JSON payloads. Using the OpenAI SDK is convenient if you already have it installed, but plain HTTP requests work equally well for integration.

Can I use fetch()?

Yes, fetch() works perfectly for making requests to the API. Construct a POST request to the speech endpoint with your JSON body and Authorization header. This method is ideal for lightweight JavaScript applications that do not require the overhead of a full SDK, ensuring minimal dependencies in your project.

How do I authenticate?

Authenticate by including an Authorization header with the value Bearer followed by your API key. The key format starts with tts-. Include this header in every request to /v1 endpoints. Ensure the key is kept secure in your JavaScript environment to prevent unauthorized usage of your account balance.

First request

curl

curl https://api.spindragons.info/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.mp3

Python (openai)

from openai import OpenAI

client = OpenAI(base_url="https://api.spindragons.info/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.spindragons.info/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
ariafemale
novafemale
lunafemale
sagefemale
felixmale
milomale
atlasmale
orionmale
language
arالعربية
zh中文
daDansk
nlNederlands
enEnglish
fiSuomi
frFrançais
deDeutsch
elΕλληνικά
heעברית
hiहिन्दी
itItaliano
ja日本語
ko한국어
msBahasa Melayu
noNorsk
plPolski
ptPortuguês
ruРусский
esEspañol
swKiswahili
svSvenska
trTürkçe

Authentication

Sound wave illustration for: Authentication

Spindragons uses a simple bearer token for authentication. Your API key, which you can retrieve from the dashboard, grants access to all endpoints. Keep this key secure, as it acts as your sole credential for API requests.

API key format

API key format

Keys start with the prefix tts- followed by a unique string of characters. This format ensures easy identification within your codebase or environment variables. There is only one active key per account, simplifying management for small teams.

  • Prefix: tts-
  • Single active key per account
  • Visible on /get-api-key/

Bearer token usage

Bearer token usage

Include the key in the Authorization header of every HTTP request. Use the standard HTTP Bearer scheme: Authorization: Bearer tts-your_key_here. This method is compatible with standard fetch APIs and libraries like axios or OpenAI's SDK.

Key rotation

If you suspect your key has been compromised, you can issue a new one from your dashboard. The old key stops working immediately. This ensures no lingering access from potentially exposed tokens, maintaining security without downtime.

Endpoints

Sound wave illustration for: Endpoints

The Spindragons TTS API exposes three primary endpoints for generating audio and retrieving metadata. Use POST /v1/audio/speech to convert text into audio files, while GET /v1/voices and GET /v1/models provide configuration details.

Speech generation

Send a JSON payload to https://api.spindragons.info/v1/audio/speech to receive an audio file. The endpoint accepts text up to 4096 characters and returns audio in formats like MP3, WAV, OPUS, FLAC, or PCM. Longer texts require client-side splitting and concatenation.

List voices

Retrieve available voice presets and language support by calling GET /v1/voices. This endpoint returns metadata for the eight available voices (e.g., aria, nova, felix) and confirms supported languages, ensuring you select the correct voice for your input text.

List models

Call GET /v1/models to verify available model identifiers. Currently, the API supports "tts-1" and "tts-1-hd", which use the same engine and pricing. This endpoint helps confirm model availability for your integration without requiring trial requests.

Request Parameters

Sound wave illustration for: Request Parameters

The Spindragons TTS API accepts standard JSON bodies with specific parameters for audio generation. You must define the model, input text, and voice to receive the synthesized audio file.

Model selection

Select either "tts-1" or "tts-1-hd" for the model parameter. Both use the same engine and pricing, so choose based on your preference without cost difference.

Input text limits

The input field accepts up to 4096 characters per request. Spaces and punctuation count toward this limit. For longer texts, split your content into chunks, generate each part, and join the resulting audio files.

  • Maximum length: 4096 characters
  • Spaces and punctuation count
  • Split and join for longer texts

Voice and speed

Choose from eight preset voices like aria or atlas. You can adjust the speed parameter between 0.25 and 4.0 to alter the playback rate. The optional language field allows you to specify an ISO code for non-English text.

  • 8 voice presets available
  • Speed range: 0.25–4.0
  • Optional language ISO code

Response Formats

Sound wave illustration for: Response Formats

The API returns audio data as binary content within the HTTP response body. The format you receive depends entirely on the response_format parameter specified in your request. This allows you to choose the best balance between file size and quality for your specific JavaScript application needs.

MP3 output

MP3 is the default and most widely supported format. It provides a good balance between audio quality and file size, making it ideal for web delivery and storage. The generated file is ready to play directly in HTML5 audio players.

WAV output

WAV delivers uncompressed, lossless audio. Use this format if you need the highest fidelity for professional editing or specific voice-over workflows. Note that WAV files are significantly larger than MP3s, which may impact bandwidth and storage costs for large projects.

Other formats

Opus, FLAC, and PCM are available via the response_format field. Opus offers efficient compression. FLAC provides lossless compression. PCM returns raw linear audio data, useful for immediate processing in audio libraries without decoding overhead.

  • Opus: Efficient compression for web streaming
  • FLAC: Lossless compression for archiving
  • PCM: Raw linear audio data

Error Handling

Sound wave illustration for: Error Handling

The API returns standard HTTP status codes to indicate success or failure. A 200 OK response means the audio file is ready in the response body or the request was successful. Any 4xx or 5xx code indicates an issue that requires attention before retrying.

Common error codes

Use 400 for bad requests, 401 for unauthorized access, and 402 for insufficient funds. Server errors return 500 or 503. Check the JSON error object for a specific message to resolve the issue quickly.

  • 400: Bad Request
  • 401: Unauthorized
  • 402: Payment Required
  • 500: Internal Server Error

Rate limit errors

If you exceed 60 requests per minute, you receive a 429 Too Many Requests error. New accounts start with a lower limit of 10 requests per minute until the first top-up is processed.

Invalid requests

Ensure the input text does not exceed 4096 characters. Invalid voice names or unsupported formats also trigger errors. The response body includes details to help you correct the request parameters immediately.

Error Handling

Rate Limits

Sound wave illustration for: Rate Limits

The Spindragons TTS API enforces a maximum of 60 requests per minute per API key. This limit applies to all synthesis endpoints and ensures fair usage for freelancers building web apps without needing enterprise infrastructure.

60 requests per minute

Each active key allows up to 60 synthesis requests within a rolling one-minute window. If you exceed this threshold, subsequent requests will receive a rate limit error until the window resets.

Initial limit

New accounts start with a lower limit of 10 requests per minute. This ensures stability while you test the API during your free trial period.

Limit increases

Once you make your first top-up, your rate limit automatically increases to the full 60 requests per minute within minutes. This change is immediate and applies to your primary key.

OpenAI SDK Integration

Sound wave illustration for: OpenAI SDK Integration

The Spindragons TTS API mirrors the OpenAI speech endpoint structure, allowing you to use the official OpenAI JavaScript SDK with minimal configuration. By simply updating the baseURL in your client instance, existing code patterns for API communication remain valid without needing custom fetch wrappers or new abstraction layers.

This compatibility ensures that standard headers, authentication flows, and response parsing logic work out of the box. You can continue using familiar SDK methods while directing requests to https://api.spindragons.info/v1, making the transition from other TTS providers or prototyping phases seamless for freelance developers.

Base URL change

To integrate the Spindragons API, initialize your OpenAI SDK client with a custom baseURL pointing to https://api.spindragons.info/v1. Ensure your apiKey is set to your Spindragons key prefixed with tts-. This single configuration change redirects all subsequent API calls to our infrastructure while maintaining the expected request and response shapes.

  • Set baseURL to https://api.spindragons.info/v1
  • Use your Spindragons key starting with tts-

SDK compatibility

The API supports standard parameters like model, input, voice, response_format, and speed. Since the endpoint mirrors the OpenAI speech API, you can use the same method signatures. However, note that we do not support streaming responses or SSML, so ensure your SDK client handles full file downloads rather than partial audio chunks.

  • Supports tts-1 and tts-1-hd models
  • Compatible with standard JSON body structures
  • No streaming or SSML support in SDK

Code example

Here is how you generate audio using the OpenAI SDK with the Spindragons base URL. The example demonstrates a basic request for a short text phrase, returning a blob that you can save or play directly in your web application.

Curl Example

Sound wave illustration for: Curl Example

Use curl to test the API directly from your terminal. This method requires no external libraries, making it ideal for quick validation of your integration logic before embedding it into your JavaScript application.

The command sends a POST request to the speech endpoint with your authentication token and the desired parameters in the JSON body.

Basic request

Execute the following command, replacing YOUR_API_KEY with your actual key from the dashboard.

curl -X POST https://api.spindragons.info/v1/audio/speech \\ -H "Authorization: Bearer YOUR_API_KEY" \\ -H "Content-Type: application/json" \\ -d '{"model": "tts-1", "input": "Hello world", "voice": "nova", "response_format": "mp3"}' > output.mp3

Headers

Always include the Authorization header with the Bearer prefix. The Content-Type must be set to application/json to ensure the server correctly parses the request body.

Body structure

The JSON body requires model, input, voice, and response_format. Optional fields like speed and language can be added. The input text is limited to 4096 characters.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Requests are processed sequentially, returning audio files directly in the response.

Avatar of the voice aria
ariafemale
Avatar of the voice nova
novafemale
Avatar of the voice luna
lunafemale
Avatar of the voice sage
sagefemale
Avatar of the voice felix
felixmale
Avatar of the voice milo
milomale
Avatar of the voice atlas
atlasmale
Avatar of the voice orion
orionmale

23 languages

Any voice speaks any of these languages.

Sources and further reading

  1. Wikipedia
  2. LibriVox public-domain audiobooks
  3. ISO 639 language codes
  4. LibriTTS-R corpus (OpenSLR 141)
  5. openai-python on GitHub
  6. FFmpeg documentation
  7. LibriTTS-R paper (arXiv 2305.18802)
  8. Creative Commons Attribution 4.0
  9. W3C WAI: making audio and video accessible
  10. OpenAI API reference: create speech
  11. Python documentation
  12. IETF RFC 7845: Ogg Opus

More on this site