# Synthesize speech from text

`POST /v1/audio/speech`

Converts text to speech. Returns audio binary. Available models: kosmik/tts-kokoro-quality, kosmik/tts-piper-fast

## Authentication

Send `Authorization: Bearer $KOSCOMPUTE_API_KEY`.

## Request

Content type: `application/json`

| Field | Type | Required | Description |
|---|---|---:|---|
| `model` | string | Yes | See the endpoint guide for behavior and model support. |
| `input` | string | Yes | Text to synthesize |
| `voice` | string | No | Voice identifier |
| `response_format` | string | No | Values: `wav`, `mp3`, `flac`, `opus`, `pcm`. |
| `speed` | number | No | See the endpoint guide for behavior and model support. |

## Examples

### cURL

```bash
curl https://api.koscompute.com/v1/audio/speech \
  -H "Authorization: Bearer $KOSCOMPUTE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"kosmik/tts-kokoro-quality","input":"Synthetic example.","response_format":"wav"}'
```

### Python

```python
import os
import requests

response = requests.post(
    "https://api.koscompute.com/v1/audio/speech",
    headers={"Authorization": f"Bearer {os.environ['KOSCOMPUTE_API_KEY']}"},
    json={
  "model": "kosmik/tts-kokoro-quality",
  "input": "Synthetic example.",
  "response_format": "wav"
},
)
print(response.json())
```

### JavaScript

```javascript
const response = await fetch("https://api.koscompute.com/v1/audio/speech", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOSCOMPUTE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({"model":"kosmik/tts-kokoro-quality","input":"Synthetic example.","response_format":"wav"}),
});
console.log(await response.json());
```

## Responses

| Status | Meaning |
|---:|---|
| `200` | Audio binary response |
| `400` | Bad request — invalid parameters or payload |
| `401` | Invalid or missing API key |
| `403` | Model not allowed for this API key |
| `404` | Public model not found |
| `413` | Request body exceeds the limit |
| `429` | Rate limit or admission capacity is full. The message states when to retry; vision saturation also reports active/total vision concurrency. |
| `502` | Invalid or failed upstream response |
| `503` | No healthy route |
| `504` | Backend generation timeout |
| `500` | Internal server error |

## Next steps

Use the endpoint guide for complete workflows, model capability notes, streaming behavior, and retry advice.
