AI
OpenAI-compatible API architecture
The AI SaaS Starter calls an OpenAI-compatible chat completions endpoint. The base URL and model are environment variables.
The AI SaaS Starter does not hardcode a vendor SDK. It posts to an OpenAI-compatible /v1 chat completions URL. AI_BASE_URL defaults to https://api.openai.com/v1. The model defaults to gpt-4o-mini. Point the base URL at another compatible host and the route stays the same.
The request asks for a stream. The Next.js route forwards that stream to the browser instead of waiting for the full body. The mechanics are in streaming AI responses in Next.js.
Each finished generation costs 1 credit and is written to the Generation model with the prompt, the output, and that credit count. Monthly caps are 20 on the free plan and 500 on Pro, counted from the first of the local month. That ledger is AI usage limits and credits and storing AI generation history.
The starter does not ship a model, a fine-tune, or a vector store. It ships the HTTP boundary, the log, and the credit check.
Plan changes still come from Stripe, as in building an AI SaaS with Next.js.