# OpenAI-compatible transcription

Source: [OpenAI-compatible transcription](<https://docs.gptunnel.ru/en/transcription/openai-compat/>)

<a id="_top"></a>
> **Note: Deprecated models**
>
> If the provider retires the model, the API uses its designated replacement and charges the originally requested model’s rate. Check the response headers to detect the replacement. The synchronous response body has no `warnings` field. If there is no replacement, the API returns `410`. See [Deprecated models](<https://docs.gptunnel.ru/en/getting-started/deprecated-models/>).

<a id="synchronous-file-transcription"></a>
## Synchronous file transcription

`POST https://gptunnel.ru/v1/audio/transcriptions`

This OpenAI-compatible endpoint accepts an audio file as `multipart/form-data` and returns the transcript in the same request. You can use the official OpenAI SDK with the GPTunneL `base_url` and API key.

Use `multipart/form-data` to upload a file. An `application/json` request instead [creates an asynchronous task from a URL](<https://docs.gptunnel.ru/en/transcription/create/>).

### Request headers

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `Authorization` | `string` | Required | API key. Support the format "Bearer YOUR\_API\_KEY" (as in OpenAI SDK) |
| `Content-Type` | `string` | Required | multipart/form-data |

### Form fields

| Parameter | Type | Required? | Description |
| --- | --- | --- | --- |
| `file` | `file` | Required | Audio file up to 25 MB, lasting from 1 second to 2 hours |
| `model` | `string` | Required | whisper-1 |
| `language` | `string` | Optional | Language code (e.g. "ru", "en"). If not specified, language is automatically defined |
| `response_format` | `string` | Optional | json ( default) or verbose\_json |
| `prompt` | `string` | Optional | A hint with a style or dictionary of terms |
| `temperature` | `number` | Optional | 0 to 1 |

> **Caution: The file should not exceed 25 MB**
>
> The limit on the size of a file is independent of its duration.
>
>
>
> Files over 25 MB return `400` with code `file_too_large`. For longer recordings, use the [asynchronous mode](<https://docs.gptunnel.ru/en/transcription/create/>) with a file URL.

<a id="supported-formats"></a>
### Supported formats

Entry file formats: `flac`, `m4a`, `mp3`, `mp4`, `mpeg`, `mpga`, `oga`, `ogg`, `wav`, `webm`.

The API detects the format from the contents of the file. A filename extension is optional. Unsupported containers such as `aiff` or `wma` return `unsupported_format` before contacting the provider, and the account is not charged.

Containers `aiff`, `wma` and `amr` available in [asynchronous mode](<https://docs.gptunnel.ru/en/transcription/about/#supported-formats>).

<a id="example-request"></a>
### Example request

Download the [sample WAV file](<https://docs.gptunnel.ru/examples/blue-sky.wav>) and set the `GPTUNNEL_API_KEY` environment variable. The examples read `blue-sky.wav` from the current directory. For Python or Node.js, install the `openai` package for that language.

<a id="tab-panel-0-0"></a>
**Python**

```python
import os

from openai import OpenAI

client = OpenAI(
    api_key=os.environ['GPTUNNEL_API_KEY'],
    base_url='https://gptunnel.ru/v1',
)

with open('blue-sky.wav', 'rb') as audio:
    transcription = client.audio.transcriptions.create(
        model='whisper-1',
        file=audio,
        language='en',
    )

print(transcription.text)
```

<a id="tab-panel-0-1"></a>
**cURL**

```bash
curl --request POST \
  --url https://gptunnel.ru/v1/audio/transcriptions \
  --header "Authorization: Bearer $GPTUNNEL_API_KEY" \
  --form 'file=@blue-sky.wav' \
  --form 'model=whisper-1' \
  --form 'language=en'
```

<a id="tab-panel-0-2"></a>
**JavaScript (Node.js)**

```javascript
import fs from 'fs'
import OpenAI from 'openai'

const client = new OpenAI({
  apiKey: process.env.GPTUNNEL_API_KEY,
  baseURL: 'https://gptunnel.ru/v1',
})

const transcription = await client.audio.transcriptions.create({
  model: 'whisper-1',
  file: fs.createReadStream('blue-sky.wav'),
  language: 'en',
})

console.log(transcription.text)
```

<a id="example-response"></a>
### Example response

The examples show excerpts from the response for the sample WAV file. With `verbose_json`, the API returns timestamped segments along with the full transcript.

<a id="tab-panel-1-0"></a>
**200 json**

```json
{
  "text": "The sky is blue today."
}
```

<a id="tab-panel-1-1"></a>
**200 verbose\_json**

```json
{
  "task": "transcribe",
  "language": "english",
  "duration": 1.8799999952316284,
  "text": "The sky is blue today.",
  "segments": [
    {
      "id": 0,
      "start": 0,
      "end": 2,
      "text": " The sky is blue today."
    }
  ]
}
```

<a id="errors"></a>
### Errors

For `whisper-1`, this endpoint returns HTTP 400 for the `text`, `srt`, and `vtt` response formats. The example below shows the error for `response_format=text`.

```json
{
  "error": {
    "message": "Unsupported response_format \"text\". Only \"json\" and \"verbose_json\" are supported.",
    "type": "invalid_request_error",
    "param": "file",
    "code": "provider_rejected"
  }
}
```

Errors return in OpenAI format:

```json
{
  "error": {
    "message": "Insufficient quota. Your account balance is too low to complete this request.",
    "type": "insufficient_quota",
    "param": null,
    "code": "insufficient_quota"
  }
}
```

| HTTP | `code` | Cause |
| --- | --- | --- |
| 400 | `missing_required_parameter` | Not transferred `file` |
| 400 | `file_too_large` | File More Than 25 MB - Use Asynchronous Mode |
| 400 | `invalid_value` | Unacceptable `model` or other parameter |
| 400 | `invalid_audio` | File failed to decode (damaged or not audio) |
| 400 | `unsupported_format` | Container format not supported |
| 400 | `audio_too_long` | Longer than 2 hours |
| 400 | `audio_too_short` | Duration less than 1 second |
| 400 | `provider_rejected` | The conductor rejected the file or the requested response format |
| 401 | — | Wrong API Key |
| 403 | `model_not_allowed` | The model is not on the API key list |
| 404 | `model_not_found` | Model unknown or not available key |
| 429 | `insufficient_quota` | Insufficient balance funds |
| 429 | `api_key_limit_exceeded` | Exceeded API-key spending limit |
| 500 | `internal_error` | Internal error |

> **Note: When funds are written off**
>
> The funds are written off according to the length of audio **after successful decryption**. The funds are not written off when there is an error of validation, lack of balance or failure of the provider.
