Overview
PDF AI requires several environment variables to connect to external services and APIs. All environment variables should be stored in a.env file in the root of your project.
Required Variables
Database
src/lib/db/index.ts:5-7- Database client initializationdrizzle.config.ts:12- Drizzle ORM configuration
- Sign up at Neon
- Create a new project
- Copy the connection string from your project dashboard
The application will throw an error if
DATABASE_URL is not found, as it’s critical for all database operations.OpenAI
src/lib/embeddings.ts:4- Creating PDF embeddingssrc/app/api/chat/route.ts:13- Chat completions API
- Sign up at OpenAI
- Navigate to API keys section
- Create a new secret key
Pinecone Vector Database
src/lib/pinecone.ts:17-18- Pinecone client initializationsrc/lib/context.ts:24-25- Context retrieval for chat
- Sign up at Pinecone
- Create a new index
- Copy your API key and environment from the console
Your Pinecone environment is typically something like
us-west1-gcp or us-east-1-aws.AWS S3 Storage
src/lib/s3.ts:7-8,12,20,51- Client-side S3 operationssrc/lib/s3-server.ts:6-7,11,16- Server-side S3 operations
- Sign up for AWS
- Create an S3 bucket in the
ap-south-1region (or modify the region in the code) - Create an IAM user with S3 access
- Generate access keys for the IAM user
Clerk Authentication
src/app/layout.tsx:4,20- ClerkProvider wrappersrc/middleware.ts:1,6- Authentication middleware
- Sign up at Clerk
- Create a new application
- Copy the publishable key and secret key from the API Keys section
Stripe Payments
src/lib/stripe.ts:3- Stripe client initializationsrc/app/api/webhook/route.ts:20- Webhook signature verification
- Sign up at Stripe
- Get your API key from the Developers section
- Set up a webhook endpoint and copy the webhook secret
Use test mode keys (
sk_test_...) during development. Switch to live keys (sk_live_...) only in production.Application URL
src/app/api/stripe/route.ts:9- Stripe checkout redirects
- Development:
http://localhost:3000 - Production:
https://your-domain.com
Environment Variable Checklist
Before running the application, ensure you have set:-
DATABASE_URL- Neon PostgreSQL connection -
OPEN_AI_KEY- OpenAI API key -
PINECONE_API_KEY- Pinecone API key -
PINECONE_ENVIRONMENT- Pinecone environment -
NEXT_PUBLIC_S3_ACCESS_KEY_ID- AWS access key -
NEXT_PUBLIC_S3_SECRET_ACCESS_KEY- AWS secret key -
NEXT_PUBLIC_S3_BUCKET_NAME- S3 bucket name -
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY- Clerk publishable key -
CLERK_SECRET_KEY- Clerk secret key -
STRIPE_API_KEY- Stripe API key -
STRIPE_WEBHOOK_SECRET- Stripe webhook secret -
NEXT_BASE_URL- Application base URL
Example .env File
Security Best Practices
Use environment-specific files
.env.local- Local development (git-ignored).env.production- Production settings- Never mix development and production credentials
Rotate keys regularly
Periodically rotate API keys and secrets, especially after:
- Team member departures
- Suspected security incidents
- Every 90 days as a best practice