AI Music Detection in Python — Complete SDK Tutorial
Integrating AI music detection into Python apps takes ~10 minutes with our SDK. This tutorial covers install, auth, file/URL analysis, batch processing, error handling, and production patterns.
Installation
pip install aisongchecker
Or directly from source:
pip install git+https://github.com/aisongchecker/python-sdk.git
Authentication
Get your API key from the dashboard (requires Pro tier — 4,99 €/month).
from aisongchecker import Client
client = Client(api_key="ASC_LIVE_xxx") # or use env: os.environ["ASC_API_KEY"]
Analyze a single file
result = client.analyze_file("track.mp3")
print(f"AI probability: {result.ai_probability:.1%}")
print(f"Verdict: {result.verdict}") # "ai" | "human" | "uncertain"
print(f"Engine: {result.platform_attribution.top}")
print(f"Confidence: {result.confidence:.2f}")
Analyze a URL (YouTube/Spotify/SoundCloud)
result = client.analyze_url("https://www.youtube.com/watch?v=xyz")
if result.verdict == "ai":
print(f"AI detected: {result.platform_attribution.top}")
print(f"Watermarks: c2pa={result.watermarks.c2pa_detected}, synthid={result.watermarks.synthid_detected}")
Batch analysis
tracks = [
{"id": "t1", "url": "https://soundcloud.com/.../track1"},
{"id": "t2", "url": "https://open.spotify.com/track/abc"},
{"id": "t3", "file_path": "/local/track3.mp3"},
]
batch = client.analyze_batch(tracks, webhook_url="https://your-app.com/asc-webhook")
print(f"Job ID: {batch.job_id}, status: {batch.status}")
# Or poll synchronously
result = client.wait_for_batch(batch.job_id, timeout=600)
for r in result.results:
print(f"{r.id}: {r.ai_probability:.1%} ({r.verdict})")
Error handling with retry
from aisongchecker import Client, RateLimitError, APIError
import time
client = Client(api_key="...", max_retries=5, retry_backoff=2.0)
try:
result = client.analyze_file("track.mp3")
except RateLimitError as e:
print(f"Rate limited, retry after {e.retry_after}s")
except APIError as e:
print(f"API error: {e.code} {e.message}")
Async (asyncio)
import asyncio
from aisongchecker.asyncio import AsyncClient
async def main():
async with AsyncClient(api_key="...") as client:
results = await asyncio.gather(*[
client.analyze_url(url) for url in urls
])
for r in results:
print(r.verdict)
asyncio.run(main())
Production checklist
- API key in env var (never hard-coded)
- Use
max_retries=5with exponential backoff - Cache results by audio hash (avoid duplicate analyses)
- Use batch endpoint for >10 tracks
- Set webhook URL to avoid polling for large batches
- Monitor
client.usage()for quota tracking