> For the complete documentation index, see [llms.txt](https://docs.fastrouter.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.fastrouter.ai/api-reference/audio/text-to-speech.md).

# Text to Speech

## Generate Speech (Text-to-Speech)

> Generates audio from input text using text-to-speech (TTS) models. The response is a JSON object containing base64-encoded audio in the \`audios\` array (not a raw binary stream).\
> \
> Only \`model\` and \`input\` are required. All other parameters are \*\*model-specific\*\* — for example \`sarvam/bulbul:v2\` supports \`target\_language\_code\`, \`speaker\`, \`pitch\`, \`pace\`, \`loudness\`, \`speech\_sample\_rate\`, \`enable\_preprocessing\`, \`output\_audio\_codec\`, \`temperature\`, and \`enable\_cached\_responses\`.\
> \
> \> \*\*Tip:\*\* Supported parameters and their accepted values differ from one model to another. Call \*\*GET /api/v1/models\*\* and inspect each model's \`supported\_parameters\` and \`supported\_params\_details\` to see exactly which fields it accepts and the allowed values, ranges, or enums.

```json
{"openapi":"3.1.0","info":{"title":"FastRouter API Reference","version":"1.0.0"},"tags":[{"name":"Audio","description":"Transcribe, translate, and generate audio using Whisper, ElevenLabs, and other audio models."}],"servers":[{"url":"https://api.fastrouter.ai","description":"Production API"}],"security":[{"bearerAuth":[]}],"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"API Key","description":"FastRouter API Key. Get yours at https://fastrouter.ai\n\nFormat: `Authorization: Bearer YOUR_API_KEY`"}},"responses":{"BadRequestError":{"description":"Bad Request - The request is malformed. This could be due to missing parameters, invalid formats, or routing errors.\n\n**Note:** the 400 body shape is not uniform. Validation errors return the structured object below, but routing/model errors may instead return a plain string: `{ \"error\": \"<message>\" }`. A few endpoints (e.g. some file operations) may return a plain-text body rather than JSON.","content":{"application/json":{"schema":{"oneOf":[{"type":"object","description":"Structured validation error.","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"}}}}},{"type":"object","description":"Plain-string routing/model error.","properties":{"error":{"type":"string"}}}]}}}},"UnauthorizedError":{"description":"Invalid Credentials - Your API key is invalid, missing, or disabled. Check your credentials.\n\nNote: the 401 error body uses `code`, `message`, `param`, and `type` (there is no `status` field), and `type` is `invalid_request_error`.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"param":{"type":"string","nullable":true},"code":{"type":"string"}}}}}}}},"InsufficientCreditsError":{"description":"Insufficient Credits - Your account or API key has run out of credits. Add more credits and retry the request.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}},"RateLimitError":{"description":"Rate Limited - You have exceeded your request limits (TPM/RPM). Slow down or increase your limits.","content":{"application/json":{"schema":{"type":"object","properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string"},"code":{"type":"string"},"status":{"type":"integer"}}}}}}}}}},"paths":{"/api/v1/audio/speech":{"post":{"operationId":"createSpeech","tags":["Audio"],"summary":"Generate Speech (Text-to-Speech)","description":"Generates audio from input text using text-to-speech (TTS) models. The response is a JSON object containing base64-encoded audio in the `audios` array (not a raw binary stream).\n\nOnly `model` and `input` are required. All other parameters are **model-specific** — for example `sarvam/bulbul:v2` supports `target_language_code`, `speaker`, `pitch`, `pace`, `loudness`, `speech_sample_rate`, `enable_preprocessing`, `output_audio_codec`, `temperature`, and `enable_cached_responses`.\n\n> **Tip:** Supported parameters and their accepted values differ from one model to another. Call **GET /api/v1/models** and inspect each model's `supported_parameters` and `supported_params_details` to see exactly which fields it accepts and the allowed values, ranges, or enums.","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["model","input"],"properties":{"model":{"type":"string","description":"TTS model in provider/model format."},"input":{"type":"string","description":"The text to convert to speech."},"target_language_code":{"type":"string","description":"Model-specific (e.g. Sarvam). BCP-47 language code of the output speech (e.g. `en-IN`, `hi-IN`)."},"speaker":{"type":"string","description":"Model-specific (e.g. Sarvam). The speaker voice to use."},"pitch":{"type":"number","description":"Model-specific (e.g. Sarvam). Adjusts the pitch of the generated speech."},"pace":{"type":"number","description":"Model-specific (e.g. Sarvam). Adjusts the speed of the speech (e.g. 0.5x to 2.0x)."},"loudness":{"type":"number","description":"Model-specific (e.g. Sarvam). Adjusts the loudness of the generated speech."},"speech_sample_rate":{"type":"integer","description":"Model-specific (e.g. Sarvam). Output audio sample rate in Hz."},"enable_preprocessing":{"type":"boolean","description":"Model-specific (e.g. Sarvam). Enables text normalization / preprocessing before synthesis."},"output_audio_codec":{"type":"string","description":"Model-specific (e.g. Sarvam). The audio codec/format of the response."},"temperature":{"type":"number","description":"Model-specific. Sampling temperature for generation."},"enable_cached_responses":{"type":"boolean","description":"Model-specific (e.g. Sarvam). Allows returning a cached response for identical requests."}}}}}},"responses":{"200":{"description":"The generated speech. Returns a JSON object containing the base64-encoded audio (not a raw binary stream).","content":{"application/json":{"schema":{"type":"object","properties":{"audios":{"type":"array","description":"Array of base64-encoded audio clips (WAV). Usually one entry.","items":{"type":"string","description":"Base64-encoded WAV audio."}},"model":{"type":"string","description":"The model used to generate the audio."},"provider":{"type":"string","description":"The upstream provider that served the request."},"usage":{"type":"object","description":"Usage and cost information for the request.","properties":{"prompt_tokens":{"type":"integer","description":"Number of input tokens."},"total_tokens":{"type":"integer","description":"Total tokens counted."},"cost":{"type":"number","description":"Cost in USD for this request."},"chat_id":{"type":"string","description":"FastRouter internal identifier for this request."}}}}}}}},"400":{"$ref":"#/components/responses/BadRequestError"},"401":{"$ref":"#/components/responses/UnauthorizedError"},"402":{"$ref":"#/components/responses/InsufficientCreditsError"},"429":{"$ref":"#/components/responses/RateLimitError"},"500":{"description":"Internal Server Error"}}}}}}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.fastrouter.ai/api-reference/audio/text-to-speech.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
