Skip to content

Feedback: guides-retry-server-error

Original URL: https://www.assemblyai.com/docs/guides/retry-server-error
Category: guides
Generated: 05/08/2025, 4:38:12 pm


Generated: 05/08/2025, 4:38:11 pm

Technical Documentation Analysis & Feedback

Section titled “Technical Documentation Analysis & Feedback”

The documentation covers a useful functionality but suffers from several structural and content issues that could frustrate users. Here’s my detailed analysis:

Error Code Identification

  • No clear definition of what constitutes a “server error” vs other error types
  • Missing HTTP status codes that trigger retries (5xx errors)
  • No list of specific error messages that should trigger retries

Configuration Details

  • Lack of guidance on optimal retry counts and wait times
  • No mention of exponential backoff strategies
  • Missing information about rate limits and how they interact with retries

SDK Requirements

  • No minimum SDK version specified
  • Missing compatibility information

Redundant Code The exact same code block appears twice (Quickstart and Step-by-step), which is confusing and suggests poor organization.

Recommended Structure:

1. Overview & When to Use
2. Prerequisites
3. Implementation Options
- Basic Implementation
- Advanced Implementation (exponential backoff)
4. Configuration Reference
5. Error Handling Best Practices
6. Troubleshooting

Logic Flow Issues

  • The retry logic is hard to follow
  • No explanation of why the function returns early in success cases
  • Unclear distinction between different error types

Parameter Explanations

# Current - unclear parameter purpose
def handle_error_transcription(audio_url, transcriber, config, retries=1, wait_time=5):
# Better - with clear documentation
def handle_error_transcription(
audio_url: str, # URL or path to audio file
transcriber: aai.Transcriber, # AssemblyAI transcriber instance
config: aai.TranscriptionConfig, # Transcription settings
max_retries: int = 3, # Maximum retry attempts (recommended: 3-5)
initial_wait: float = 2.0, # Initial wait time in seconds
use_exponential_backoff: bool = True # Whether to increase wait time per retry
) -> Optional[aai.Transcript]:

Current Example Issues:

  • Generic placeholder values
  • No real-world audio URL
  • Missing error scenarios demonstration

Improved Examples:

# Example 1: Basic retry with real audio
audio_url = "https://github.com/AssemblyAI-Examples/audio-examples/raw/main/20230607_me_canadian_wildfires.mp3"
transcript = handle_error_transcription(
audio_url=audio_url,
transcriber=transcriber,
config=config,
max_retries=3,
initial_wait=2.0
)
# Example 2: Advanced configuration with speaker detection
config = aai.TranscriptionConfig(
speaker_labels=True,
auto_highlights=True
)
# Example 3: Handling different error scenarios
try:
transcript = handle_error_transcription(audio_url, transcriber, config)
if transcript:
print(f"✅ Transcription successful: {len(transcript.text)} characters")
if transcript.confidence < 0.8:
print("⚠️ Low confidence score - consider audio quality")
else:
print("❌ Transcription failed after retries")
except Exception as e:
print(f"❌ Unexpected error: {e}")

Immediate Issues:

  • Users can’t distinguish between retry-worthy and non-retry-worthy errors
  • No guidance on what to do when retries are exhausted
  • Hardcoded error message matching is fragile

Improved Error Handling:

def is_retriable_error(transcript: aai.Transcript) -> bool:
"""Check if the error is worth retrying."""
if transcript.status != aai.TranscriptStatus.error:
return False
# Server errors that should be retried
retriable_errors = [
"Server error, developers have been alerted",
"Internal server error",
"Service temporarily unavailable",
"Timeout error"
]
return any(error in transcript.error.lower() for error in retriable_errors)
def calculate_wait_time(attempt: int, initial_wait: float, max_wait: float = 60.0) -> float:
"""Calculate wait time with exponential backoff and jitter."""
import random
wait_time = initial_wait * (2 ** attempt) # Exponential backoff
wait_time = min(wait_time, max_wait) # Cap maximum wait
jitter = random.uniform(0.1, 0.9) # Add jitter to prevent thundering herd
return wait_time * jitter
ParameterTypeDefaultDescriptionRecommended Range
max_retriesint3Maximum retry attempts1-5
initial_waitfloat2.0Initial wait time (seconds)1.0-5.0
max_waitfloat60.0Maximum wait time (seconds)30.0-300.0
use_exponential_backoffboolTrueIncrease wait time per retry-
## Troubleshooting
**Q: My retries keep failing with server errors**
A: If you experience persistent server errors after 3+ retries, this may indicate a service outage. Check our [status page](https://status.assemblyai.com) or contact support.
**Q: Should I retry client errors (4xx)?**
A: No, client errors indicate issues with your request (invalid API key, malformed audio, etc.) and retrying won't help.
**Q: How long should I wait between retries?**
A: Start with 2-5 seconds and use exponential backoff. Our servers typically recover within seconds.
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def handle_error_transcription_with_logging(audio_url, transcriber, config, max_retries=3):
for attempt in range(max_retries + 1):
logger.info(f"Transcription attempt {attempt + 1}/{max_retries + 1}")
transcript = transcriber.transcribe(audio_url, config)
if transcript.status == aai.TranscriptStatus.completed:
logger.info("✅ Transcription completed successfully")
return transcript
elif is_retriable_error(transcript):
wait_time = calculate_wait_time(attempt, 2.0)
logger.warning(f"⚠️ Server error on attempt {attempt + 1}. Retrying in {wait_time:.1f}s...")
time.sleep(wait_time)
else:
logger.error(f"❌ Non-retriable error: {transcript.error}")
return None
logger.error("❌ All retry attempts exhausted")
return None

This improved structure would make the documentation much more user-friendly and production-ready.