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
LogoLogo
PlaygroundChangelogSign In
On this page
  • Create a webhook for a transcription
  • Handle webhook deliveries
  • Delivery payload
  • Webhook status code
  • Retrieve a transcript with the transcript ID
  • Authenticate webhook deliveries
  • Add metadata to webhook deliveries
  • Failed webhook deliveries
Getting started

Webhooks for pre-recorded audio

Was this page helpful?
Built with

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.

Python
Python SDK
JavaScript
JavaScript SDK

To create a webhook, set the webhook_url parameter when you create a new transcription. The URL must be accessible from AssemblyAI’s servers.

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5
6headers = {
7 "authorization": "<YOUR_API_KEY>"
8}
9
10with open("./my-audio.mp3", "rb") as f:
11 response = requests.post(base_url + "/v2/upload",
12 headers=headers,
13 data=f)
14
15upload_url = response.json()["upload_url"]
16
17data = {
18 "audio_url": upload_url,
19 "webhook_url": "https://example.com/webhook"
20}
21
22url = base_url + "/v2/transcript"
23response = requests.post(url, json=data, headers=headers)

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.

The webhook payload only contains the transcript_id and status. It doesn’t include the transcript text or error details. If the status is "error", make a GET /v2/transcript/{transcript_id} request to retrieve the error message from the error field in the response. See Retrieve a transcript with the transcript ID below.

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

Python
Python SDK
JavaScript
JavaScript SDK
1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5
6headers = {
7 "authorization": "<YOUR_API_KEY>"
8}
9
10transcript_id = "<TRANSCRIPT_ID>"
11
12polling_endpoint = f"https://api.assemblyai.com/v2/transcript/{transcript_id}"
13
14transcription_result = requests.get(polling_endpoint, headers=headers).json()
15
16if transcription_result['status'] == 'completed':
17 print(f"Transcript ID: {transcript_id}")
18elif transcription_result['status'] == 'error':
19 raise RuntimeError(f"Transcription failed: {transcription_result['error']}")

Authenticate webhook deliveries

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

Python
JavaScript

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)
Python
Python SDK
JavaScript
JavaScript SDK

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

1import requests
2import time
3
4base_url = "https://api.assemblyai.com"
5
6headers = {
7 "authorization": "<YOUR_API_KEY>"
8}
9
10with open("./my-audio.mp3", "rb") as f:
11 response = requests.post(base_url + "/v2/upload",
12 headers=headers,
13 data=f)
14
15upload_url = response.json()["upload_url"]
16
17data = {
18 "audio_url": upload_url,
19 "webhook_url": "https://example.com/webhook",
20 "webhook_auth_header_name": "X-My-Webhook-Secret",
21 "webhook_auth_header_value": "secret-value"
22}
23
24url = base_url + "/v2/transcript"
25response = requests.post(url, json=data, headers=headers)

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.