Recipe From Macros
The 'recipe-from-macros' endpoint allows you to generate recipes from a target macronutrient distribution and additional criterias are available to fine ture the output. Customers have the choice of receiving the response as JSON or as a readable stream.
Introduction
This API route allows you to generate a recipe based on macronutrient distributions and optional 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:
carbs
(number, required): The amount of carbohydrates in grams.proteins
(number, required): The amount of proteins in grams.fats
(number, required): The amount of fats in grams.diet
(string, optional): The dietary preference ['vegetarian','pescatarian','vegan','diaryfree','glutenfree','keto','paleo']. Default: No diet restrictions.meal
(string, optional): The meal type ['breakfast', 'lunch', 'dinner', 'snack', 'dessert']. Default: No meal restrictions.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.servings
(number, optional): The amount of servings the recipe should yield. Default: 1 serving.
JSON Route Details
Endpoint
POST /api/generate/recipe-from-macros
Request Example
POST /api/generate/recipe-from-macros
Headers:
{
"Authorization": "YOUR_API_KEY"
}
Body:
{
"carbs": 100,
"proteins": 50,
"fats": 30,
"diet": "vegetarian",
"meal": "lunch",
"servings": 2
}
Response (JSON)
- Status Code: 200 (OK)
- Content-Type: application/json
{
"recipeName": "Delicious Chicken and Rice",
"ingredients": [
{
"name": "Chicken",
"unit": "grams",
"amount": 500
},
{
"name": "Rice",
"unit": "cups",
"amount": 2
},
// ... other ingredients
],
"instructions": [
"1. Preheat the oven to 350°F.",
"2. Season the chicken with salt and pepper.",
// ... other instructions
],
"recipeCategory": ["dinner"],
"recipeCuisine": ["american"],
"difficulty": "intermediate",
"macros": {
"carbs": {
"amount": 40,
"unit": "grams"
},
// ... other macros
},
"preparationTime": 30,
"servings": 1,
"kitchenToolsUsed": ["oven", "pot"]
}
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 for the 'recipe-from-macros' endpoint.
Error Responses
Both routes return specific error responses for various scenarios:
- Missing API Key (Status Code: 403):
- Response:
No API Key in request
- Response:
- Invalid API Key (Status Code: 403):
- Response:
Invalid API Key
- Response:
- Missing Required Inputs (Status Code: 400):
- Response:
Required inputs not provided
- Response:
- Inactive Subscription (Status Code: 403):
- Response:
You don't have an active subscription
- Response: