Recipe
The 'recipe' endpoint allows you to generate recipes based on provided criteria, including recipe statement, dietary preferences, servings, preparation time, and difficulty level, with the choice of receiving the response as JSON or as a readable stream.
Introduction
This API allows you to generate meal recipes based on specific criteria. It provides two endpoints, each with a different response format:
- JSON Route: Returns the recipe details as JSON.
- Readable Stream Route: Streams the recipe details in a readable stream.
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:
recipe
(string, required): A statement describing the desired recipe.diet
(string, optional): Dietary preference ['vegetarian','pescatarian','vegan','diaryfree','glutenfree','keto','paleo']. Default: No diet restrictions.servings
(number, optional): The number of servings for the recipe. Default: 1 Serving.preparationTime
(number, optional): The maximum preparation time in minutes. Default: No time restrictions.difficulty
(string, optional): The difficulty level of the recipe ['novice', 'intermediate', 'expert']. Default: No difficulty 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.
JSON Route Details
Endpoint
POST /api/generate/recipe
Request Example
POST /api/generate/recipe
Headers:
{
"Authorization": "YOUR_API_KEY"
}
Body:
{
"recipe": "Beef Wellington",
"diet": "vegetarian",
"servings": 4,
"preparationTime": 30,
"difficulty": "intermediate"
}
Response (JSON)
- Status Code: 200 (OK)
- Content-Type: application/json
{
"recipeName": "Delicious Tomato Basil Pasta",
"difficulty": "intermediate",
"kitchenToolsUsed": ["Saucepan", "Knife", "Colander"],
"instructions": ["1. Boil pasta.", "2. Make tomato sauce.", "3. Mix pasta and sauce."],
"preparationTime": 30,
"servings": 4,
"ingredients": [
{ "name": "Pasta", "unit": "grams", "amount": 250 },
{ "name": "Tomatoes", "unit": "grams", "amount": 300 },
{ "name": "Basil", "unit": "grams", "amount": 10 }
],
"macros": {
"carbs": { "amount": 45, "unit": "grams" },
"fats": { "amount": 10, "unit": "grams" },
"proteins": { "amount": 8, "unit": "grams" },
"calories": { "amount": 280, "unit": "kcal" }
}
}
Readable Stream Route Details
Endpoint
POST /api/generate/stream/recipe
Request Example
POST /api/generate/stream/recipe
Headers:
{
"Authorization": "YOUR_API_KEY"
}
Body:
{
"recipe": "Beef Wellington",
"diet": "vegetarian",
"servings": 4,
"preparationTime": 30,
"difficulty": "intermediate"
}
Response (Readable Stream)
- Status Code: 200 (OK)
- Content-Type: application/json (Streaming)
{
"recipeName": "Delicious Tomato Basil Pasta",
"difficulty": "intermediate",
"kitchenToolsUsed": ["Saucepan", "Knife", "Colander"],
"instructions": ["1. Boil pasta.", "2. Make tomato sauce.", "3. Mix pasta and sauce."],
"preparationTime": 30,
"servings": 4,
"ingredients": [
{ "name": "Pasta", "unit": "grams", "amount": 250 },
{ "name": "Tomatoes", "unit": "grams", "amount": 300 },
{ "name": "Basil", "unit": "grams", "amount": 10 }
],
"macros": {
"carbs": { "amount": 45, "unit": "grams" },
"fats": { "amount": 10, "unit": "grams" },
"proteins": { "amount": 8, "unit": "grams" },
"calories": { "amount": 280, "unit": "kcal" }
}
}
The response is streamed and varies in size based on the generated content. On the client side, you should process the stream accordingly.
Handling the Readable Stream Response (JavaScript Example)
To handle the Readable Stream response in JavaScript, you can use the following code as an example:
const responseStream = fetch('/api/generate/stream/recipe', {
method: 'POST',
headers: {
'Authorization': 'YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
"recipe": "Beef Wellington",
"diet": "vegetarian",
"servings": 4,
"preparationTime": 30,
"difficulty": "intermediate"
}),
});
// Process the stream
responseStream.then(async (response) => {
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (!done) {
const { value, done: doneReading } = await reader.read();
done = doneReading; // Break the loop if stream completed
const newValue = decoder.decode(value);
chunks = chunks + newValue;
}
// Parses the completed response (recipe data)
const recipeData = JSON.parse(chunks);
// Handle the recipe data as needed
console.log(recipeData);
});
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' 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: