Skip to content

Meal Plan API

Generate Meal Plan

Proxies to the upstream meal-plan Cloud Function and returns its JSON response.

Endpoint

URLs:

  • Development: https://api.rex.fit/[org-id]/dev/v1/generate-meal-plan
  • Production: https://api.rex.fit/[org-id]/prod/v1/generate-meal-plan

Method: POST
Content-Type: application/json
Authorization: Bearer <GENERIC_WEBHOOK_API_KEY>

Request Fields

CamelCase or snake_case accepted for all fields.

Important Notes:

  • All 8 required fields must be included for successful meal plan generation

  • String values are case-flexible: "Male"/"male" and "moderate active"/"Moderate active" both work

  • Boolean fields accept multiple formats: "true"/"false", true/false, or "Yes"/"No"

  • Height in feet/inches format: Convert to decimal feet (e.g., 5'10" = 5.83 feet)

  • Missing required fields will result in HTTP 500 errors

Field Type Required Description Example
height number Yes Height in cm or decimal feet 180 (cm) or 5.83 (5'10" in feet has to be converted to decimal feet)
weight number Yes Weight in kg 80
age number Yes Age in years 30
sex string Yes Biological sex (flexible case) "Male", "Female", "male", "female"
targetWeight number Yes Goal weight (same unit as weight) 75
targetTimeWeeks number Yes Weeks to reach target weight 8
activityLevel string Yes Activity level (flexible case) "sedentary", "lightly active", "moderate active", "very active", "active"
measurementSystem string Yes Units for height/weight "kg/cm", "lbs/feet", "kg/feet", "lbs/cm"
thingsYouDontEat string No Comma-separated foods to exclude "pork, shellfish, peanuts"
isVegetarian string No Vegetarian preference "true" or "false"
isGlutenFree string No Gluten-free preference "true" or "false"
allergies string No Free-text allergies "peanuts"
allergiesList string No Comma-separated allergies "peanuts, dairy"
timeToCook string No Typical time available to cook "30-45 min"
cookingExperience string No Cooking skill level "Intermediate", "Beginner", "Advanced"
mealVariety string No Variety preference "Moderate variety", "High variety"
dailyCalories number No 0 to auto-calculate, or specific number 0
cuisine array No Preferred cuisines ["All"], ["Mediterranean"]
country string No ISO country name/code "US"
otherCountry string No Additional country context "LB"
selectedIngredients array No Preferred ingredients to include ["egg", "spinach"]
newMealsPerWeek number No Number of new meals per week (defaults to 12) 12

Example Request

Minimal Required Request:

{
  "height": 180,
  "weight": 80,
  "age": 30,
  "sex": "Male",
  "targetWeight": 75,
  "targetTimeWeeks": 8,
  "activityLevel": "moderate active",
  "measurementSystem": "kg/cm"
}

Full Request with Optional Fields:

{
  "height": 180,
  "weight": 80,
  "age": 30,
  "sex": "Male",
  "targetWeight": 75,
  "targetTimeWeeks": 8,
  "activityLevel": "moderate active",
  "measurementSystem": "kg/cm",
  "thingsYouDontEat": "pork, shellfish",
  "isVegetarian": "false",
  "isGlutenFree": "false",
  "allergies": "false",
  "allergiesList": "",
  "timeToCook": "30-45 min",
  "cookingExperience": "Intermediate",
  "mealVariety": "Moderate variety",
  "dailyCalories": 0,
  "cuisine": ["All"],
  "country": "US",
  "otherCountry": "",
  "selectedIngredients": ["egg", "spinach", "olive oil"]
}

Response

Status 200:

  • weekly_plan: array of 7 day objects { breakfast, lunch, dinner } each with:
  • dish_name: string name of the dish
  • diet: dietary classification (e.g., "Non-Vegetarian", "Vegetarian")
  • weight: total weight of the dish (e.g., "250g")
  • cooking_time: time required to prepare (e.g., "15 minutes")
  • calories: number of calories
  • ingredients: array of objects { ingredient, quantity }
  • instructions: object keyed by "Step N"
  • image_url: signed URL to generated meal image (valid ~24h)
  • daily_calories: array of 7 triplets [breakfast, lunch, dinner]
  • caloric_needs: number
  • ingredients_list: weekly shopping list (array of objects { ingredient, quantity })
  • pdf_url: signed URL to download combined weekly PDF (valid ~24h)

Note: Ingredient quantity values are human-readable strings and may include units like g, ml, pieces, loaves, heads, etc.

New: Each meal now includes an image_url field with a generated image of the dish (signed URL, valid ~24h).

Example Response (actual, truncated)

{
  "weekly_plan": [
    {
      "breakfast": { "dish_name": "Avocado Toast with Egg", "diet": "Non-Vegetarian", "weight": "250g", "cooking_time": "15 minutes", "calories": 450, "image_url": "https://storage.googleapis.com/rexfit-abeb2.appspot.com/meal-images/uuid/day_1_breakfast.png?signed...", "instructions": { "Step 1": "Toast the slices of whole grain bread in a toaster until golden brown." }, "ingredients": [ { "ingredient": "Whole grain bread slices", "quantity": "2 slices" }, { "ingredient": "Avocado", "quantity": "1 medium" } ] },
      "lunch": { "dish_name": "Grilled Chicken Caesar Salad", "diet": "Non-Vegetarian", "weight": "350g", "cooking_time": "20 minutes", "calories": 600, "image_url": "https://storage.googleapis.com/rexfit-abeb2.appspot.com/meal-images/uuid/day_1_lunch.png?signed...", "instructions": { "Step 1": "Preheat the grill to medium-high heat." }, "ingredients": [ { "ingredient": "Chicken breasts", "quantity": "200g" }, { "ingredient": "Romaine lettuce", "quantity": "100g" } ] },
      "dinner": { "dish_name": "Beef Stir-fry with Vegetables", "diet": "Non-Vegetarian", "weight": "400g", "cooking_time": "30 minutes", "calories": 715, "image_url": "https://storage.googleapis.com/rexfit-abeb2.appspot.com/meal-images/uuid/day_1_dinner.png?signed...", "instructions": { "Step 1": "Slice the beef into thin strips against the grain for tenderness." }, "ingredients": [ { "ingredient": "Beef sirloin", "quantity": "200g" }, { "ingredient": "Bell peppers", "quantity": "100g" } ] }
    },
    "..."
  ],
  "daily_calories": [[450, 600, 715], ["..."], "..."],
  "caloric_needs": 1814.9032000000002,
  "ingredients_list": [
    { "ingredient": "Avocado", "quantity": "3 whole" },
    { "ingredient": "Eggs", "quantity": "12 large" },
    "..."
  ],
  "pdf_url": "https://storage.googleapis.com/...signed..."
}

Error Responses

Code Description
204 CORS preflight (OPTIONS)
405 Method not allowed (non-POST)
401 Missing/invalid bearer token
502 Upstream returned invalid JSON
500 Internal error

Common 500 Error Examples

Missing height field:

{
  "error": "float() argument must be a string or a real number, not 'NoneType'"
}

Missing sex field:

{
  "error": "'NoneType' object has no attribute 'lower'"
}

Invalid measurement system:

{
  "error": "Invalid unit for height. Use 'cm' or 'feet'."
}

Invalid height format (feet/inches string):

{
  "error": "could not convert string to float: \"5'10\""
}