Files
9628b5f868 fix(ai): give text analysis a real multi-vendor fallback chain (#238)
llm-analysis.js and aiAnalysisService.js each constructed their own
OpenAI client, hardcoded model: 'gpt-4', and threw/skipped outright
whenever OPENAI_API_KEY was unset — a single vendor, single model, with
no recovery path. The moment OpenAI has a billing hiccup, an outage, or
retires gpt-4, every text-analysis feature in this app goes dead until
someone notices and redeploys.

backend/lib/aiChain.js gives both services a real chain via ai-kit
(Groq -> OpenRouter free tier, same package already adopted fleet-wide
for this exact failure mode), plus a health tracker exposed
informationally on /health (never gates the endpoint's status — a dead
vendor key can't be fixed by a restart).

Vision/image analysis (imageIngestionService.js, video frame analysis,
openaiVisionService.ts) and Whisper audio transcription stay on OpenAI
directly: ai-kit's free chain carries no vision- or audio-capable free
models, so forcing those onto it would silently degrade output quality
rather than provide a real fallback. Documented as a known limitation
in .claude/CLAUDE.md's env var list.


Claude-Session: https://claude.ai/code/session_01HVwg8DKHQktxJuHeLM3xpG

Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-02 09:16:38 +00:00

51 lines
1.5 KiB
Bash

# Database Configuration
DATABASE_URL="postgresql://username:password@localhost:5432/formular?schema=public"
# JWT Configuration
JWT_SECRET="your-super-secret-jwt-key-here-change-in-production"
# Redis Configuration (for background jobs)
REDIS_HOST="localhost"
REDIS_PORT=6379
REDIS_PASSWORD=""
# AI Configuration
#
# Text analysis (LLM analysis, database queries/insights) runs on a
# multi-vendor free-tier fallback chain via ai-kit — set GROQ_API_KEY and/or
# OPENROUTER_API_KEY. Either alone is enough; both gives real failover (a
# single vendor's outage/billing hiccup no longer kills the feature).
GROQ_API_KEY="your-groq-api-key-here"
OPENROUTER_API_KEY="your-openrouter-api-key-here"
# Vision/image ingestion and audio transcription (Whisper) are OpenAI-only —
# ai-kit's free chain carries no vision- or audio-capable free models. See
# backend/lib/aiChain.js for why that split is deliberate, not an oversight.
OPENAI_API_KEY="your-openai-api-key-here"
# Server Configuration
PORT=5001
NODE_ENV=development
FRONTEND_URL="http://localhost:3000"
# Email Configuration (optional - for notifications)
EMAIL_SERVICE="sendgrid"
EMAIL_API_KEY=""
EMAIL_FROM="noreply@formular.com"
# File Upload Configuration
MAX_FILE_SIZE=10485760 # 10MB in bytes
UPLOAD_DIR="./uploads"
EXPORT_DIR="./exports"
# Rate Limiting
RATE_LIMIT_WINDOW_MS=900000 # 15 minutes
RATE_LIMIT_MAX_REQUESTS=100
# Security
BCRYPT_ROUNDS=12
SESSION_SECRET="your-session-secret-here"
# Monitoring (optional)
ENABLE_METRICS=false
METRICS_PORT=9090