Swap Meal Recommendation
Recommendations
Swap Meal Recommendation
POST
Swap Meal Recommendation
Swap a recipe in your meal plan with a similar alternative that matches your dietary preferences and nutritional goals.
Authentication
This endpoint requires Bearer token authentication. Include your access token in the Authorization header:Request
Query Parameters
The external recipe ID of the meal you want to swap. This is the
recipe_id field from the recipe object, not the database id.The meal type for which you want a replacement. Must be one of:
breakfastlunchdinnersnack
The number of similar recipes to search through before filtering. Higher values increase the likelihood of finding a good match but may slow down the response. Range: 1-1000
Response
Returns a recipe object that is nutritionally similar to the original but matches your dietary requirements.Database ID of the recommended recipe
External recipe ID from the dataset
Name of the recipeExample:
"Mediterranean Chicken Bowl"Total calories per servingExample:
480Protein content in gramsExample:
35Carbohydrate content in gramsExample:
45Fat content in gramsExample:
18URL to the recipe imageExample:
"https://example.com/recipes/mediterranean-bowl.jpg"URL to the full recipe details and instructionsExample:
"https://example.com/recipes/mediterranean-bowl"Comma-separated list of ingredientsExample:
"chicken breast, quinoa, cherry tomatoes, cucumber, feta cheese, olive oil, lemon"Array of meal type objects indicating when this recipe is suitable
Array of diet type objects this recipe belongs to
The meal label that was requested in the swapExample:
"dinner"Similarity score from the ML model. Lower values indicate higher similarity to the original recipe.Example:
0.234Example Request
cURL
Python
JavaScript
Example Response
200 - Success
404 - No Match Found
401 - Unauthorized
How It Works
- Load User Profile: Retrieves your dietary preferences and restrictions
- Get Active Plan: Checks your current meal plan to avoid duplicate recipes
- Find Similar Recipes: Uses K-Nearest Neighbors ML model to find recipes with similar nutritional profiles
- Apply Filters:
- Excludes recipes already in your meal plan
- Filters by the requested meal type (breakfast, lunch, dinner, snack)
- Ensures compatibility with your diet types (e.g., vegan, high-protein)
- Calculate Distance: Measures similarity in scaled nutritional feature space
- Random Selection: If multiple good matches exist, randomly selects one for variety
Notes
- The algorithm searches through up to
n_searchneighbors (default 550) - Recipes already in your active meal plan are automatically excluded
- The swap respects your dietary restrictions from your profile
- Lower
distancevalues indicate closer nutritional similarity - If no suitable match is found, a 404 error is returned
- The ML model uses standardized scaling for fair comparison across nutritional metrics
- Diet type filtering ensures recommendations align with your preferences (e.g., vegan users only get vegan recipes)
Tips for Best Results
- Use higher
n_searchvalues (700-1000) if you have strict dietary restrictions - Use lower
n_searchvalues (300-400) for faster responses when flexibility is acceptable - Ensure your profile has diet types set for more accurate filtering
- The
distancemetric helps you understand how similar the swap is nutritionally
