All integrationsAuthentication
Clerk Integration
Use Clerk for user sign-in, the kit's API keys for backend access.
Clerk handles user-facing authentication (sign-up, sign-in, session management, orgs). FastAPI AI Kit's JWT + API key system handles backend API access. Most teams run both: Clerk in front, kit-issued API keys behind it.
Setup in 4 steps
- 1Verify the Clerk session JWT on your frontend or a thin auth middleware
- 2On first authenticated request, issue a kit API key tied to the Clerk user ID
- 3Store the mapping between Clerk user ID and kit API key in your Postgres database
- 4Backend endpoints continue to use @require_api_key exactly as documented
What's included
- No changes needed to the kit's existing require_api_key/rate_limit decorators
- Clerk organizations map naturally onto per-team API key tiers
- Stripe metering keeps working per API key, which you resolve back to a Clerk user
- Avoids reimplementing session management or MFA inside the FastAPI service
Code example
# Backend: resolve Clerk user -> kit API key on first request
@router.post("/internal/session-exchange")
async def exchange_clerk_session(clerk_user_id: str, db: AsyncSession = Depends(get_db)):
key = await get_or_create_api_key(db, external_id=clerk_user_id, provider="clerk")
return {"api_key": key.raw_key}
# All existing endpoints work unchanged
@router.post("/v1/chat")
@require_api_key(tier=["basic", "pro"])
async def chat(...): ...Full documentation: /docs/authentication
Clerk integration pre-wired and ready.
FastAPI AI Kit ships with Clerk configured out of the box. No manual setup required.
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
