> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elbic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Generate Speech API

> REST reference for POST /v1/tts/generate: send text in one request and receive streamed PCM audio, with every request body field, the response and errors.

Generate audio from text. The response streams raw audio bytes as they are
produced.

```http
POST /v1/tts/generate
```

<RequestExample>

```bash cURL
curl -X POST "https://api.elbic.com/v1/tts/generate" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json; charset=utf-8" \
  -d '{
    "text": "Hello, this is a quick test of the speech API.",
    "model_id": "kugel-3.5",
    "voice_id": 1071,
    "cfg_scale": 2.0
  }'
```

```python Python
from kugelaudio import KugelAudio

client = KugelAudio(api_key="YOUR_API_KEY")

audio = client.tts.generate(
    text="Hello, this is a quick test of the speech API.",
    model_id="kugel-3.5",
    voice_id=1071,
    cfg_scale=2.0,
)

audio.save("output.wav")
```

```typescript JavaScript
import { KugelAudio } from 'kugelaudio';

const client = new KugelAudio({ apiKey: 'YOUR_API_KEY' });

const audio = await client.tts.generate({
  text: 'Hello, this is a quick test of the speech API.',
  modelId: 'kugel-3.5',
  voiceId: 1071,
  cfgScale: 2.0,
});
```

</RequestExample>

<ResponseExample>
  <AudioSample
    title="Audio"
    src="/images/audio/generate-example.mp3"
    voice="Samantha Ferris"
    voiceId={1071}
    language="English"
    model="kugel-3.5"
  />
</ResponseExample>

## Request Body

