# Create a synthesis job

`POST https://my.neuronai.uz/api/v1/tts/jobs`

Справочник API › Синтез речи

Queues a synthesis and answers at once, so a long text never keeps the connection waiting.

The body is the same as for `POST /v1/tts/synthesize`. Check the job with `GET /v1/tts/jobs/{id}` until it has `succeeded` or `failed`, then download its audio. You are charged only when the job succeeds.

**Authentication:** `Authorization: Bearer <API key>`, a key with `tts:write`.

**Pricing:** per character: Default voice 0.3 credits; Voice clone 0.5 credits.

## Заголовки

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | No | Makes a retry safe: the same key again answers 200 with the job it created, whatever its state, instead of queuing another. At most 191 characters, scoped to your organization, and released 24 hours after the job finishes. |

## Тело запроса (`application/json`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `text` | string | Yes | The text to speak. Emotion tags such as `[laughter]` or `[sigh]` are acted out, not read aloud, and count as one character each. The tags: `[laughter]`, `[sigh]`, `[dissatisfaction-hnn]`, `[confirmation-en]`, `[question-en]`, `[question-ah]`, `[question-oh]`, `[question-ei]`, `[question-yi]`, `[surprise-ah]`, `[surprise-oh]`, `[surprise-wa]`, `[surprise-yo]`. At least 1 character. |
| `voice_id` | string \| null | No | A stock voice or one of your voice clones (`GET /v1/tts/voices`). At most 128 characters. |
| `language` | string \| null | No | The language of the text. One of `uz`, `ru`, `en`, `kk`, `ky`, `tk`, `tg`, `az`, `tr`, `ug`, `tt`, `ba` and 25 more. |
| `quality` | string \| null | No | `fast` for the lowest latency, `standard` (the default) for balance, or `high` for the best fidelity. One of `fast`, `standard`, `high`, `null`. |
| `speed` | number \| null | No | How fast the voice speaks, from 0.5 to 2. 1 is normal. Minimum 0.5. Maximum 2. |

## Ответ (200, `application/json`)

An idempotent replay: the job this `Idempotency-Key` already created.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object | Yes |  |
| `data.id` | string | Yes |  |
| `data.status` | string | Yes | One of `queued`, `running`, `succeeded`, `failed`. |
| `data.created_at` | string | Yes |  |
| `data.started_at` | string \| null | Yes | When a worker started on the job, or `null` while it is queued. |
| `data.finished_at` | string \| null | Yes | When the job succeeded or failed, or `null` until then. |
| `data.character_count` | integer | Yes |  |
| `data.cost` | number \| null | Yes |  |
| `data.balance_after` | number \| null | Yes |  |
| `data.voice_custom` | boolean | Yes |  |
| `data.latency_ms` | number \| null | Yes |  |
| `data.error` | object \| null | Yes | Why the job failed, set only once it has `failed`. `code` is `insufficient_balance`, `voice_unavailable`, `synthesis_failed`, `storage_failed` or `queue_timeout`. |
| `data.error.code` | string | Yes |  |
| `data.error.message` | string | Yes |  |
| `data.audio_url` | string \| null | Yes |  |
| `request_id` | string | Yes |  |

