link,[object Object]
Skip to content

AI Setup Guide ​

Overview ​

This guide covers the setup and configuration of the AI Project Analyzer feature, including Mistral AI integration and n8n webhook configuration.

Prerequisites ​

  • Supabase project with Edge Functions enabled
  • Mistral AI API key
  • n8n instance (optional, for admin notifications)

Mistral AI Setup ​

1. Get Mistral API Key ​

  1. Visit Mistral AI Console
  2. Sign up or log in to your account
  3. Navigate to API Keys section
  4. Create a new API key
  5. Copy the key for configuration

2. Configure Supabase Secret ​

Add the Mistral API key as a Supabase project secret:

bash
# Using Supabase CLI
supabase secrets set MISTRAL_API_KEY=your_mistral_api_key_here --project-ref nujcbrbtejvhuajfwgeo

# Or via Supabase Dashboard
# Go to Project Settings > Edge Functions > Secrets
# Add: MISTRAL_API_KEY = your_mistral_api_key_here

3. Deploy Edge Function ​

Deploy the analyze-project Edge Function:

bash
supabase functions deploy analyze-project --project-ref nujcbrbtejvhuajfwgeo

4. Verify Configuration ​

Test the Edge Function:

bash
curl -X POST https://nujcbrbtejvhuajfwgeo.supabase.co/functions/v1/analyze-project \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
  -d '{"url":"https://example.com"}'

n8n Webhook Setup (Optional) ​

1. Create n8n Webhooks ​

Set up webhooks in your n8n instance:

  • General Webhook: https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912
  • Chat Webhook: https://n8n.10alert.com/webhook/64ea74c0-2f7d-46d6-bec8-d988607b951b
  • Listing Webhook: https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912

2. Configure Supabase Secrets ​

Add n8n webhook URLs as Supabase secrets:

bash
supabase secrets set N8N_WEBHOOK_URL=https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912 --project-ref nujcbrbtejvhuajfwgeo

supabase secrets set N8N_WEBHOOK_CHAT=https://n8n.10alert.com/webhook/64ea74c0-2f7d-46d6-bec8-d988607b951b --project-ref nujcbrbtejvhuajfwgeo

supabase secrets set N8N_WEBHOOK_LISTING=https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912 --project-ref nujcbrbtejvhuajfwgeo

Deploy functions that use n8n webhooks:

bash
supabase functions deploy n8n-chat --project-ref nujcbrbtejvhuajfwgeo
supabase functions deploy send-admin-listing-notification --project-ref nujcbrbtejvhuajfwgeo

Environment Variables ​

Frontend (.env.local) ​

env
# Supabase Configuration
VITE_SUPABASE_URL=https://nujcbrbtejvhuajfwgeo.supabase.co
VITE_SUPABASE_ANON_KEY=your_supabase_anon_key

# Other existing variables...

Backend (Supabase Secrets) ​

env
# Mistral AI
MISTRAL_API_KEY=your_mistral_api_key

# n8n Webhooks (Optional)
N8N_WEBHOOK_URL=https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912
N8N_WEBHOOK_CHAT=https://n8n.10alert.com/webhook/64ea74c0-2f7d-46d6-bec8-d988607b951b
N8N_WEBHOOK_LISTING=https://n8n.10alert.com/webhook/95e9d69b-25c0-4642-bd84-9a52ad68f912

Testing the Setup ​

1. Test AI Project Analysis ​

  1. Start the development server:

    bash
    pnpm dev
  2. Navigate to /create-listing

  3. Log in with a test account

  4. Enter a project URL (e.g., https://windowsreport.com)

  5. Click "Analyze Project"

  6. Verify that fields are populated correctly

2. Test Error Handling ​

Test various error scenarios:

  • Invalid URL: Enter an invalid URL format
  • Rate Limit: Test with multiple rapid requests
  • Network Error: Test with offline network
  • Authentication: Test without being logged in

3. Verify Logs ​

Check logs for debugging:

  • Frontend: Browser console logs
  • Backend: Supabase Edge Function logs
  • Database: Check for any data inconsistencies

Troubleshooting ​

Common Issues ​

  1. 401 Unauthorized

    • Ensure user is logged in
    • Check JWT token validity
    • Verify verify_jwt = true in config
  2. 429 Rate Limit

    • Mistral API rate limit exceeded
    • Wait 10 minutes before retrying
    • Consider upgrading Mistral plan
  3. 500 Internal Server Error

    • Check Mistral API key validity
    • Verify Edge Function deployment
    • Check Supabase function logs
  4. JSON Parse Errors

    • System automatically attempts recovery
    • Check Mistral API response format
    • Verify prompt optimization

Debug Steps ​

  1. Check Secrets:

    bash
    supabase secrets list --project-ref nujcbrbtejvhuajfwgeo
  2. Test Edge Function:

    bash
    supabase functions serve analyze-project --project-ref nujcbrbtejvhuajfwgeo
  3. Check Logs:

    bash
    supabase functions logs analyze-project --project-ref nujcbrbtejvhuajfwgeo

Production Considerations ​

Security ​

  • Never expose API keys in frontend code
  • Use Supabase secrets for all sensitive data
  • Implement proper rate limiting
  • Monitor API usage and costs

Performance ​

  • Monitor Mistral API response times
  • Implement caching for repeated requests
  • Optimize prompts for token efficiency
  • Set appropriate timeouts

Monitoring ​

  • Set up alerts for API failures
  • Monitor Edge Function execution times
  • Track AI analysis success rates
  • Log user interactions for analytics

Cost Management ​

Mistral AI Costs ​

  • Monitor token usage in Mistral dashboard
  • Optimize prompts to reduce token consumption
  • Implement fallback strategies for rate limits
  • Consider usage-based pricing models

n8n Costs ​

  • Monitor webhook execution frequency
  • Optimize workflow efficiency
  • Consider self-hosting for high volume