Meal Plan

The 'meal-plan' endpoint allows you to generate a personalized meal plan based on specific criteria and constraints. Customers have the choice of receiving the response as JSON or as a readable stream.

Introduction

This API route allows you to generate a personalized meal plan based on specific criteria and constraints.

Authentication

To access these endpoints, you must include an Authorization header with a valid API key.

Common Request Parameters

Both routes accept the following request parameters:

  • goal (enum, required): The meal plan goal, ['lose-weight', 'gain-muscles', 'eat-healthy']
  • duration (number, required): The number of days for the meal plan.
  • activityLevel (enum, required): The user's daily activity level ['sedentary', 'light-active', 'moderately-active', 'very-active', 'extremely-active'].
  • age (number, required): The user's age.
  • height (number, required): The user's height in centimeters.
  • weight (number, required): The user's weight in kilograms.
  • gender (string, required): The user's gender ['male', 'female', 'undefined']
  • diet (string, required): The dietary preference ['vegetarian','pescatarian','vegan','diaryfree','glutenfree','keto','paleo'].
  • measurement (string, required): The measurement system used in the output ['imperial', 'metric']. Default: Metric.
  • language (string, optional): The language in which the recipe should be generated. Supported languages ['english', 'spanish', 'portuguese', 'french', 'italian', 'german', 'chinese', 'japanese', 'korean', 'hebrew']. Default: "english".
  • allergies (string, optional): A comma separated list of ingredients to exclude from the recipe.

JSON Route Details

Endpoint

POST /api/generate/meal-plan

Request Example

POST /api/generate/meal-plan
Headers:
{
  "Authorization": "YOUR_API_KEY"
}
Body:
{
  "goal": "lose-weight",
  "duration": 30,
  "activityLevel": "moderately-active",
  "age": 30,
  "height": 175,
  "weight": 70,
  "gender": "male",
  "diet": "vegetarian"
}

Response (JSON)

  • Status Code: 200 (OK)
  • Content-Type: application/json
{
  "mealPlan": [
    {
      "day": 1,
      "breakfast": {
        "recipeName": "Healthy Oatmeal",
        "difficulty": "novice",
        "kitchenToolsUsed": ["bowl", "spoon"],
        "instructions": ["Cook oats with water.", "Add fruits and nuts.", "Enjoy!"],
        "preparationTime": 15,
        "servings": 1,
        "ingredients": [
          {
            "name": "Oats",
            "unit": "grams",
            "amount": 50
          },
          {
            "name": "Banana",
            "unit": "pieces",
            "amount": 1
          },
          {
            "name": "Almonds",
            "unit": "grams",
            "amount": 20
          }
        ],
        "recipeCategory": ["breakfast"],
        "recipeCuisine": ["american"],
        "macros": {
          "carbs": {
            "amount": 30,
            "unit": "grams"
          },
          "fats": {
            "amount": 10,
            "unit": "grams"
          },
          "proteins": {
            "amount": 5,
            "unit": "grams"
          },
          "calories": {
            "amount": 250,
            "unit": "kcal"
          }
        }
      },
      "lunch": {
        // ... (same structure as breakfast)
      },
      "snack": {
        // ... (same structure as breakfast)
      },
      "dinner": {
        // ... (same structure as breakfast)
      }
    },
    // ... (meal plan for other days)
  ]
}

Execution Time

As responses are generated on the fly through AI, response time will vary depending on the lenght of the response. Approximate time for response is 10s per recipe. A 'meal-plan' endpoint response is composed by multiple days and each days is composed by 4 recipes, you should account for a response time of 40/45 seconds per day.

Error Responses

Both routes return specific error responses for various scenarios:

  • Missing API Key (Status Code: 403):
    • Response: No API Key in request
  • Invalid API Key (Status Code: 403):
    • Response: Invalid API Key
  • Missing Required Inputs (Status Code: 400):
    • Response: Required inputs not provided
  • Inactive Subscription (Status Code: 403):
    • Response: You don't have an active subscription