Skip to main content

Overview

The Recommendations endpoint uses AI to analyze Monte Carlo simulation results and generate specific, actionable financial recommendations. It considers the user’s financial profile, goal, and simulation outcomes to provide personalized advice.

Endpoint

POST /llm/recommendations

Request Body

simulationResults
object
required
Results from a Monte Carlo simulation run.
financialProfile
object
required
User’s current financial situation.
goal
object
required
The user’s financial goal.

Response

recommendations
string[]
Array of 3-4 specific, actionable recommendations. Each recommendation:
  • References specific numbers from the user’s financial data
  • Provides actionable advice (not vague suggestions)
  • Explains the expected impact on success probability

Examples

Low Success Probability

curl -X POST https://api.drift.example/llm/recommendations \
  -H "Content-Type: application/json" \
  -d '{
    "simulationResults": {
      "successProbability": 0.35,
      "medianOutcome": 30000,
      "percentiles": {
        "p10": 15000,
        "p25": 22000,
        "p50": 30000,
        "p75": 38000,
        "p90": 45000
      },
      "mean": 31000,
      "std": 12000,
      "worstCase": 8000,
      "bestCase": 55000
    },
    "financialProfile": {
      "monthlyIncome": 5000,
      "monthlySpending": 4200,
      "liquidAssets": 3000,
      "creditDebt": 2000,
      "loanDebt": 15000,
      "monthlyLoanPayments": 350,
      "spendingByCategory": {
        "Food & Dining": 9600,
        "Shopping": 7200,
        "Entertainment": 4800,
        "Transportation": 6000
      },
      "spendingVolatility": 0.15
    },
    "goal": {
      "targetAmount": 50000,
      "timelineMonths": 36,
      "goalType": "major_purchase"
    }
  }'

Good Success Probability

curl -X POST https://api.drift.example/llm/recommendations \
  -H "Content-Type: application/json" \
  -d '{
    "simulationResults": {
      "successProbability": 0.82,
      "medianOutcome": 52000,
      "percentiles": {
        "p10": 45000,
        "p25": 48000,
        "p50": 52000,
        "p75": 56000,
        "p90": 60000
      },
      "mean": 52500,
      "std": 6000,
      "worstCase": 38000,
      "bestCase": 68000
    },
    "financialProfile": {
      "monthlyIncome": 7000,
      "monthlySpending": 4500,
      "liquidAssets": 15000,
      "creditDebt": 0,
      "loanDebt": 8000,
      "monthlyLoanPayments": 200,
      "spendingByCategory": {
        "Food & Dining": 7200,
        "Transportation": 4800,
        "Entertainment": 3600,
        "Utilities": 2400
      },
      "spendingVolatility": 0.08
    },
    "goal": {
      "targetAmount": 50000,
      "timelineMonths": 36,
      "goalType": "major_purchase"
    }
  }'

Emergency Fund Goal

curl -X POST https://api.drift.example/llm/recommendations \
  -H "Content-Type: application/json" \
  -d '{
    "simulationResults": {
      "successProbability": 0.65,
      "medianOutcome": 13500,
      "percentiles": {
        "p10": 10000,
        "p25": 11500,
        "p50": 13500,
        "p75": 15000,
        "p90": 16500
      },
      "mean": 13600,
      "std": 2500,
      "worstCase": 7500,
      "bestCase": 19000
    },
    "financialProfile": {
      "monthlyIncome": 4500,
      "monthlySpending": 3400,
      "liquidAssets": 1200,
      "creditDebt": 3500,
      "loanDebt": 0,
      "monthlyLoanPayments": 0,
      "spendingByCategory": {
        "Food & Dining": 6000,
        "Entertainment": 4800,
        "Shopping": 3600,
        "Utilities": 1800
      },
      "spendingVolatility": 0.18
    },
    "goal": {
      "targetAmount": 15000,
      "timelineMonths": 12,
      "goalType": "emergency_fund"
    }
  }'

Error Responses

error
string
Error message describing what went wrong.

Server Error

500 Internal Server Error
{
  "error": "Failed to generate recommendations"
}

Implementation Notes

  • The endpoint uses Google’s Gemini 2.0 Flash model for generating recommendations
  • If the Gemini API is unavailable, it falls back to rule-based recommendations
  • Recommendations are tailored based on:
    • Success probability (low vs. high)
    • Savings rate (spending vs. income ratio)
    • Risk factors (debt levels, spending volatility)
    • Specific spending categories from transaction data
  • Each recommendation includes specific dollar amounts and expected impact
  • The AI prioritizes actionable advice over generic suggestions

Build docs developers (and LLMs) love