> ## Documentation Index
> Fetch the complete documentation index at: https://assemblyai.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Migration guide: Gladia to AssemblyAI

This guide walks through the process of migrating from Gladia to AssemblyAI for transcribing pre-recorded audio.

## Get started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up (`https://www.assemblyai.com/dashboard/signup?utm_source=docs_md&utm_medium=ai_agent&utm_campaign=agent_docs`) for a free account and get your API key from your dashboard (`https://www.assemblyai.com/dashboard/signup?utm_source=docs_md&utm_medium=ai_agent&utm_campaign=agent_docs`).
If you'd prefer to use one of our official SDKs, check our [documentation for the full list of available SDKs](https://assemblyai.com/docs/pre-recorded-audio/guides/do-more-with-sdk.md).

> [!NOTE]
>
> The [Gladia
> documentation](https://docs.gladia.io/chapters/pre-recorded-stt/getting-started)
> uses cURL commands to demonstrate API usage. In this guide, we will use Python
> code snippets to illustrate the same functionality across both APIs. If you
> prefer to use cURL, you can find the equivalent commands in the [AssemblyAI
> API Reference](https://assemblyai.com/docs/pre-recorded-audio/api-reference/transcripts/submit.md).

## Side-by-side code comparison

Below is a side-by-side comparison of a basic snippet to transcribe pre-recorded audio with Gladia and AssemblyAI:

> [tab] Gladia
>
> ```python expandable theme={null}
> import requests
> import time
>
> base_url = "https://api.gladia.io"
>
> headers = {
>     "x-gladia-key": "<YOUR_API_KEY>"
> }
>
> with open("./my-audio.mp3", "rb") as f:
>     files = {"audio": ("my-audio.mp3", f, "audio/mp3")}
>     response = requests.post(base_url + "/v2/upload",
>                             headers=headers,
>                             files=files)
>
> upload_url = response.json()["audio_url"]
>
> data = {
>     "audio_url": upload_url # You can also use a URL to an audio or video file on the web.
> }
>
> url = base_url + "/v2/pre-recorded"
> response = requests.post(url, json=data, headers=headers)
>
> transcript_id = response.json()['id'] # You can also use response.json()['result_url'] to get the polling_endpoint directly.
> polling_endpoint = url + "/" + transcript_id
>
> while True:
>     transcript = requests.get(polling_endpoint, headers=headers).json()
>
>     if transcript['status'] == 'done':
>         print(f"Full Transcript: {transcript['result']['transcription']['full_transcript']}")
>         break
>
>     elif transcript['status'] == 'error':
>         raise RuntimeError(f"Transcription failed: {transcript['error_code']}")
>
>     else:
>         time.sleep(3)
> ```

> [tab] AssemblyAI
>
> ```python expandable theme={null}
> import requests
> import time
>
> base_url = "https://api.assemblyai.com"
>
> headers = {
>     "authorization": "<YOUR_API_KEY>"
> }
>
> with open("./my-audio.mp3", "rb") as f:
>   response = requests.post(base_url + "/v2/upload",
>                           headers=headers,
>                           data=f)
>
> upload_url = response.json()["upload_url"]
>
> data = {
>     "audio_url": upload_url, # You can also use a URL to an audio or video file on the web
>     "speech_models": ["assemblyai-stt-3-7", "universal-2"],
>     "language_detection": True,
> }
>
> url = base_url + "/v2/transcript"
> response = requests.post(url, json=data, headers=headers)
>
> transcript_id = response.json()['id']
> polling_endpoint = url + "/" + transcript_id
>
> while True:
>     transcript = requests.get(polling_endpoint, headers=headers).json()
>
>     if transcript['status'] == 'completed':
>         print(f"Full Transcript: {transcript['text']}")
>         break
>
>     elif transcript['status'] == 'error':
>         raise RuntimeError(f"Transcription failed: {transcript['error']}")
>
>     else:
>         time.sleep(3)
> ```

## Installation and authentication

> [tab] Gladia
>
> ```python theme={null}
> import requests
> import time
>
> base_url = "https://api.gladia.io"
>
> headers = {
>     "x-gladia-key": "<YOUR_API_KEY>"
> }
> ```

> [tab] AssemblyAI
>
> ```python theme={null}
> import requests
> import time
>
> base_url = "https://api.assemblyai.com"
>
> headers = {
>     "authorization": "<YOUR_API_KEY>"
> }
> ```

When migrating from Gladia to AssemblyAI, you'll first need to handle authentication:

Get your API key from your AssemblyAI dashboard (`https://www.assemblyai.com/dashboard/signup?utm_source=docs_md&utm_medium=ai_agent&utm_campaign=agent_docs`).

Things to know:

* Store your API key securely in an environment variable.
* We support the ability to create [multiple API keys and projects](https://assemblyai.com/docs/account-management.md) to help you track and manage seperate environments.

> [!NOTE]
>
> Gladia uses the `x-gladia-key` HTTP header for authentication, while
> AssemblyAI uses the `authorization` header.

## Audio file sources

You can provide either a locally stored audio file or a publicly accessible URL.

> [tab] Gladia
>
> ```python theme={null}
> # Local Files
> with open("./my-audio.mp3", "rb") as f:
>     files = {"audio": ("my-audio.mp3", f, "audio/mp3")}
>     response = requests.post(base_url + "/v2/upload",
>                             headers=headers,
>                             files=files)
>
> upload_url = response.json()["audio_url"]
>
> data = {
>     "audio_url": upload_url
> }
>
> #Public URLs
> audio_file = "https://assembly.ai/sports_injuries.mp3"
>
> data = {
>     "audio_url": audio_file
> }
> ```

> [tab] AssemblyAI
>
> ```python expandable theme={null}
> # Local Files
> with open("./my-audio.mp3", "rb") as f:
>   response = requests.post(base_url + "/v2/upload",
>                           headers=headers,
>                           data=f)
>
> upload_url = response.json()["upload_url"]
>
> data = {
>     "audio_url": upload_url,
>     "speech_models": ["assemblyai-stt-3-7", "universal-2"],
>     "language_detection": True,
> }
>
> # Public URLs
> audio_file = "https://assembly.ai/sports_injuries.mp3"
>
> data = {
>     "audio_url": audio_file,
>     "speech_models": ["assemblyai-stt-3-7", "universal-2"],
>     "language_detection": True,
> }
> ```

## Basic transcription and polling the transcription status

> [tab] Gladia
>
> **Step 1**
>
> Make a `POST` request to the [/v2/pre-recorded](https://docs.gladia.io/docs/api-reference/v2/pre-recorded/init) endpoint.
>
> ```python theme={null}
> url = base_url + "/v2/pre-recorded"
> response = requests.post(url, json=data, headers=headers)
> ```
>
> **Step 2**
>
> Every few seconds, make a `GET` request to the [/v2/pre-recorded/:transcript\_id](https://docs.gladia.io/docs/api-reference/v2/pre-recorded/get) endpoint until the transcription status is `'done'`.
>
> ```python theme={null}
> transcript_id = response.json()['id'] # You can also use response.json()['result_url'] to get the polling_endpoint directly.
> polling_endpoint = url + "/" + transcript_id
>
> while True:
>     transcript = requests.get(polling_endpoint, headers=headers).json()
>
>     if transcript['status'] == 'done':
>         print(f"Full Transcript: {transcript['result']['transcription']['full_transcript']}")
>         break
>
>     elif transcript['status'] == 'error':
>         raise RuntimeError(f"Transcription failed: {transcript['error_code']}")
>
>     else:
>         time.sleep(3)
> ```

> [tab] AssemblyAI
>
> **Step 1**
>
> Make a `POST` request to the [/v2/transcript](https://assemblyai.com/docs/api-reference/transcripts/submit.md) endpoint.
>
> ```python theme={null}
> url = base_url + "/v2/transcript"
> response = requests.post(url, json=data, headers=headers)
> ```
>
> **Step 2**
>
> Every few seconds, make a `GET` request to the [/v2/transcript/:transcript\_id](https://assemblyai.com/docs/api-reference/transcripts/get.md) endpoint until the transcription status is `'completed'`.
>
> ```python theme={null}
> transcript_id = response.json()['id']
> polling_endpoint = url + "/" + transcript_id
>
> while True:
>     transcript = requests.get(polling_endpoint, headers=headers).json()
>
>     if transcript['status'] == 'completed':
>         print(f"Full Transcript: {transcript['text']}")
>         break
>
>     elif transcript['status'] == 'error':
>         raise RuntimeError(f"Transcription failed: {transcript['error']}")
>
>     else:
>         time.sleep(3)
> ```

> [!NOTE]
>
> **Transcription status**
>
> Note that our APIs possible values for transcription status are `queued`, `processing`, `completed`, and `error`. Check out the [AssemblyAI API Reference](https://assemblyai.com/docs/api-reference/transcripts/get.md#response.body.status) for the full list of possible transcription status values.
> If you'd rather not poll the API, you can use our [SDKs](https://assemblyai.com/docs/pre-recorded-audio/guides/do-more-with-sdk.md) which handle polling internally. Alternatively, you can also use [webhooks](https://assemblyai.com/docs/pre-recorded-audio/webhooks.md) to get notified when your transcript is complete.

Here are helpful things to know when migrating your audio input handling:

* Both AssemblyAI and Gladia allow you the option of uploading a local file or specifying a publicly accessible URL.
* There's no need to specify the audio format to AssemblyAI - it's auto-detected. AssemblyAI accepts almost every audio/video file type: [here is a full list of all our supported file types](https://assemblyai.com/docs/faq/what-audio-and-video-file-types-are-supported-by-your-api.md)
* For self-hosted or pre-signed URLs (i.e. S3), [see our example in this cookbook](https://assemblyai.com/docs/pre-recorded-audio/guides/transcribe_from_s3.md).

## Adding features

> [tab] Gladia
>
> ```python theme={null}
> data = {
>     "audio_url": upload_url,
>     "diarization": True,                # Speaker diarization
>     "chapterization": True,             # Auto chapter detection
>     "named_entity_recognition": True    # Named entity detection
> }
>
> # Access speaker labels
> for utterance in transcript['result']['transcription']['utterances']:
>     print(f"Speaker {utterance['speaker']}: {utterance['text']}")
>
> # Access auto chapters
> for chapter in transcript['result']['chapterization']['results']:
>     print(f"{chapter['start']} - {chapter['end']}: {chapter['headline']}")
>
> # Access named entities
> for entity in transcript['result']['named_entity_recognition']['results']:
>     print(entity['text'])
>     print(entity['entity_type'])
>     print(f"Timestamp: {entity['start']} - {entity['end']}\n")
> ```

> [tab] AssemblyAI
>
> ```python expandable theme={null}
> data = {
>     "audio_url": upload_url,
>     "speech_models": ["assemblyai-stt-3-7", "universal-2"],
>     "language_detection": True,
>     "speaker_labels": True,     # Speaker diarization
>     "auto_chapters": True,      # Auto chapter detection
>     "entity_detection": True    # Named entity detection
> }
>
> # Access speaker labels
> for utterance in transcript['utterances']:
>     print(f"Speaker {utterance['speaker']}: {utterance['text']}")
>
> # Access auto chapters
> for chapter in transcript['chapters']:
>     print(f"{chapter['start']} - {chapter['end']}: {chapter['headline']}")
>
> # Access named entities
> for entity in transcript['entities']:
>     print(entity['text'])
>     print(entity['entity_type'])
>     print(f"Timestamp: {entity['start']} - {entity['end']}\n")
> ```

Key differences:

* Make sure to note any differences in parameters or response structure. If using [Speaker Diarization](https://assemblyai.com/docs/pre-recorded-audio/label-speakers.md), for example:
  * Parameters: AssemblyAI uses `speaker_labels`, while Gladia uses `diarization`.
  * Response: AssemblyAI uses `transcript.utterances`, while Gladia uses `transcript.result.transcription.utterances`.
* Make sure to review each API reference for the full list of parameters and response objects.
  * [AssemblyAI API Reference](https://assemblyai.com/docs/api-reference/transcripts/submit.md)
  * [Gladia API Reference](https://docs.gladia.io/docs/api-reference/v2/pre-recorded/init)
