Webhooks for pre-recorded audio

Webhooks are custom HTTP callbacks that you can define to get notified when your pre-recorded audio transcripts are ready.

This guide covers webhooks for pre-recorded audio transcription. For webhooks with streaming audio, see Webhooks for streaming speech-to-text.

To use webhooks, you need to set up your own webhook receiver to handle webhook deliveries.

Create a webhook for a transcription

Don't have a webhook endpoint yet?

Create a test webhook endpoint with webhook.site to test your webhook integration.

To create a webhook, use set_webhook() on the transcription config. The URL must be accessible from AssemblyAI’s servers.

Use submit() instead of transcribe() to create a transcription without waiting for it to complete.

1import assemblyai as aai
2
3aai.settings.api_key = "<YOUR_API_KEY>"
4
5# audio_file = "./local_file.mp3"
6audio_file = "https://assembly.ai/wildfires.mp3"
7
8config = aai.TranscriptionConfig().set_webhook("https://example.com/webhook")
9
10aai.Transcriber().submit(audio_file, config)

Handle webhook deliveries

When the transcript is ready, AssemblyAI will send a POST HTTP request to the URL that you specified.

Your webhook endpoint must return a 2xx HTTP status code within 10 seconds to indicate successful receipt. If a 2xx status is not received within 10 seconds, AssemblyAI will retry the webhook call up to a total of 10 attempts. If at any point your endpoint returns a 4xx status code, the webhook call is considered failed and will not be retried.

Static Webhook IP addresses

AssemblyAI sends all webhook deliveries from fixed IP addresses:

RegionIP Address
US44.238.19.20
EU54.220.25.36

Delivery payload

The webhook delivery payload contains a JSON object with the following properties:

1{
2 "transcript_id": "5552493-16d8-42d8-8feb-c2a16b56f6e8",
3 "status": "completed"
4}
KeyTypeDescription
transcript_idstringThe ID of the transcript.
statusstringThe status of the transcript. Either completed or error.

Webhook status code

When you retrieve the transcript using the transcript ID, the JSON response will include a webhook_status_code field. This field contains the HTTP status code that AssemblyAI received when calling your webhook endpoint, allowing you to verify that the webhook was delivered successfully.

Retrieve a transcript with the transcript ID

1import assemblyai as aai
2
3aai.settings.api_key = "<YOUR_API_KEY>"
4
5transcript = aai.Transcript.get_by_id("<TRANSCRIPT_ID>")
6
7if transcript.status == "error":
8 raise RuntimeError(f"Transcription failed: {transcript.error}")
9
10print(transcript.text)

Authenticate webhook deliveries

You can authenticate webhook deliveries from AssemblyAI by including a custom HTTP header in the request.

To add an authentication header, include the auth header name and value in set_webhook().

1config = aai.TranscriptionConfig().set_webhook(
2 "https://example.com/webhook", "X-My-Webhook-Secret", "secret-value"
3)
4
5aai.Transcriber().submit(audio_url, config)

To add an authentication header, include the auth header name and value in set_webhook().

1import assemblyai as aai
2
3aai.settings.api_key = "<YOUR_API_KEY>"
4
5# audio_file = "./local_file.mp3"
6audio_file = "https://assembly.ai/wildfires.mp3"
7
8config = aai.TranscriptionConfig().set_webhook("https://example.com/webhook", "X-My-Webhook-Secret", "secret-value")
9
10aai.Transcriber().submit(audio_file, config)

Add metadata to webhook deliveries

To associate metadata for a specific transcription request, you can add your own query parameters to the webhook URL.

1https://example.com/webhook?customer_id=1234&order_id=5678

Now, when you receive the webhook delivery, you’ll know the customer who requested it.

Failed webhook deliveries

Webhook deliveries can fail for multiple reasons. For example, if your server is down or takes more than 10 seconds to respond.

If a webhook delivery fails, AssemblyAI will attempt to redeliver it up to 10 times, waiting 10 seconds between each attempt. If all attempts fail, AssemblyAI considers the delivery as permanently failed.