# Transcribe audio

`POST https://my.neuronai.uz/api/v1/stt/transcribe`

API reference › Speech to text

Transcribes an audio file into text, with timestamped segments.

Set `language` to `auto` to have it detected. Billed per second of audio, for its actual length.

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

**Pricing:** per second: Standard 1 credits.

## Headers

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | No | Makes a retry safe: the same key again returns the original transcription instead of transcribing and charging again. At most 191 characters, scoped to your organization and kept indefinitely, so reuse a key only for the same file. |

## Request body (`multipart/form-data`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `file` | string | Yes | The audio: MP3, WAV, OGG, FLAC, M4A or WebM, at most 25 MB. |
| `language` | string | Yes | The spoken language, or `auto` to have it detected. One of `auto`, `uz`, `kaa`, `ru`, `en`, `kk`, `tk`, `tg`, `tr`, `az`, `ja`, `de` and 1 more. |

## Response (200, `application/json`)

The transcription under `data`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object | Yes |  |
| `data.text` | string | Yes |  |
| `data.language` | string | Yes |  |
| `data.duration_seconds` | number | Yes |  |
| `data.segments` | object[] | Yes | The text in timed pieces, in order: where each starts and ends in the audio, in seconds, and what was said. |
| `data.segments[].start` | number | Yes |  |
| `data.segments[].end` | number | Yes |  |
| `data.segments[].text` | string | Yes |  |
| `data.cost` | number | Yes |  |
| `data.balance` | number | Yes |  |
| `request_id` | string | Yes |  |

```json
{
  "data": {
    "text": "Assalomu alaykum!",
    "language": "uz",
    "duration_seconds": 3.2,
    "segments": [
      {
        "start": 0,
        "end": 3.2,
        "text": "Assalomu alaykum!"
      }
    ],
    "cost": 12.6,
    "balance": 987.4
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

### Headers

| 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. |

## Errors

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 this endpoint needs (`insufficient_permissions`), or the client IP is not in its allowlist (`ip_not_allowed`). |
| 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 | A rate or concurrency limit was reached (`rate_limit_exceeded`, `concurrency_limit_exceeded`). Retry after `Retry-After` seconds. |
| 500 | Transcription failed: `transcription_failed`. Nothing is charged. Anything else that fails unexpectedly: `server_error`. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
curl -X POST "https://my.neuronai.uz/api/v1/stt/transcribe" \
  -H "Authorization: Bearer <your-api-key>" \
  -F "file=@/path/to/recording.mp3" \
  -F "language=uz"
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";
import {readFile} from "node:fs/promises";

const client = new NeuronAI();

const transcription = await client.stt.transcribe({
    file: {data: await readFile("recording.mp3"), filename: "recording.mp3"},
    language: "uz",
});

console.log(transcription.text);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

transcription = client.stt.transcribe(file="recording.mp3", language="uz")

print(transcription.text)
```

### PHP SDK

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

$transcription = $client->stt->transcribe([
    'file' => 'recording.mp3',
    'language' => 'uz',
]);

echo $transcription->text, PHP_EOL;
```

### JavaScript

```javascript
const form = new FormData();
form.append('file', audioFile);  // File or Blob
form.append('language', 'uz');

const response = await fetch('https://my.neuronai.uz/api/v1/stt/transcribe', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <your-api-key>' },
    body: form,
});

const { data } = await response.json();
console.log(data.text);
```

### Python

```python
import requests

with open("recording.mp3", "rb") as audio:
    response = requests.post(
        "https://my.neuronai.uz/api/v1/stt/transcribe",
        headers={"Authorization": "Bearer <your-api-key>"},
        data={"language": "uz"},
        files={"file": audio},
    )

response.raise_for_status()
transcript = response.json()["data"]["text"]
```

### PHP

```php
$ch = curl_init('https://my.neuronai.uz/api/v1/stt/transcribe');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer <your-api-key>'],
    CURLOPT_POSTFIELDS => [
        'language' => 'uz',
        'file' => new CURLFile('/path/to/recording.mp3'),
    ],
]);

$response = curl_exec($ch);
curl_close($ch);

$transcript = json_decode($response, true)['data']['text'];
```

---

Source: https://docs.neuronai.uz/api/reference/speech-to-text/create-transcription
