For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
PlaygroundChangelogSign In
OverviewAPI ReferencePre-recorded STTStreaming STTVoice AgentsSpeech UnderstandingGuardrailsLLM GatewayFAQ
OverviewAPI ReferencePre-recorded STTStreaming STTVoice AgentsSpeech UnderstandingGuardrailsLLM GatewayFAQ
  • Getting started
    • Transcribe a pre-recorded audio file
    • Model selection
    • View model benchmarks
    • Evaluate model accuracy
    • Cloud endpoints & data residency
    • Manage concurrent requests
    • Webhooks
  • Models
    • Medical Mode
  • Features
    • Boost specific terms
    • Label speakers
    • Transcribe multiple audio channels
    • Transcribe audio with mixed languages
    • Correct spelling of terms
    • Include filler words
    • Search for words in transcript
    • Set the start and end of the transcript
  • Guides
      • Build a meeting notetaker
      • Build a medical scribe
      • Build a contact center application
        • Troubleshoot Common Errors
        • Implement Retry Server Error Logic
        • Implement Retry Upload Error Logic
        • Identify Duplicate Dual Channel Files
        • Correct Audio Duration Discrepancies with Multi-Tool Validation and Transcoding
        • Audio File Downsampling Recommendations and Best Practices
LogoLogo
PlaygroundChangelogSign In
On this page
  • Quickstart
  • Get started
  • Step-by-step instructions
GuidesTutorialsError handling and audio file fixes

Implement Retry Server Error Logic

Was this page helpful?
Previous

Implement Retry Upload Error Logic

Next
Built with

In this guide, we’ll show you how to setup automatic server error retry logic in your transcription process.

Server errors indicate a server-side issue during the transcription process. These rarely happen, but can occasionally occur on our side. If a transcription fails due to a server error, we recommend that you resubmit the file for transcription to allow another server to process the audio. If the issue persists, please reach out to our support team: support@assemblyai.com

This workflow is designed to automatically retry these transcripts if a server error is encountered.

If your transcription fails due to a server error on our side, we will automatically retry the request up to three times. You can find this option in your Account Settings.

Quickstart

1import assemblyai as aai
2import time
3
4aai.settings.api_key = "YOUR_API_KEY"
5
6def handle_error_transcription(audio_url, transcriber, config, retries=1, wait_time=5):
7 for attempt in range(retries + 1):
8 transcript = transcriber.transcribe(audio_url, config)
9 if transcript.error == "Server error, developers have been alerted":
10 if attempt < retries:
11 print(f"Encountered a server error. Retrying in {wait_time} second(s)...")
12 time.sleep(wait_time)
13 else:
14 print("Retry failed with a server error. Please contact AssemblyAI Support: support@assemblyai.com")
15 return None
16 elif transcript.status == aai.TranscriptStatus.error:
17 print(f"Transcription failed: {transcript.error}")
18 return None
19 else:
20 return transcript
21
22audio_url = "YOUR_AUDIO_URL"
23transcriber = aai.Transcriber()
24config = aai.TranscriptionConfig(speech_models=["universal-3-pro", "universal-2"])
25
26transcript = handle_error_transcription(audio_url, transcriber, config, retries=1, wait_time=5)
27if transcript:
28 print(transcript.text)

Get started

Before we begin, make sure you have an AssemblyAI account and an API key. You can sign up for a free account and get your API key from your dashboard.

Step-by-step instructions

Install the SDK:

$pip install assemblyai

Import the assemblyai and time package and set your API key:

1import assemblyai as aai
2import time
3
4aai.settings.api_key = "YOUR_API_KEY"

Create a function that handles errors that may occur during the transcription process. The default number of retires is 1. The default wait time before retranscribing is 5 seconds.

1def handle_error_transcription(audio_url, transcriber, config, retries=1, wait_time=5):
2 for attempt in range(retries + 1):
3 transcript = transcriber.transcribe(audio_url, config)
4 if transcript.error == "Server error, developers have been alerted":
5 if attempt < retries:
6 print(f"Encountered a server error. Retrying in {wait_time} second(s)...")
7 time.sleep(wait_time)
8 else:
9 print("Retry failed with a server error. Please contact AssemblyAI Support: support@assemblyai.com")
10 return None
11 elif transcript.status == aai.TranscriptStatus.error:
12 print(f"Transcription failed: {transcript.error}")
13 return None
14 else:
15 return transcript

Define the audio file that you want to transcribe.

1audio_url = "YOUR_AUDIO_URL"

Create a Transcriber object and specify features in TranscriptionConfig.

1transcriber = aai.Transcriber()
2config = aai.TranscriptionConfig(speech_models=["universal-3-pro", "universal-2"])

Call the function to handle transcription with error handling. Specify number of retries and wait time. Return the transcribed text if transcription is successful.

1transcript = handle_error_transcription(audio_url, transcriber, config, retries=1, wait_time=5)
2if transcript:
3 print(transcript.text)