Back to Templates

Next.js AI application with Thinkroman for billing credits

Simple AI image generation application. Contains example code of generating and refilling Thinkroman API keys in response to a Stripe payment link, and using the `remaining` field for measuring usage.

Written by
domeccleston
Framework
Next.js
Language
Typescript
Simple AI image generation application. Contains example code of generating and refilling Thinkroman API keys in response to a Stripe payment link, and using the `remaining` field for measuring usage.

How to use Unkey to set up billing for your AI application

Example of a generative AI application using Unkey for billing.

  • Includes example code to set up Stripe for payment links
  • On payment, users are assigned an Unkey API key with the 'remaining' field set to 10, signifying 10 credits
  • This API key is saved to a cookie (httpOnly, so not accessible via client-side Javascript)
  • This cookie is attached to requests to an API route in /api/openai; this API route verifies the key (decrementing remaining) and requests images from OpenAI.

Deploy to Vercel

Elevate your career with ThinkRoman USA

Stay ahead, stay informed, and stay connected with ThinkRoman USA!