Skip to main content
All integrationsBilling

Stripe Integration

Usage-based billing wired to every API call.

FastAPI AI Kit ships with Stripe usage metering hooks. Every API call records token consumption, which flows into Stripe's metered billing without any additional setup.

Setup in 4 steps

  1. 1Add STRIPE_SECRET_KEY to your .env
  2. 2Configure your metered billing product in Stripe Dashboard
  3. 3Set STRIPE_METERED_PRICE_ID in config
  4. 4Token usage automatically reported to Stripe meter API

What's included

  • Automatic Stripe usage metering on every metered endpoint
  • Per-API-key usage tracking mapped to Stripe subscriptions
  • Webhook handler for subscription lifecycle events
  • Configurable metering unit (tokens, requests, or custom)
  • Usage dashboard hooks for internal analytics

Code example

example.py
# Every metered endpoint auto-reports to Stripe
@router.post("/v1/chat")
@require_api_key(tier=["basic", "pro"])
async def chat(body: ChatRequest, key: APIKey = Depends(get_api_key)):
    response = await llm.chat(body.messages, track_tokens=True)
    # Automatically batches usage reports to Stripe
    await meter.record(
        customer_id=key.stripe_customer_id,
        units=response.tokens,
    )
    return {"reply": response.content}

Full documentation: /docs/configuration

Stripe integration pre-wired and ready.

FastAPI AI Kit ships with Stripe 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.

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