This guide covers deploying Sakura AI to Netlify with secure API key handling.
API keys are never exposed to the frontend. All Groq API calls are made through secure Netlify serverless functions.
- A Netlify account
- A Groq API key
- Node.js 18+ installed
-
Push your code to GitHub
git init git add . git commit -m "Initial commit" git branch -M main git remote add origin <your-repo-url> git push -u origin main
-
Connect to Netlify
- Go to Netlify
- Click "Add new site" → "Import an existing project"
- Choose GitHub and select your repository
- Configure build settings:
- Build command:
npm run build - Publish directory:
dist - Functions directory:
netlify/functions
- Build command:
-
Set Environment Variables
- In Netlify dashboard, go to: Site settings → Environment variables
- Add the following variable:
- Key:
GROQ_API_KEY - Value: Your Groq API key from https://console.groq.com/keys
- Key:
- Click "Save"
-
Deploy
- Click "Deploy site"
- Wait for deployment to complete
- Your site will be live at
https://<your-site-name>.netlify.app
-
Install Netlify CLI
npm install -g netlify-cli
-
Login to Netlify
netlify login
-
Initialize Netlify site
netlify init
- Choose "Create & configure a new site"
- Select your team
- Enter a site name (or leave blank for auto-generated)
- Build command:
npm run build - Publish directory:
dist - Functions directory:
netlify/functions
-
Set environment variables
netlify env:set GROQ_API_KEY "your_groq_api_key_here" -
Deploy
netlify deploy --prod
-
Install dependencies
npm install
-
Create
.env.localfile (DO NOT commit this file!)GROQ_API_KEY=your_groq_api_key_here
-
Run development server with Netlify Functions
npm run dev
This uses
netlify devwhich:- Runs Vite dev server
- Runs Netlify Functions locally
- Proxies function requests to
http://localhost:8888/.netlify/functions
-
Access the app
- Open http://localhost:8888 (NOT 5173)
- Netlify Dev automatically proxies both the frontend and functions
GROQ_API_KEY- Your Groq API key (set in Netlify dashboard or via CLI)
The frontend no longer needs any API keys! All sensitive operations happen in serverless functions.
AfnyAI-v2/
├── netlify/
│ └── functions/ # Serverless functions
│ ├── chat.ts # Chat completion endpoint
│ ├── translate.ts # Translation endpoint
│ └── word-of-day.ts # Word of the day endpoint
├── services/
│ ├── apiService.ts # Frontend API client (calls Netlify functions)
│ └── speechService.ts # Text-to-speech service
├── components/ # React components
├── netlify.toml # Netlify configuration
├── .env.local.example # Example environment file
└── package.json
When deployed, your Netlify functions will be available at:
/.netlify/functions/chat- Chat completions/.netlify/functions/translate- Text translation/.netlify/functions/word-of-day- Word of the day
Make sure you're running npm run dev (which uses netlify dev), not vite.
- Check that
GROQ_API_KEYis set in Netlify dashboard - After adding env vars, redeploy your site
- For local dev, make sure
.env.localexists with the key
- Check Node.js version in
netlify.toml(should be 18+) - Verify all dependencies are in
package.json - Check build logs for specific errors
The Netlify functions automatically set CORS headers. If you still see CORS errors:
- Clear browser cache
- Make sure you're accessing the site via the Netlify URL, not
localhost:5173
- Never commit
.env.local- it's in.gitignorefor security - API keys are stored securely in Netlify environment variables
- Functions are deployed automatically with each push to main branch
- Free Groq tier limits: Check https://console.groq.com/ for current limits
For issues:
- Check Netlify function logs in dashboard
- Check browser console for errors
- Verify Groq API key is valid and has quota remaining