# Transcription

> Turn audio files into text with timestamps or subtitles, send large files efficiently, and read the cost of each transcription.

`POST /audio/transcriptions` turns an audio file into text. It takes the same `multipart/form-data` request as OpenAI's transcription endpoint, so the OpenAI SDKs' `audio.transcriptions.create` works against it. Field by field reference: [POST /audio/transcriptions](https://www.getlykia.com/en/docs/api-reference/audio-transcriptions).

## Transcribe a file

**cURL**

```bash
# Put `file` last: Lykia then streams it to the provider without storing it
curl https://api.getlykia.com/v1/audio/transcriptions \
  -H "Authorization: Bearer $LYKIA_API_KEY" \
  -F model=openai/gpt-4o-mini-transcribe \
  -F language=en \
  -F file=@meeting.mp3
```

**Python**

```python
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.getlykia.com/v1", api_key=os.environ["LYKIA_API_KEY"])

with open("meeting.mp3", "rb") as audio:
    transcript = client.audio.transcriptions.create(
        model="openai/gpt-4o-mini-transcribe",
        file=audio,
        language="en",
    )
print(transcript.text)
print("cost (USD):", transcript.usage.cost)
```

**TypeScript**

```typescript
import { readFile } from "node:fs/promises";

const form = new FormData();
form.append("model", "openai/gpt-4o-mini-transcribe");
form.append("language", "en");
// Put `file` last: Lykia then streams it to the provider without storing it
form.append("file", new Blob([await readFile("meeting.mp3")], { type: "audio/mpeg" }), "meeting.mp3");

const response = await fetch("https://api.getlykia.com/v1/audio/transcriptions", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
  body: form,
});
if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);

const transcript = (await response.json()) as { text: string; usage: { cost: number } };
console.log(transcript.text);
console.log("cost (USD):", transcript.usage.cost);
```

The answer is the provider's result in OpenAI's format. With a JSON format, Lykia adds `cost`, `is_byok` and `cost_details` to its `usage`:

```json
{
    "text": "hello world",
    "usage": {
        "type": "tokens",
        "input_tokens": 20,
        "output_tokens": 5,
        "total_tokens": 25,
        "input_token_details": {
            "audio_tokens": 18,
            "text_tokens": 2
        },
        "cost": 0.00005,
        "is_byok": false,
        "cost_details": {
            "upstream_cost": 0.00005,
            "platform_fee": 0,
            "is_byok": false
        }
    }
}
```

The `X-Lykia-Cost` header carries the cost with every format, including the plain text ones.

## Response formats

`response_format` decides the shape of the answer:

| Value            | Answer                                                                                          |
| ---------------- | ----------------------------------------------------------------------------------------------- |
| `json` (default) | `{ "text": "…", "usage": { … } }`                                                               |
| `verbose_json`   | The text with language, duration and segments (and words with `timestamp_granularities[]=word`) |
| `diarized_json`  | Segments labelled by speaker, for models that tell speakers apart                               |
| `text`           | Plain text                                                                                      |
| `srt`, `vtt`     | Subtitles                                                                                       |

Not every model offers every format: `media.capabilities.transcription` in [`GET /models?kind=transcription`](https://www.getlykia.com/en/docs/api-reference/models) lists a model's `formats`, its `timestampGranularities` and the audio types it reads (`mimes`). An unsupported format returns `400` with `unsupported_input` and `metadata.param: "response_format"`.

Other fields: `language` (the spoken language, which helps accuracy), `prompt` (words or context to expect, for models that take it) and `temperature`.

## Send large files efficiently

Put `file` after the other fields, as the samples do. Lykia then streams the file to the provider as it arrives, without keeping it anywhere. If `file` comes first (the OpenAI SDKs send it first), Lykia keeps it in a private temporary file until the request ends and then deletes it; it is never stored. Fields that come after `file` in streamed requests cannot be applied any more; their names come back in the `X-Lykia-Ignored-Fields` header.

Lykia sets a size limit for transcription files (25 MB by default). A larger file returns `413`. A transcription goes to a single provider: the file is read once, so there is no fallback to another provider.

## Cost

Transcription is priced per second of audio (or per token for models whose provider bills tokens). Before the request runs, Lykia reserves an amount based on the file size; afterwards it charges the duration the provider reports. `usage.cost` and `X-Lykia-Cost` show what was charged.

## Errors

| Code                      | Status | When                                                                                                         |
| ------------------------- | ------ | ------------------------------------------------------------------------------------------------------------ |
| `unsupported_input`       | `400`  | An unsupported `response_format`, timestamp option or audio type. `metadata.param` names the field.          |
| `unsupported_model`       | `400`  | The model does not transcribe audio.                                                                         |
| `platform_sales_disabled` | `403`  | The model's provider is not offered on Lykia credits yet. Add your own key for that provider to the project. |
| `payload_too_large`       | `413`  | The file is larger than Lykia's limit.                                                                       |

See [Errors](https://www.getlykia.com/en/docs/guides/errors) for the error body and the other status codes.
