MicroAuth for FastAPI

API keys, rate limits and billing for FastAPI

Add one dependency to your routes. Customers get a portal to sign up, create keys and pay you, and every key is checked inside your app.

Free plan. No credit card. Open source SDK.

Live in three steps

About five minutes. Python 3.10 or later.

  1. 1

    Install the SDK

    Terminal
    pip install microauth-fastapi
  2. 2

    Protect a route

    Add the three highlighted lines. Routes withSecurity(auth) now need a customer key. Every other route stays public.

    main.py
    from 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}
  3. 3

    Add your secret key and run

    Create a free account and name your API. The dashboard shows your secret key right away. Put it in a.env file next tomain.py.

    .env
    MICROAUTH_SECRET_KEY=mas_...
    Terminal
    fastapi dev main.py
    Get your secret keyFree plan. No credit card.

What you get

Customers sign up, get a key and pay you

  • A portal for your customers

    Customers sign up at yourapi.microauth.dev, create keys, check usage and pay. Add your logo and colors in the dashboard.

  • Limits and billing per customer

    Rate limits, monthly quotas and prepaid credit are enforced before your route runs. Charge per request or by plan through your own Stripe account.

  • Keys that work in /docs

    The SDK adds the API key to your OpenAPI schema, so customers 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 is reported to MicroAuth in the background.

Terminal

$ 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 are sent 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 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 to MicroAuth so every worker shares one exact limit. Vercel and AWS Lambda are supported too.

How do I get paid?

Connect your own Stripe account. Customers 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

Turn your FastAPI app into a paid API

Install the SDK, protect a route and share your portal link. The free plan needs no credit card.