Skip to main content
General
AI

Overview

Learn about the built-in AI features powered by the Vercel AI SDK.

Open MarkdownFull AI corpusFeedback

The Pro Next.js Prisma starter kit ships an organization-scoped chat powered by AI SDK 7 and the direct OpenAI provider. It includes text streaming, tRPC conversation history, model selection and usage-based credits.

Architecture

The AI system is built with a hybrid architecture to support high-performance streaming while maintaining a type-safe tRPC API for CRUD operations.

FeatureTechnologyReason
Streaming responsesAPI RoutetRPC doesn't support streaming
Chat CRUDtRPCType-safe, cached queries
State managementVercel AI SDKuseChat hook handles streaming

Configuration

Add your OpenAI API key to the .env file to enable the AI features.

.env
OPENAI_API_KEY=sk-...

Shipped Provider

The repository installs @ai-sdk/openai and configures OpenAI models in config/billing.config.ts. Anthropic, Google, Mistral and other provider packages are not included. Install and configure another provider package before using it in custom code.

See the AI SDK provider directory for provider-specific installation and configuration.

Verify the Integration

After adding OPENAI_API_KEY, restart the development server and verify the complete chat flow:

  1. Create or select an organization with a positive credit balance.
  2. Open AI Chatbot, create a new chat and send a short prompt with GPT-4o Mini.
  3. Confirm assistant text streams into the page.
  4. Reload the chat and confirm both messages were persisted.
  5. Open Settings → Credits and confirm a usage transaction was recorded.

An HTTP 200 from /api/ai/chat alone does not prove generation succeeded. Streaming responses send their headers before the provider has finished. If no assistant text appears, verify the server-side key, OpenAI quota and access to the selected model, then inspect the server logs for the provider error.

No assistant response

Use the provider error in the development server log to identify the failing layer:

Provider errorMeaningWhat to check
invalid_api_key or HTTP 401OpenAI rejected the credentialCreate a server key in the intended OpenAI Platform project, replace OPENAI_API_KEY and restart the development server
insufficient_quota or HTTP 429 with a quota messageThe key is valid but its project cannot spendEnable API billing, add credit and confirm the project budget allows requests
model_not_found or HTTP 404The project cannot use the selected modelSelect a model listed in config/billing.config.ts that is available to the project
insufficient_credits or HTTP 402 from AchromaticThe organization does not have enough application creditsAdd credits in the application, then retry the message

OpenAI API keys are scoped to a project. When you create a replacement key, verify that the selected project is the same project where API billing and the budget are configured. Never paste a real key into an issue, support message or client-side environment variable. Rotate any key that has been shared.