MicroAuth for FastAPI
API keys, rate limits and billing for FastAPI
Add one dependency to your routes. Developers get a portal to sign up, create keys and pay you, and every key is checked inside your app.
Free plan, no credit card. microauth-fastapi on PyPI
Live in three steps
About five minutes. Python 3.10 or later.
-
Install the SDK
Terminalpip install microauth-fastapi
-
Protect a route
Add the three highlighted lines. Routes with
Security(auth)now need a customer key, and every other route stays public.main.pyfrom fastapi import FastAPI, Securityfrom microauth_fastapi import MicroAuth, Customer app = FastAPI()auth = MicroAuth(app) # reads MICROAUTH_SECRET_KEY @app.get("/forecast")async def forecast(customer: Customer = Security(auth)): return {"hello": customer.id} -
Add your secret key and run
Create a free account and name your API. The dashboard shows your SDK secret key right away. Put it in a
.envfile next tomain.py..envMICROAUTH_SECRET_KEY=mas_...
Terminalfastapi dev main.py
Get your secret key The dashboard also gives you a test key to try it right away.
What you get
Developers sign up, get a key and pay you
A portal for your developers
Developers sign up at yourapi.microauth.dev, create keys, check usage and pay. Add your logo and accent color in the dashboard.
Limits and billing per customer
Rate limits, monthly quotas and prepaid credit are checked before your route runs. Charge per request or sell plans through your own Stripe account.
Keys that work in /docs
The SDK adds the API key to your OpenAPI schema, so developers can paste their key into the Authorize button in Swagger UI.
Nothing in front of your API
Keys are checked from a local cache with no network call. Usage goes to MicroAuth in the background.
$ curl localhost:8000/forecast
401{"detail":"Invalid or missing API key"}
$ curl localhost:8000/forecast -H "X-API-Key: map_…"
200{"hello":"2b7c1f8e-…"}
# the same key, over its plan's rate limit
429{"detail":"Rate limit exceeded"}
# a customer with no credit left
402{"detail":"Insufficient credit balance"}
Questions FastAPI developers ask
Does my API traffic go through MicroAuth?
No. The SDK runs inside your FastAPI app and checks keys against a cached copy of your customers and limits. Only usage counts go to MicroAuth, in background batches. Request and response bodies never leave your servers.
What happens if MicroAuth is down?
Your API keeps serving from its cached data, up to a staleness limit you control, and sends the buffered usage once MicroAuth is reachable again.
I run several workers. Does that work?
Yes. With several uvicorn workers or machines, install microauth-fastapi[redis] and pass redis_url so every worker shares one exact limit. Vercel and AWS Lambda work too.
How do I get paid?
Connect your own Stripe account. Developers subscribe or top up credit on your portal and the money goes straight to you. MicroAuth takes no revenue share.
What does MicroAuth cost?
You can start on the free plan without a credit card. Paid plans are a flat monthly price per API. See pricing.