Deployment
Deployment
Section titled “Deployment”Introduction
Section titled “Introduction”Deploying an AI application requires the same steps as other Next.js apps, plus configuration for streaming support and API keys.
Environment Variables
Section titled “Environment Variables”OPENAI_API_KEY=sk-your-key-hereDATABASE_URL=your_production_db_urlGet your OpenAI API key from platform.openai.com.
Streaming on Vercel
Section titled “Streaming on Vercel”Vercel supports streaming responses out of the box. No additional configuration is needed for the AI SDK. The Server Action streaming pattern works automatically.
Rate Limiting
Section titled “Rate Limiting”Consider adding rate limiting to prevent abuse:
import { Ratelimit } from '@upstash/ratelimit'import { Redis } from '@upstash/redis'
const ratelimit = new Ratelimit({ redis: Redis.fromEnv(), limiter: Ratelimit.slidingWindow(20, '10 m'),})
export async function checkRateLimit(identifier: string) { const { success } = await ratelimit.limit(identifier) if (!success) { throw new Error('Rate limit exceeded') }}Deployment Checklist
Section titled “Deployment Checklist”- AI API key is configured as an environment variable
- Streaming works in production
- Error handling shows user-friendly messages
- Rate limiting is configured
- Messages are persisted to the database
- Abort/cancel functionality works
- Build passes with no TypeScript errors
Summary
Section titled “Summary”Deploying an AI app is similar to any Next.js app. The key difference is configuring the AI API key and ensuring streaming works in production. Add rate limiting to protect your API usage.