Nutrition FunctionsCook Basic & Pro
The functions on this page that look ingredients up call the Cook nutrition service. They work in any report template when you're signed in with Cook Basic or Cook Pro; accounts from before the paywall don't have the nutrition service. They resolve your ingredients against a curated nutrition database (USDA and other reference sources) with unit and preparation conversion. Prefer to maintain your own numbers? The free local db() datastore works without a subscription.
Requests that a template sends to the nutrition service count against your nutrition API daily quota: Cook Basic 1,000 requests a day, Cook Pro 5,000. The Nutrition API page describes the quota; it is also the HTTP service behind these functions, and the Cook MCP gives the same data to any AI agent as tools.
compare, within_tol, record_check, all_checks() and failed_checks() make no lookups, so they work without a plan.
| Function | Returns |
|---|---|
nutrition_for(ingredient) | macros — kcal, protein_g, fat_g, carb_g, fiber_g. The ingredient must have a numeric amount. |
nutrition_for_amount(name, amount, unit?, prep?, standard?) | full item: macros, micros, vitamins, source, confidence, allergens |
aggregate_nutrition(ingredients, standard?) | items, failures, totals, confidence_breakdown, allergen_summary, reference_standard, reference_intakes |
total_calories(ingredients) | number |
macros(ingredients) | {kcal, protein_g, fat_g, carb_g, fiber_g, sugar_g, sat_fat_g} |
vitamins(ingredients) | vitamin totals |
nutrient_total(ingredients, key) | one nutrient, e.g. "iron_mg", "vit_d_iu" |
reference_intake(name, standard?) | the daily reference value for a nutrient, e.g. reference_intake("sodium_mg"); undefined when the nutrient has none |
dv_percent(name, amount, standard?) | amount as a percentage of the daily reference value; undefined when the nutrient has none |
nutrition_report(ingredients) | a JSON string: ingredients_listed, ingredients_resolved, ingredients_failed and failures (each with index, code, ingredient, unit, amount) |
is_in_category(ingredient, slug) | true/false, category-tree aware |
category_servings(plan, slug) | meals containing the category (see plans) |
convert(amount, from, to, ingredient?) | unit conversion; pass the ingredient for volume/count units |
compare(actual, target, op) / within_tol(actual, target, tol_pct) | true/false; op is "gte", "lte" or "eq" (see checks) |
record_check(label, ok), all_checks(), failed_checks() | pass/fail tracking (see checks) |
matched_exclusions(), unresolved_exclusions() | exclusion matches for a client profile; always empty in Cook Editor (see checks) |
standard is "fda", "eu" or "uk". On aggregate_nutrition and nutrition_for_amount it picks the reference intakes and the allergen list; leave it out for the service default. reference_intake and dv_percent use "fda" when you leave it out.
Reading nutrition
aggregate_nutrition(ingredients) sums a whole list in one call and is the workhorse for recipe and plan totals. Macros sit under macros, both in the totals and in each item:
{% set n = aggregate_nutrition(ingredients) -%}
{% for item in n["items"] -%}
- {{ item.ingredient }}: {{ item.macros.kcal }} kcal, {{ item.macros.protein_g }} g protein
{% endfor %}
Total: {{ n.totals.macros.kcal }} kcal, {{ n.totals.macros.protein_g }} g protein
An ingredient with no amount is counted as a pinch. Ingredients the service could not resolve are left out of the totals and listed in n.failures, each with ingredient and error.message. totals also has micros, vitamins and mass_g. total_calories, macros, vitamins and nutrient_total are shortcuts over the same call.
nutrition_for(ingredient) looks up one ingredient, using the quantity, unit and preparation from the recipe itself:
{% set n = nutrition_for(ingredient) %}
{{ n.kcal }} kcal, {{ n.protein_g }} g protein
It needs a plain number as the amount (@salmon{150%g}, @eggs{2}). On an ingredient with no amount (@salt), a text amount (@butter{a knob}) or a range (1-2) the render stops with an error, so don't call it in a loop over every ingredient of an arbitrary recipe; use aggregate_nutrition for that.
For micronutrients and vitamins, or when there's no ingredient object to hand, use the lower-level form. It returns the full item, so macros are under macros here too:
{{ nutrition_for_amount("salmon", 150, "g", "cooked").macros.protein_g }}
Allergens
Every resolved item carries an allergens block, and aggregate_nutrition adds an allergen_summary for the batch. The one rule that matters: check status before contains. An ingredient with status: "unverified" has an empty contains list that means "nothing known" — never "allergen-free".
You don't have to hand-write the logic — include the built-in "allergens" partial and it renders the standard, correctly guarded lines:
{% set alg = aggregate_nutrition(ingredients).allergen_summary %}
{% include "allergens" %}
When some ingredients are unverified, the summary reads "Contains at least …" — the list is a floor, not a ceiling.
Confidence & sources
Nutrition numbers are estimates, and the report can be honest about it. aggregate_nutrition returns a confidence_breakdown next to the totals:
{% set t = aggregate_nutrition(ingredients) %}
Overall: {{ t.totals.confidence }} (weighted: {{ t.totals.confidence_weighted }})
totals.confidence— worst-of across items (strict).totals.confidence_weighted— mass-weighted, so one small estimated item doesn't tank the score.confidence_breakdown.estimated_share_of_micronutrients— how much of the micronutrient totals comes from estimated entries.
Each item also carries its own source and confidence, so templates can flag individual rows.
Categories & conversion
is_in_category(ingredient, slug) is tree-aware — an oily fish counts as fish_and_shellfish too. convert(amount, from, to, ingredient?) converts units; pass the ingredient when converting volume or count units that need density or portion data.
Building reports outside the editor? Released CookCLI (0.41.1) renders plain templates with cook report, but it has no nutrition functions and no plan value, and it reads a db/ folder only when you pass -d db. The developer guides cover the HTTP API and cook-nutrition-demo, a separate command-line program that has the nutrition functions.
For a worked example in the editor, see Make a nutrition report for a meal plan.