This is the canonical parameter reference for TTS generation. The WebSocket
endpoints accept the same fields (plus their own session controls, see
[Stream Input](/api-reference/tts/stream-input#config-message)).

<ParamField body="text" type="string" required>
  The text to convert to speech. It must contain at least 2 characters after
  trimming whitespace and is limited to 10,000 characters. Text with nothing
  to speak, such as `"!!"`, is refused with `400` and
  `"error": "text contains nothing to speak"`. Supports inline
  [`<break>`](/prompting/breaks), [`<spell>`](/prompting/spell), and
  [`<prosody rate>`](/prompting/speed#per-span-speed-with-prosody-rate) tags.
  Other SSML has no stable stripping or interpretation contract; remove it
  before sending text (see [Prompting](/prompting/overview#unsupported-tags)).
  Shorter text or text over 10,000 characters returns `400 VALIDATION_ERROR`;
  text over the model's or your plan's per-request limit returns
  `413 VALIDATION_ERROR`. Streaming chunks on the WebSocket endpoints are exempt
  from the 2-character minimum.
</ParamField>

<ParamField body="model_id" type="string" default="kugel-3.5">
  The model to use: `kugel-3.5` (the default, our newest model) or `kugel-3`; see [Models](/models) to choose. The legacy IDs listed on [Models](/models#legacy-model-ids) remain accepted for backwards compatibility. The legacy request field `model` is also accepted as an alias when `model_id` is omitted; do not send both. Unknown IDs return `400 VALIDATION_ERROR`. Accepted model IDs are billed and shown in Dashboard usage as requested, even when they route through the current production model.
</ParamField>

<ParamField body="voice_id" type="integer | string" required>
  The numeric voice ID or the voice handle. Required: there is no default voice. A request without a
  `voice_id` is rejected with `400 MISSING_VOICE_ID`; a `voice_id` that doesn't
  exist (or isn't visible to your API key) returns `404 NOT_FOUND`.
</ParamField>

<ParamField body="cfg_scale" type="number" default="2.0">
  Classifier-free guidance scale. Range: 1.2-2.5 (inclusive); values outside this range are clamped into it. Higher values = more expressive.
</ParamField>

<ParamField body="temperature" type="number">
  Sampling variance (0.0 to 1.0). `0`, the default, always takes the model's most
  likely pacing decision; higher values sample it for more variation between
  takes. See [temperature guidance](#temperature-guidance). Values outside the
  range return `400 VALIDATION_ERROR`. When omitted, uses the engine default,
  consistently with the streaming endpoints.
</ParamField>

<ParamField body="max_new_tokens" type="integer" default="2048">
  Maximum tokens to generate. Range: 1-2048. Limits output length. Values
  outside the range return `400 VALIDATION_ERROR`.
</ParamField>

<ParamField body="sample_rate" type="integer" default="24000">
  Output sample rate in Hz. Options: 8000, 16000, 22050, 24000, 44100.

  Audio is generated natively at 24kHz. Other rates use server-side resampling.
  Any other value returns `400 VALIDATION_ERROR`.
</ParamField>

<ParamField body="output_format" type="string">
  Combined codec + rate token (e.g. `ulaw_8000`) for non-PCM output such as
  G.711 telephony codecs. Opt-in; when set it is authoritative and must not
  contradict an explicitly non-default `sample_rate`. The wire-default
  `sample_rate: 24000` is ignored when resolving the token. See
  [Audio formats](/api-reference/tts/audio-formats).
</ParamField>

<ParamField body="normalize" type="boolean" default="true">
  Enable text normalization (converts numbers, dates, etc. to spoken words).

  Set `language` when you know it; without it each sentence is normalized in the language it is written in ([Text normalization](/features/text-processing)).
</ParamField>

<ParamField body="language" type="string">
  ISO 639-1 language code for text normalization (e.g., 'de', 'en', 'fr').

  Supported: de, en, fr, es, it, pt, nl, pl, sv, da, no, fi, cs, hu, ro, el, uk, bg, tr, vi, ar, hi, zh, ja, ko, sk, sl, hr, sr, ru, he, fa, ur, bn, ta, yue, th, id, ms

  If not provided, the server recognizes each sentence's language from its words, and uses the voice's primary language (English if it has none) when a sentence gives no clear sign ([Text normalization](/features/text-processing)).
  Other values return `400 VALIDATION_ERROR`.
</ParamField>

<ParamField body="word_timestamps" type="boolean" default="false">
  **WebSocket endpoints only.** Enable word-level timestamp alignment. See
  [Word timestamps](/streaming/word-timestamps). Not accepted by this REST
  endpoint: requests are strictly validated, so sending it here returns
  `400 Bad Request`. Use a WebSocket endpoint or an SDK instead.
</ParamField>

<ParamField body="speed" type="number" default="1.0">
  Playback speed multiplier. Range: `0.8` (20% slower) to `1.2` (20% faster).

  Uses pitch-preserving time-stretching (WSOLA) so the voice pitch stays natural at any speed.
  Applies to the whole request; wrap text in `<prosody rate="slow|medium|fast|0.8-1.2">` to override
  the rate for a span (see [Speed](/prompting/speed#per-span-speed-with-prosody-rate)).
  Values outside the range return `400 VALIDATION_ERROR`; unlike `cfg_scale`,
  `speed` is not clamped.
</ParamField>

<ParamField body="project_id" type="integer">
  Project whose custom dictionaries should be loaded. Optional for a project
  API key: when omitted, the key's own project is used, so a key issued per end
  customer (see [Projects](/api-reference/endpoints/projects)) applies that
  customer's dictionaries without naming the project. A caller without a
  project that omits it generates without project dictionaries. When you name a
  project, the API verifies that the caller can access it if `dictionary_ids`
  is non-empty. A bare inaccessible `project_id` currently falls back to
  generation without a dictionary; an explicit selection fails with
  `403 UNAUTHORIZED`.
</ParamField>

<ParamField body="dictionary_ids" type="integer[]">
  Per-request [dictionary](/features/dictionaries) selection.

  - **Omitted**: all active dictionaries of the request's project (`project_id`, or the API key's own project when `project_id` is omitted) apply, filtered by language; a caller without a project loads none.
  - **`[]`**: no dictionary applies to this request.
  - **`[7, 9]`**: exactly those dictionaries apply, including inactive ones, bypassing the language filter.

  A non-empty list needs a project: `project_id`, or the API key's own
  project; a caller without either gets a `400`. IDs must belong to that
  project; unknown IDs return a `400` before generation starts. Maximum 50 IDs.
</ParamField>

### Temperature guidance

`temperature` controls how the model decides where speech segments start and end,
which shapes pacing and where pauses and sentence ends fall. At `0`, and when the
field is omitted, the model always takes its most likely decision. Above `0` those
decisions are sampled, more freely as the value rises, so regenerating the same
text varies more between takes.

The effect is subtle. Two renders of the same text differ at every temperature,
because the acoustic sampler is randomized; `temperature` adds to that variation
rather than switching it on. In our measurements on long German and English
paragraphs and on number-heavy text, every value from `0` to `1` kept content
accuracy, voice similarity and audio quality at the level of `0`.

| Use case | Suggested value |
|---|---|
| IVR prompts, compliance reads, numbers and IDs | omit, or `0.0` |
| General voiceover, conversational UX | `0.0` to `0.5` |
| Narration where takes should differ more | `0.5` to `1.0` |

Explicit values override the default; a client preset that sends a value is an
explicit override.

## Spell Tags

Wrap text in `<spell>` to read it letter by letter (emails, codes, acronyms).
Spell content bypasses normalization. See [Spell](/prompting/spell).

## Response

Returns the requested raw encoding as a streaming binary response. The default
is PCM16 (`audio/pcm`); G.711 output uses `audio/basic`. For encoding details
and the watermark, see
[Audio formats](/api-reference/tts/audio-formats).

**Response Headers:**

| Header | Value | Description |
|--------|-------|-------------|
| `Content-Type` | `audio/pcm` | `audio/pcm` for PCM16; `audio/basic` for G.711 |
| `X-Sample-Rate` | `24000` | Resolved output sample rate (shown: default) |
| `X-Audio-Format` | `pcm_s16le` | Resolved encoding: `pcm_s16le`, `mulaw`, or `alaw` (shown: default) |
| `X-KugelAudio-AI-Generated` | `true` | AI-generated audio disclosure (see [Audio formats](/api-reference/tts/audio-formats#ai-generated-audio-marking)) |

With the default format, the response body is raw **PCM 16-bit signed
little-endian** audio data streamed as binary chunks.

The response example on this page plays the audio that the example request
returns, saved as MP3 so your browser can play it.

## Example

<Warning>
  Encode JSON as UTF-8. For predictable normalization of short or ambiguous
  text, set `language` explicitly. Unicode NFC normalization can also make
  equivalent composed and decomposed input consistent before it reaches the
  API.
</Warning>

## Errors

See [Error Codes](/api-reference/errors) for the full TTS error lookup table,
including HTTP status codes, WebSocket close codes, and rate-limit behavior.

## Related endpoints

<CardGroup cols={2}>
  <Card title="Stream Speech" icon="wave-square" href="/api-reference/tts/stream">
    Same request, audio chunks streamed over a WebSocket
  </Card>
  <Card title="Stream Input" icon="keyboard" href="/api-reference/tts/stream-input">
    Token-by-token text input for LLM agents
  </Card>
</CardGroup>