```json
{
  "data": {
    "id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41",
    "status": "queued",
    "created_at": "2026-11-17T09:30:00Z",
    "started_at": "2026-11-17T09:30:00Z",
    "finished_at": "2026-11-17T09:30:00Z",
    "character_count": 42,
    "cost": 12.6,
    "balance_after": 987.4,
    "voice_custom": true,
    "latency_ms": 840,
    "error": {
      "code": "string",
      "message": "string"
    },
    "audio_url": "https://my.neuronai.uz/api/v1/tts/jobs/7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41/audio"
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

### Заголовки

| Header | Type | Description |
| --- | --- | --- |
| `Idempotency-Replayed` | string | `1` when the answer is a replay of an earlier request with the same `Idempotency-Key`. |
| `X-Request-Id` | string | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |
| `X-RateLimit-Limit` | integer | The requests a minute the rate limit on this endpoint allows. Sent once the limit has counted the request, so not when the key itself is refused. |
| `X-RateLimit-Remaining` | integer | How many of them are left this minute. |

## Ошибки

Every error has the same JSON shape:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "The request is malformed or failed validation.",
    "param": null
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

| Status | Meaning |
| --- | --- |
| 400 | The `Idempotency-Key` is over 191 characters: `invalid_request`. |
| 401 | The API key is missing or not recognized (`invalid_api_key`), revoked (`api_key_revoked`), disabled (`api_key_disabled`) or expired (`api_key_expired`). |
| 402 | Not enough balance (`insufficient_balance`), or the charge would pass this key's monthly spend limit (`spend_limit_exceeded`). |
| 403 | The key lacks the permission (`insufficient_permissions`), the IP is not allowed (`ip_not_allowed`), or the voice cannot be used (`voice_unavailable`). |
| 409 | The `Idempotency-Key` was already used with a different body: `idempotency_conflict`. |
| 422 | The request failed validation (`invalid_request`). `error.fields` names each invalid field. |
| 429 | Too many jobs in progress (`too_many_active_jobs`), or the rate limit is used up (`rate_limit_exceeded`). Retry after `Retry-After` seconds. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
# 1. Submit
curl -X POST "https://my.neuronai.uz/api/v1/tts/jobs" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <your-api-key>" \
  -H "Idempotency-Key: my-unique-key-123" \
  -d '{"voice_id": "kamron", "text": "Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.", "language": "uz"}'

# 2. Poll until data.status is "succeeded" or "failed"
curl "https://my.neuronai.uz/api/v1/tts/jobs/<job-id>" -H "Authorization: Bearer <your-api-key>"

# 3. Download
curl "https://my.neuronai.uz/api/v1/tts/jobs/<job-id>/audio" -H "Authorization: Bearer <your-api-key>" --output speech.wav
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";

const client = new NeuronAI();

const job = await client.tts.jobs.create({
    voice_id: "kamron",
    text: "Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.",
    language: "uz",
});

console.log(job.id, job.status);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

job = client.tts.jobs.create(
    voice_id="kamron",
    text="Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.",
    language="uz",
)

print(job.id, job.status)
```

### PHP SDK

```php
$client = new \Naiuz\NeuronAI();

$job = $client->tts->jobs->create([
    'voice_id' => 'kamron',
    'text' => 'Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.',
    'language' => 'uz',
]);

echo $job->id, ' ', $job->status, PHP_EOL;
```

### JavaScript

```javascript
const headers = { 'Authorization': 'Bearer <your-api-key>', 'Content-Type': 'application/json' };

const submitted = await fetch('https://my.neuronai.uz/api/v1/tts/jobs', {
    method: 'POST',
    headers: { ...headers, 'Idempotency-Key': crypto.randomUUID() },
    body: JSON.stringify({ voice_id: 'kamron', text: 'Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.', language: 'uz' }),
}).then((r) => r.json());

let job = submitted.data;
while (job.status === 'queued' || job.status === 'running') {
    await new Promise((resolve) => setTimeout(resolve, 2000));
    job = (await fetch(`https://my.neuronai.uz/api/v1/tts/jobs/${job.id}`, { headers }).then((r) => r.json())).data;
}

if (job.status === 'failed') throw new Error(job.error.message);

const audio = await fetch(job.audio_url, { headers }).then((r) => r.blob());
```

### Python

```python
import time, uuid, requests

headers = {"Authorization": "Bearer <your-api-key>"}

job = requests.post(
    "https://my.neuronai.uz/api/v1/tts/jobs",
    headers={**headers, "Idempotency-Key": str(uuid.uuid4())},
    json={"voice_id": "kamron", "text": "Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.", "language": "uz"},
).json()["data"]

while job["status"] in ("queued", "running"):
    time.sleep(2)
    job = requests.get(f"https://my.neuronai.uz/api/v1/tts/jobs/{job['id']}", headers=headers).json()["data"]

if job["status"] == "failed":
    raise RuntimeError(job["error"]["message"])

with open("speech.wav", "wb") as f:
    f.write(requests.get(job["audio_url"], headers=headers).content)
```

### PHP

```php
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

$api = Http::withHeaders(['Authorization' => 'Bearer <your-api-key>']);

$job = $api->withHeaders(['Idempotency-Key' => (string) Str::uuid()])
    ->post('https://my.neuronai.uz/api/v1/tts/jobs', ['voice_id' => 'kamron', 'text' => 'Assalomu alaykum! Bu NeuronAI matn-nutq xizmati orqali yaratilgan ovoz.', 'language' => 'uz'])
    ->json('data');

while (in_array($job['status'], ['queued', 'running'], true)) {
    sleep(2);
    $job = $api->get("https://my.neuronai.uz/api/v1/tts/jobs/{$job['id']}")->json('data');
}

if ($job['status'] === 'failed') {
    throw new RuntimeException($job['error']['message']);
}

file_put_contents('speech.wav', $api->get($job['audio_url'])->body());
```

---

Source: https://docs.neuronai.uz/ru/api/reference/text-to-speech/create-tts-job
