Authentication & Security
The Mizen API uses environment variables for authentication with third-party services. Currently, the API does not require authentication from clients, but it relies on server-side API keys for AI services and integrations.Environment Variables
Mizen requires the following environment variables to be configured:Required Variables
GROQ_API_KEY
Purpose: Authentication for AI recipe parsing and enhancement features Where it’s used:/api/parseIngredients- AI-based ingredient extraction/api/parseInstructions- AI-based instruction parsing/api/parseRecipe- Unified recipe parsing (AI fallback)/api/parseRecipeFromImage- Image-based recipe extraction/api/generateSubstitutions- AI-powered ingredient substitutions/api/generatePlatingGuidance- AI plating recommendations
- Create an account at Groq Cloud
- Generate an API key from the console
- Add to your
.env.localfile:
Optional Variables
NOTION_API_KEY
Purpose: Integration with Notion for feedback submission Where it’s used:/api/feedback- Submit user feedback to Notion database/api/feedback/upload- Upload feedback screenshots
- Create a Notion integration at Notion Integrations
- Copy the Internal Integration Token
- Add to your
.env.localfile:
NOTION_FEEDBACK_DATABASE_ID
Purpose: Target Notion database for storing feedback Where it’s used:/api/feedback- Specifies which Notion database to write to
-
Create a Notion database with the required properties:
- Title (title)
- Type (select)
- Status (status)
- Priority (select)
- Source (select)
- Reporter (rich_text)
- Device/OS (rich_text)
- App Version (rich_text)
- Share the database with your integration
-
Copy the database ID from the URL:
https://notion.so/workspace/<database_id>?v=... -
Add to your
.env.localfile:
Security Best Practices
API Key Protection
Never expose API keys in client-side code. All API keys should be stored in environment variables and only accessed server-side. ✅ Good - Server-side usage:Environment File Security
- Never commit
.env.localor.envfiles to version control - Add to
.gitignore:
- Use
.env.examplefor documentation:
Request Validation
All API endpoints validate incoming requests:URL Validation
Endpoints accepting URLs perform validation:File Upload Validation
Image upload endpoints enforce security constraints: Allowed file types:image/jpegimage/jpgimage/pngimage/webpimage/gif
Input Sanitization
The API sanitizes all user inputs:- Type validation: Ensures inputs match expected types
- Length limits: Prevents oversized payloads
- Content cleaning: Removes potentially harmful content
Rate Limiting
To prevent abuse, the API implements rate limiting through the AI service provider (Groq). When limits are exceeded:retryAfter timestamp (Unix milliseconds) indicates when to retry.
Implementing client-side rate limit handling:
CORS Configuration
Mizen API endpoints are designed for same-origin requests. If you need to enable CORS for external access, configure Next.js middleware:Production Deployment
Vercel Environment Variables
When deploying to Vercel:- Go to your project settings
- Navigate to “Environment Variables”
- Add each required variable:
GROQ_API_KEYNOTION_API_KEY(optional)NOTION_FEEDBACK_DATABASE_ID(optional)
- Select environments: Production, Preview, Development
- Click “Save”
Other Platforms
For other hosting platforms, consult their documentation for setting environment variables:- AWS Amplify: Environment variables in App settings
- Netlify: Site settings → Environment variables
- Railway: Project settings → Variables
- Render: Environment → Environment Variables
Testing Authentication
Verify your API keys are configured correctly:Error Logging
The API logs authentication errors to the console:Next Steps
- API Overview - Learn about response formats and error codes
- Parse Recipe - Start parsing recipes from URLs
- Parse Recipe from Image - Extract recipes from images
- Generate Substitutions - Get ingredient alternatives
- Generate Plating Guidance - Get plating and storage advice