All templatesTemplate
A multi-tenant SaaS API backend with auth, billing, and LLM integration.
The SaaS API template configures FastAPI AI Kit for multi-tenant AI SaaS products. Each customer gets their own API keys with independent rate limits, usage tracking, and billing. Perfect for B2B AI products where customers integrate via your API.
FastAPIPostgreSQLRedisStripeOpenAI / AnthropicCelery
What's included
- Multi-tenant API key auth with per-customer isolation
- Per-key rate limiting with configurable tiers (free, pro, enterprise)
- Stripe subscription management with usage-based metering
- LLM integration with per-tenant model configuration
- Token and request usage tracking per customer
- Customer onboarding and API key management endpoints
- Admin endpoints for usage monitoring and key management
- Webhook infrastructure for async event notification
Code preview
# Multi-tenant endpoint with per-key auth and billing
@router.post("/v1/generate")
async def generate(
body: GenerateRequest,
key: APIKey = Depends(verify_api_key), # tenant-scoped
):
await check_rate_limit(key) # per-key limits
await check_usage_quota(key) # monthly caps
response = await llm.chat(
messages=body.messages,
model=key.tier_config.model, # per-tier model access
track_tokens=True,
)
await meter.record(key.id, response.tokens) # Stripe metering
return GenerateResponse(content=response.content, tokens_used=response.tokens)
# Admin: view customer usage
@router.get("/admin/usage/{customer_id}")
async def get_usage(customer_id: str, admin: Admin = Depends(require_admin)):
return await get_customer_usage_summary(customer_id)Start with this template
Get FastAPI AI Kit, select this template configuration, and deploy your fastapi saas api template in minutes.
Ready to ship your AI backend this weekend?
Join developers who skipped weeks of boilerplate and went straight to building.
No subscriptions · One-time payment · Lifetime updates