Skip to main content
All use casesUse Case

The auth, billing, and job infrastructure behind an AI video product.

Video generation models run for seconds to minutes per job. FastAPI AI Kit handles the parts around the model call — auth, per-customer rate limits, async job orchestration, and usage-based billing — while you connect your generation provider of choice (Fal.ai, Replicate, or a self-hosted model).

FastAPICeleryRedisFal.ai / ReplicateStripePostgreSQL

The usual pain points

  • Generation jobs take too long to run in an HTTP request/response cycle
  • Tracking job status and returning results once generation finishes
  • Billing customers per generation, not per API call
  • Rate limiting to control GPU/provider costs per customer tier

How the kit solves them

  • Celery background jobs built for exactly this kind of long-running async work
  • Job-status endpoint pattern already used for document processing, reused here
  • Stripe metering hooks bill per generation instead of per request
  • Per-API-key rate limiting caps how many generations a tier can request per day

Example implementation

main.py
@router.post("/v1/video/generate")
@require_api_key(tier=["basic", "pro"])
@rate_limit(per_day=20)
async def generate_video(body: VideoGenRequest, key: APIKey = Depends(get_api_key)):
    job = generate_video_task.delay(body.prompt, key.id)
    return {"job_id": job.id, "status": "processing"}

@celery.task
def generate_video_task(prompt: str, key_id: str):
    result = fal_client.subscribe("fal-ai/video-model", arguments={"prompt": prompt})
    meter.record(key_id, units=1)  # billed per generation
    update_job_result(result)

Ready to build your ai video generator backend?

FastAPI AI Kit ships with everything shown above, pre-configured and production-ready. Clone the repo and start building in minutes.

Ready to ship your AI backend this weekend?

Join developers who skipped weeks of boilerplate and went straight to building.

Read the docs
No subscriptions · One-time payment · Lifetime updates