Overview
The AI-BIM App uses environment variables to configure sensitive settings like API keys. These variables are loaded at build time by Vite and must be properly configured before building or running the application.Environment Variable Setup
Creating the .env File
Create a.env file in the root directory of your project (same level as vite.config.ts):
Required Variables
VITE_OPENAI_API_KEY
The OpenAI API key used for AI-powered BIM data queries.Vite Configuration Considerations
Environment Variable Prefix
Vite uses theVITE_ prefix to expose environment variables to client-side code. Variables without this prefix are not accessible in the browser for security reasons.
File reference: vite.config.ts:1-12
The current Vite configuration uses default settings:
How Environment Variables Are Used
The OpenAI API key is accessed in the ChatGpt component using Vite’simport.meta.env object:
File reference: src/bim-components/ChatGpt/index.ts:63
src/bim-components/ChatGpt/index.ts:67-86).
Build-Time vs Runtime
Environment variables in Vite are embedded at build time. If you change your
.env file, you must rebuild the application for changes to take effect.Development Mode
.env and watches for changes.
Production Build
.env file is configured before building.
Security Best Practices
.gitignore Configuration
Always add environment files to.gitignore:
API Key Protection
Environment Templates
Create a.env.example file (safe to commit) as a template:
Troubleshooting
API Key Not Found
If you see errors about missing API keys:- Verify
.envfile exists in the project root - Check that the variable name starts with
VITE_ - Restart the development server after adding variables
- Rebuild the application if running a production build
Invalid API Key Errors
If authentication fails:- Verify your API key is correct in
.env - Check that there are no extra spaces or quotes
- Ensure your OpenAI account has active billing
- Verify the API key hasn’t been revoked
Additional Configuration
The application uses standard Vite configuration with:- Base path:
./for relative asset paths - Top-level await: Enabled for modern async module loading
- ESBuild: Default TypeScript transpilation