Skip to main content
POST
/
api
/
generateSubstitutions
Generate Ingredient Substitutions
curl --request POST \
  --url https://api.example.com/api/generateSubstitutions \
  --header 'Content-Type: application/json' \
  --data '
{
  "ingredientName": "<string>",
  "ingredientAmount": "<string>",
  "recipeTitle": "<string>",
  "cuisine": [
    {}
  ],
  "ingredients": [
    {}
  ],
  "instructions": [
    {}
  ]
}
'
{
  "success": true,
  "data": {
    "substitutions": [
      {
        "name": "<string>",
        "description": "<string>"
      }
    ]
  },
  "error": "<string>",
  "details": "<string>"
}

Overview

The /api/generateSubstitutions endpoint generates intelligent, context-aware ingredient substitutions. It analyzes the full recipe context (ingredients, instructions, cuisine) to suggest practical substitutions that work specifically for the recipe at hand. Unlike generic substitution lists, this endpoint considers:
  • The cooking method used in the recipe
  • Other ingredients in the recipe
  • The cuisine style
  • How the ingredient interacts with the dish

Request

ingredientName
string
required
The name of the ingredient to find substitutions for.Example: "heavy cream", "gochujang", "parmesan cheese"
ingredientAmount
string
The amount of the ingredient in the recipe (optional but recommended for better suggestions).Example: "1/2 cup", "2 tablespoons"
recipeTitle
string
The title of the recipe (helps provide context).Example: "Gochujang Pasta"
cuisine
array
Array of cuisine tags for the recipe.Example: ["Korean", "Italian Fusion"]
ingredients
array
Full ingredient list of the recipe. Helps the AI understand ingredient interactions.
instructions
array
Full cooking instructions. Helps the AI understand how the ingredient is used.Example: ["Heat butter in a pan", "Add gochujang and cream"]

Response

Success Response

success
boolean
required
Always true for successful responses
data
object
required
Substitution data

Error Response

error
string
Error message describing what went wrong
details
string
Additional error details (if available)

Examples

curl -X POST https://your-domain.com/api/generateSubstitutions \
  -H "Content-Type: application/json" \
  -d '{
    "ingredientName": "gochujang",
    "ingredientAmount": "2 tablespoons",
    "recipeTitle": "Gochujang Pasta",
    "cuisine": ["Korean", "Fusion"],
    "ingredients": [
      {
        "groupName": "For the sauce",
        "ingredients": [
          {"amount": "2", "units": "tablespoons", "ingredient": "gochujang"},
          {"amount": "1/2", "units": "cup", "ingredient": "heavy cream"}
        ]
      }
    ],
    "instructions": [
      "Heat butter in a pan over medium heat.",
      "Add gochujang and stir until fragrant.",
      "Add cream and simmer."
    ]
  }'

Success Response Example

{
  "success": true,
  "data": {
    "substitutions": [
      {
        "name": "Sriracha mixed with miso paste",
        "description": "Combines heat and umami to mimic gochujang's fermented depth in cream sauce"
      },
      {
        "name": "Sambal oelek with a pinch of sugar",
        "description": "Provides similar heat level; sugar balances the spiciness with cream"
      },
      {
        "name": "Tomato paste with red pepper flakes",
        "description": "Creates savory base with adjustable heat for this pasta sauce"
      }
    ]
  }
}

Error Response Example

{
  "error": "Ingredient name is required"
}

AI Model

This endpoint uses the llama-3.3-70b-versatile model via Groq with:
  • Temperature: 0.4 (balanced between creativity and consistency)
  • Max tokens: 1024
This endpoint requires a valid Groq API key configured as GROQ_API_KEY in your environment variables.
While only ingredientName is required, providing full recipe context (ingredients, instructions, cuisine) results in much better, more contextually relevant substitution suggestions.

Build docs developers (and LLMs) love