TurboStarter
For the complete documentation index, see llms.txt. Prefer markdown by appending .md to documentation URLs or sending Accept: text/markdown.

Billing

Middleware-based credit system that deducts a configured amount per AI request, with usage-based billing and payment provider integration planned.

AI Kit includes a straightforward middleware setup to manage user credits for AI features. This lets you control access based on available credits without complex payment integrations.

Credit-based access

A focused middleware verifies if users have enough credits before allowing them to access specific AI-powered routes or actions.

ai.router.ts
export const aiRouter = new Hono().post(
  "/chat",
  rateLimiter,
  validate("json", chatMessageSchema),
  deductCredits({
    amount: 10, 
  }),
  streamChat,
);

This example shows how the deductCredits middleware subtracts a specific amount (10 credits) for each request to the /chat endpoint.

Extending billing

To charge for subscriptions or credit purchases, follow Integrate Core Kit, then use the provider guides below. Keep one server-side policy for payments and AI usage.

How is this guide?

Last updated on

On this page

Make AI your edge, not replacement.Try AI Kit