Overview
The application uses two types of environment variables:Client-side Variables
Variables prefixed with
VITE_ are embedded in the client bundle and accessible in browser codeServer-side Variables
Variables without the
VITE_ prefix are only available in Netlify Functions (serverless backend)Required Variables
API_TOKEN
Azure AI API token for chat functionality
netlify/functions/chat.ts
Scope: Server-side only (Netlify Functions)
How to obtain:
Access Azure AI
- Sign in to Azure Portal
- Navigate to Azure AI Services
netlify/functions/chat.ts
VITE_GITHUB_API_TOKEN
GitHub API token for accessing repository data
Access GitHub Settings
- Go to github.com
- Click your profile picture > Settings
Generate Token
- Navigate to Developer settings > Personal access tokens > Tokens (classic)
- Click “Generate new token (classic)”
Configure Permissions
Select the following scopes:
public_repo- Access public repositoriesread:user- Read user profile data
Generate and Copy
- Click “Generate token”
- Copy the token immediately (you won’t be able to see it again)
This token is optional. If not provided, some GitHub-related features may be limited or disabled.
Configuration by Environment
Local Development
Create a.env file in the root directory:
.env
.env files:
Netlify Production
Navigate to Settings
- Open your site in Netlify dashboard
- Go to Site settings > Environment variables
Add Variables
Click “Add a variable” and enter:Variable 1:
- Key:
API_TOKEN - Value: Your Azure AI API token
- Scopes: Production, Deploy previews (recommended)
- Key:
VITE_GITHUB_API_TOKEN - Value: Your GitHub API token
- Scopes: Production, Deploy previews (recommended)
Using Netlify CLI
When usingnetlify dev, environment variables are automatically synced from your Netlify site:
No need to create a
.env file when using netlify dev - variables are pulled from your Netlify site configuration.Environment Variable Security
Best Practices
Never Commit Tokens
- Always add
.envto.gitignore - Never hardcode API keys in source code
- Use environment variables for all sensitive data
Use Appropriate Scopes
- Only use
VITE_prefix for non-sensitive data - Keep API tokens server-side when possible
- Grant minimal permissions to API tokens
Rotate Tokens Regularly
- Periodically regenerate API tokens
- Update tokens in Netlify when changed
- Revoke old tokens after updating
What NOT to Do
Verifying Configuration
Local Verification
Test that environment variables are loaded correctly:The chat function already includes this check on line 25 of
netlify/functions/chat.tsProduction Verification
-
Check Function Logs:
- Go to Netlify dashboard > Functions > chat
- View recent invocations
- Look for “API Token: exists” in logs
-
Test Chat Functionality:
- Open your deployed site
- Try using the chat assistant
- Check browser console for errors
-
Check Build Logs:
- Go to Deploys > Latest deploy
- Verify no environment variable warnings
Troubleshooting
Function returns 'API Token missing'
Function returns 'API Token missing'
Cause:
API_TOKEN not configured in NetlifySolution:- Go to Site settings > Environment variables
- Add
API_TOKENwith your Azure AI key - Redeploy the site
GitHub data not loading
GitHub data not loading
Cause:
VITE_GITHUB_API_TOKEN not set or invalidSolution:- Verify token is added to environment variables
- Check token has correct permissions (public_repo, read:user)
- Ensure token hasn’t expired
- Regenerate token if necessary
Environment variables not updating
Environment variables not updating
Cause: Changed variables but site not redeployedSolution:
- After changing environment variables in Netlify
- Go to Deploys
- Click “Trigger deploy” > “Clear cache and deploy site”
VITE_ variable undefined in production
VITE_ variable undefined in production
Cause: Variable may not have been available during build timeSolution:
- Ensure variable is set before deploying
- Clear cache and redeploy
- Check build logs for warnings about missing variables
Package.json Configuration
Thedeploy script in package.json demonstrates environment variable usage:
package.json
- Uses
cross-envfor cross-platform compatibility - Maps
API_TOKENtoVITE_GITHUB_API_TOKENfor the gh-pages deployment - Deploys the
distdirectory to GitHub Pages
This deploy script is for GitHub Pages. For Netlify deployment, environment variables are configured in the Netlify dashboard.
Summary
API_TOKEN
Required for Azure AI chat functionality
Server-side only, configured in Netlify
Server-side only, configured in Netlify
VITE_GITHUB_API_TOKEN
Optional for GitHub data features
Client-side, embedded in build
Client-side, embedded in build
Next Steps
Netlify Setup
Complete deployment guide
Quickstart
Get started with local development