DEV Community

Cover image for "0.1667 cups" isn't a measurement. Scaling recipes the way cooks measure
Dani
Dani

Posted on

"0.1667 cups" isn't a measurement. Scaling recipes the way cooks measure

Multiplying a recipe by 1.5 is easy math. Making the answer usable in a real kitchen is not. Nobody owns a 0.1667 cup measure, and "1.5 eggs" isn't something you can crack.

So I built an API that scales recipes and writes the results the way a cook would.

Example: a 4-serving recipe scaled to 6

Send the ingredient lines with the old and new servings:

{
  "ingredients": [
    "1 1/2 cups flour",
    "2 eggs",
    "1/2 cup butter",
    "1 tsp vanilla extract",
    "Pinch of salt"
  ],
  "servings": 4,
  "target_servings": 6
}
Enter fullscreen mode Exit fullscreen mode

And you get back:

  • 2 1/4 cups flour
  • 3 eggs
  • 3/4 cup butter
  • 1 1/2 teaspoons vanilla extract
  • Pinch of salt (left alone, since a pinch is a pinch)

Each line also comes back as structured JSON with the quantity, unit and ingredient, so you can display it however you like.

The details that make it kitchen-friendly

  • Measurable fractions. Results round to 1/8, 1/4, 1/3, 1/2, 2/3, 3/4. If rounding moved an amount more than 3%, the result is flagged approximate.
  • Unit tidying. 8 tbsp becomes 1/2 cup, 48 tsp becomes 1 cup.
  • Whole items. If eggs or lemons come out fractional, you get a tip like "Works out to 1 1/2; round to 1 or 2 as you prefer."
  • US ↔ metric. /convert turns 2 cups milk into 475ml milk.

Quick example (Python)

import requests

resp = requests.post(
    "https://recipe-scaler.p.rapidapi.com/scale",
    json={
        "ingredients": ["1 1/2 cups flour", "2 eggs"],
        "servings": 4,
        "target_servings": 6,
    },
    headers={
        "X-RapidAPI-Key": "your-key",
        "X-RapidAPI-Host": "recipe-scaler.p.rapidapi.com",
    },
)
for item in resp.json()["results"]:
    print(item["text"])
Enter fullscreen mode Exit fullscreen mode

One honest limitation

Converting cups of flour to grams depends on the ingredient's density, so volume-to-weight conversion isn't supported yet. You get a clear error instead of a wrong number.

Try it

There's a free plan, so you can test it on your own recipes without paying anything.

👉 Recipe Scaler on RapidAPI

It pairs with my Recipe Extractor, which pulls the ingredient list from any recipe link to scale. Each line is read by my Ingredient Parser, which you can also use on its own.

What would you want it to handle next? Let me know in the comments.

Top comments (0)