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
| Param | Example | Rule |
|---|---|---|
food_id | 12345 | From search or barcode |
grams | 175 | 0 < 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
| Pattern | Implementation |
|---|---|
| Slider 50 to 400g | Debounce portion API 200 ms |
| Preset buttons (100g, 150g) | Instant calc calls |
| Kitchen scale BLE | Auto-fill grams field |
| Edit logged meal | Re-call with new grams |
food_id Lifecycle
- User searches → store
idfrom results - User scans barcode →
idfrom barcode JSON - Pass same
idto 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.
Related
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.
