Skip to content

AI Chat

NuxtBase ships with a real AI chat feature, not just a demo input box.

The AI area includes:

  • a dashboard entry that redirects to /ai/chat
  • persisted conversations
  • organization-scoped credits wallets
  • request rate limiting
  • provider-backed streaming responses

AI chat requires:

  • a verified session
  • an active organization
  • available AI credits

If there is no active organization, the request fails with 403. If the wallet has no available balance, the chat endpoint fails with 402.

Conversation access is scoped to both:

  • the current organization
  • the current user

That means a conversation ID is not globally readable just because it exists in the database. The server checks that the conversation belongs to the same organization and the same user before loading it.

The shipped AI flow is more careful than “send prompt, then charge later”.

The request lifecycle is:

  1. rate limit by IP
  2. rate limit by authenticated user
  3. load the active organization’s effective plan quota
  4. load the credits wallet
  5. reserve estimated credits as a pending settlement
  6. stream the model response
  7. resolve the pending settlement using actual token usage

That reservation step matters because it prevents the app from overspending credits while a response is still in progress.

The AI UI reads /api/ai/wallet and gets:

{
balance,
monthlyQuota,
resetAt
}

That data powers the usage display in the chat UI and the billing area.

Provider Selection Versus Feature Behavior

Section titled “Provider Selection Versus Feature Behavior”

The actual provider setup lives in setup/ai-setup.

This page is about what happens after provider setup is already correct:

  • conversations are created lazily when the first message is sent
  • user prompts are stored before the assistant finishes
  • assistant messages are saved after the model stream completes
  • wallet usage is refreshed after each finished response
  1. open /ai/chat as a verified user with an active organization
  2. start a new conversation
  3. refresh the page and confirm the conversation still exists
  4. send enough prompts to see wallet usage move
  5. confirm insufficient credits returns a user-visible error