Skip to content

Portion Size Nutrition Scaler API: Food ID and Grams

Published May 31, 2026

A portion size nutrition scaler API food ID grams workflow is the core of meal logging: user picks a food, enters grams, app shows exact calories and macros. Calorie API GET /public/calc/portion takes food_id + grams and returns scaled nutrients in one call.

Full reference: food portion size calculator API. This guide focuses on the food_id + grams scaler pattern.

Parameters

ParamExampleRule
food_id12345From search or barcode
grams1750 < grams ≤ 5000
curl "https://api.calorieapi.com/api/v1/public/calc/portion?food_id=12345&grams=175"

Response Usage

Map scaled fields directly to log rows:

const portion = await fetch(`/api/calc/portion?food_id=${id}&grams=${grams}`).then(r => r.json());
await saveLog({
  foodId: id,
  grams,
  calories: portion.calories,
  proteinG: portion.protein_g,
  carbsG: portion.carbohydrates_g,
  fatG: portion.fat_g,
});

Mobile UX Patterns

PatternImplementation
Slider 50 to 400gDebounce portion API 200 ms
Preset buttons (100g, 150g)Instant calc calls
Kitchen scale BLEAuto-fill grams field
Edit logged mealRe-call with new grams

food_id Lifecycle

  1. User searches → store id from results
  2. User scans barcode → id from barcode JSON
  3. Pass same id to portion scaler on every gram change

Never re-search by name when scaling; IDs are stable.

vs Client-Side Math

Client formula works too: scale per 100g guide. Use portion API when you want server-validated math and single source of truth.

Docs | Register

Frequently Asked Questions

How does the portion size nutrition scaler API work?

Send food_id from search or barcode plus grams to GET /public/calc/portion. Calorie API returns scaled calories, protein, carbs, fat, and fiber for that exact serving.

Where do I get food_id?

food_id comes from search results, suggest selection, barcode lookup, or food detail endpoints.

What is the maximum grams for portion calc?

Calorie API portion calc accepts grams greater than 0 and up to 5000 per request.

Should I call portion calc on every slider movement?

Debounce 200 ms on sliders to avoid excessive calls, or scale client-side from cached per-100g detail for instant feedback.

Can portion scaler replace manual per-100g math?

Yes. Portion calc is equivalent to (grams/100)*per_100g_nutrient with server-side validation.

← Back to all articles

Start building with the Calorie API

Get a free API key and access 4M+ foods with search, barcode lookup, and full macro data.