> ## 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: OpenAI to AssemblyAI

This guide walks through the process of migrating from OpenAI 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.

## Side-By-Side Code Comparison

Below is a side-by-side comparison of a basic snippet to transcribe a **local file** by OpenAI and AssemblyAI:

> [tab] OpenAI
>
> ```python theme={null}
> from openai import OpenAI
>
> api_key = "YOUR_OPENAI_API_KEY"
> client = OpenAI(api_key)
>
> audio_file = open("./example.wav", "rb")
>
> transcript = client.audio.transcriptions.create(
>     model = "whisper-1",
>     file = audio_file
> )
>
> print(transcript.text)
> ```

> [tab] AssemblyAI
>
> ```python theme={null}
> import assemblyai as aai
>
> aai.settings.api_key = "YOUR-API-KEY"
> transcriber = aai.Transcriber()
>
> audio_file = "./example.wav"
>
> config = aai.TranscriptionConfig(
>     speech_models=["assemblyai-stt-3-7", "universal-2"],
>     language_detection=True,
> )
> transcript = transcriber.transcribe(audio_file, config)
>
> if transcript.status == aai.TranscriptStatus.error:
>     print(f"Transcription failed: {transcript.error}")
>     exit(1)
>
> print(transcript.text)
> ```

Here are helpful things to know about our `transcribe` method:

* The SDK handles polling under the hood
* Transcript is directly accessible via `transcript.text`
* English is the default language. We recommend specifying `speech_models=["assemblyai-stt-3-7", "universal-2"]` for the highest accuracy
* We have a [cookbook for error handling common errors](https://assemblyai.com/docs/pre-recorded-audio/guides/common_errors_and_solutions.md) when using our API.

## Installation

> [tab] OpenAI
>
> ```python theme={null}
> from openai import OpenAI
>
> api_key = "YOUR_OPENAI_API_KEY"
> client = OpenAI(api_key)
> ```

> [tab] AssemblyAI
>
> ```python theme={null}
> import assemblyai as aai
>
> aai.settings.api_key = "YOUR-API-KEY"
> transcriber = aai.Transcriber()
> ```

When migrating from OpenAI to AssemblyAI, you'll first need to handle authentication and SDK setup:

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`) \
To follow this guide, install AssemblyAI's Python SDK by typing this code into your terminal: \
`pip install assemblyai`

Things to know:

* Store your API key securely in an environment variable
* API key authentication works the same across all AssemblyAI SDKs

## Audio File Sources

> [tab] OpenAI
>
> ```python theme={null}
> client = OpenAI()
>
> # Local Files
>
> audio_file = open("./example.wav", "rb")
> transcript = client.audio.transcriptions.create(
>     model = "whisper-1",
>     file = audio_file
> )
>
> ```

> [tab] AssemblyAI
>
> ```python theme={null}
> transcriber = aai.Transcriber()
>
> # Local Files
> transcript = transcriber.transcribe("./audio.mp3")
>
> # Public URLs
> transcript = transcriber.transcribe("https://example.com/audio.mp3")
> ```

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

* AssemblyAI natively supports transcribing publicly accessible audio URLs (for example, S3 URLs), the Whisper API only natively supports transcribing local files.
* 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)
* The Whisper API only supports file sizes up to 25MB, AssemblyAI supports file sizes up to 5GB.

## Adding Features

> [tab] OpenAI
>
> ```python theme={null}
> transcript = client.audio.transcriptions.create(
>     file = audio_file,
>     prompt = "INSERT_PROMPT", # Optional text to guide the model's style
>     language = "en", # Set language code
>     model = "whisper-1",
>     response_format = "verbose_json",
>     timestamp_granularities = ["word"]
> )
>
> # Access word-level timestamps
>
> print(transcript.words)
> ```

> [tab] AssemblyAI
>
> ```python theme={null}
> config = aai.TranscriptionConfig(
>     speech_models=["assemblyai-stt-3-7", "universal-2"],
>     language_detection=True,
>     speaker_labels = True, # Speaker diarization
>     sentiment_analysis=True, # Sentiment Analysis
>     entity_detection = True, # Named entity detection
> )
>
> transcript = transcriber.transcribe(audio_url, config)
>
> # Access word-level timestamps
> print(transcript.words)
>
> # Access speaker labels
> for utterance in transcript.utterances:
>     print(f"Speaker {utterance.speaker}: {utterance.text}")
> ```

Key differences:

* OpenAI does not offer speech understanding features for their speech-to-text API
* Use `aai.TranscriptionConfig` to specify any extra features that you wish to use
* With AssemblyAI, timestamp granularity is word-level by default
* The results for Speaker Diarization are stored in `transcript.utterances`. To see the full transcript response object, refer to our [API Reference](https://assemblyai.com/docs/api-reference).
* Check our [documentation](https://assemblyai.com/docs/speech-understanding/getting-started.md) for our full list of available features and their parameters
* If you want to send a custom prompt to an LLM, you can use [LLM Gateway](https://assemblyai.com/docs/llm-gateway/quickstart.md) to apply the model to your transcribed audio files.
