Skip to main content

Async webhooks

Some LLM tasks take too long for a synchronous HTTP response. This recipe shows how to accept a request, enqueue the work, call Radium in the background, and deliver results via a webhook callback.

The script (FastAPI + background tasks)

webhook_server.py

Run it

Submit a job

Receive the webhook

Your endpoint will receive:

Production queue (Celery + Redis)

For high throughput, replace FastAPI background tasks with a proper queue:
celery_worker.py

Polling fallback

Not every client supports webhooks. Offer a status endpoint:

Tips

  • Return request_id immediately — never block the HTTP connection waiting for an LLM response.
  • Retry webhooks with exponential backoff — your user’s endpoint might be temporarily down.
  • Sign webhooks with an HMAC signature so clients can verify the payload came from you.
  • Use tycho-1.0 for fast, cheap async tasks like classification and tagging.
  • Monitor queue depth — if jobs pile up, scale workers or add a circuit breaker.

Next steps

Error handling & retries

Add resilience to async workers

Monitoring usage

Track async job metrics and costs