Skip to main content

Generate Recommendations

Get AI-powered, actionable financial recommendations based on simulation results and current financial profile.
POST /api/ai/recommendations

Request Body

simulationResults
object
required
Simulation results containing success probability and outcome distribution
financialProfile
object
required
Current financial situation
goal
object
required
Financial goal details

Response

recommendations
array
Array of actionable recommendation strings, ordered by impact/priority

Example Request

const response = await fetch('http://localhost:3001/api/ai/recommendations', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    simulationResults: {
      successProbability: 0.42,
      medianOutcome: 38000,
      percentiles: {
        p10: 22000,
        p25: 30000,
        p50: 38000,
        p75: 46000,
        p90: 54000
      },
      mean: 38500,
      worstCase: 15000,
      bestCase: 65000
    },
    financialProfile: {
      monthlyIncome: 5000,
      monthlySpending: 4200,
      liquidAssets: 8000,
      creditDebt: 3500,
      loanDebt: 0,
      monthlyLoanPayments: 0,
      spendingByCategory: {
        'Food & Dining': 800,
        'Shopping': 600,
        'Entertainment': 400,
        'Transportation': 500,
        'Bills': 1200,
        'Other': 700
      },
      spendingVolatility: 0.18
    },
    goal: {
      targetAmount: 50000,
      timelineMonths: 48,
      goalType: 'house'
    }
  })
})

const { recommendations } = await response.json()

Example Response

{
  "recommendations": [
    "Your success probability is currently 42%, which is below the ideal 70%+ range. Consider extending your timeline or adjusting your target.",
    "Pay off your $3,500 credit card debt first. This will free up ~$105/month in interest charges and improve your monthly cash flow.",
    "Reduce discretionary spending by 15% ($450/month). Focus on categories like Shopping ($600) and Entertainment ($400) where you have flexibility.",
    "Build an emergency fund of $12,600 (3 months of expenses) before aggressively saving for your house goal. This prevents setbacks from derailing your progress.",
    "Your spending volatility is 18%, which is slightly above average. Try to stabilize monthly expenses by reducing impulse purchases.",
    "Consider a side income source. An extra $300/month would increase your success probability to ~62%."
  ]
}

Recommendation Engine Logic

The AI analyzes multiple factors:
  1. Success Probability - Below 70% triggers suggestions to improve odds
  2. Debt Analysis - High-interest debt gets prioritized
  3. Spending Patterns - Identifies high-spend categories for reduction
  4. Income Gap - Calculates shortfall and suggests income increases
  5. Timeline Flexibility - Recommends timeline adjustments if needed
  6. Risk Factors - Flags volatility, emergency fund gaps, etc.
Recommendations are ordered by impact. The first 2-3 recommendations typically have the highest leverage for improving goal success.

Error Responses

error
string
Error message
message
string
Detailed error description

Common Errors

  • 400 Bad Request - Missing required fields (simulationResults, financialProfile, or goal)
  • 500 Internal Server Error - Gemini API failure or recommendation generation error
This endpoint requires GEMINI_API_KEY to be configured. It uses the Gemini 1.5 Pro model for intelligent analysis.

Build docs developers (and LLMs) love